Dustin J. Mitchell | 5daf919 | 2024-04-15 14:38:09 | [diff] [blame] | 1 | // Copyright 2024 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_SOCKET_CONNECT_JOB_PARAMS_H_ |
| 6 | #define NET_SOCKET_CONNECT_JOB_PARAMS_H_ |
| 7 | |
Victor Hugo Vianna Silva | c6de5ce | 2025-03-18 16:33:11 | [diff] [blame] | 8 | #include <variant> |
| 9 | |
Dustin J. Mitchell | 5daf919 | 2024-04-15 14:38:09 | [diff] [blame] | 10 | #include "base/memory/scoped_refptr.h" |
| 11 | #include "net/base/net_export.h" |
Dustin J. Mitchell | 5daf919 | 2024-04-15 14:38:09 | [diff] [blame] | 12 | |
| 13 | namespace net { |
| 14 | |
| 15 | class HttpProxySocketParams; |
| 16 | class SOCKSSocketParams; |
| 17 | class TransportSocketParams; |
| 18 | class SSLSocketParams; |
| 19 | |
| 20 | // Abstraction over the param types for various connect jobs. |
| 21 | class NET_EXPORT_PRIVATE ConnectJobParams { |
| 22 | public: |
| 23 | ConnectJobParams(); |
| 24 | explicit ConnectJobParams(scoped_refptr<HttpProxySocketParams> params); |
| 25 | explicit ConnectJobParams(scoped_refptr<SOCKSSocketParams> params); |
| 26 | explicit ConnectJobParams(scoped_refptr<TransportSocketParams> params); |
| 27 | explicit ConnectJobParams(scoped_refptr<SSLSocketParams> params); |
| 28 | ~ConnectJobParams(); |
| 29 | |
| 30 | ConnectJobParams(ConnectJobParams&); |
| 31 | ConnectJobParams& operator=(ConnectJobParams&); |
| 32 | ConnectJobParams(ConnectJobParams&&); |
| 33 | ConnectJobParams& operator=(ConnectJobParams&&); |
| 34 | |
| 35 | bool is_http_proxy() const { |
Victor Hugo Vianna Silva | c6de5ce | 2025-03-18 16:33:11 | [diff] [blame] | 36 | return std::holds_alternative<scoped_refptr<HttpProxySocketParams>>( |
Dustin J. Mitchell | 5daf919 | 2024-04-15 14:38:09 | [diff] [blame] | 37 | params_); |
| 38 | } |
| 39 | |
| 40 | bool is_socks() const { |
Victor Hugo Vianna Silva | c6de5ce | 2025-03-18 16:33:11 | [diff] [blame] | 41 | return std::holds_alternative<scoped_refptr<SOCKSSocketParams>>(params_); |
Dustin J. Mitchell | 5daf919 | 2024-04-15 14:38:09 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | bool is_transport() const { |
Victor Hugo Vianna Silva | c6de5ce | 2025-03-18 16:33:11 | [diff] [blame] | 45 | return std::holds_alternative<scoped_refptr<TransportSocketParams>>( |
Dustin J. Mitchell | 5daf919 | 2024-04-15 14:38:09 | [diff] [blame] | 46 | params_); |
| 47 | } |
| 48 | |
| 49 | bool is_ssl() const { |
Victor Hugo Vianna Silva | c6de5ce | 2025-03-18 16:33:11 | [diff] [blame] | 50 | return std::holds_alternative<scoped_refptr<SSLSocketParams>>(params_); |
Dustin J. Mitchell | 5daf919 | 2024-04-15 14:38:09 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | // Get lvalue references to the contained params. |
| 54 | const scoped_refptr<HttpProxySocketParams>& http_proxy() const { |
| 55 | return get<scoped_refptr<HttpProxySocketParams>>(params_); |
| 56 | } |
| 57 | const scoped_refptr<SOCKSSocketParams>& socks() const { |
| 58 | return get<scoped_refptr<SOCKSSocketParams>>(params_); |
| 59 | } |
| 60 | const scoped_refptr<TransportSocketParams>& transport() const { |
| 61 | return get<scoped_refptr<TransportSocketParams>>(params_); |
| 62 | } |
| 63 | const scoped_refptr<SSLSocketParams>& ssl() const { |
| 64 | return get<scoped_refptr<SSLSocketParams>>(params_); |
| 65 | } |
| 66 | |
| 67 | // Take params out of this value. |
| 68 | scoped_refptr<HttpProxySocketParams>&& take_http_proxy() { |
| 69 | return get<scoped_refptr<HttpProxySocketParams>>(std::move(params_)); |
| 70 | } |
| 71 | scoped_refptr<SOCKSSocketParams>&& take_socks() { |
| 72 | return get<scoped_refptr<SOCKSSocketParams>>(std::move(params_)); |
| 73 | } |
| 74 | scoped_refptr<TransportSocketParams>&& take_transport() { |
| 75 | return get<scoped_refptr<TransportSocketParams>>(std::move(params_)); |
| 76 | } |
| 77 | scoped_refptr<SSLSocketParams>&& take_ssl() { |
| 78 | return get<scoped_refptr<SSLSocketParams>>(std::move(params_)); |
| 79 | } |
| 80 | |
| 81 | private: |
Victor Hugo Vianna Silva | c6de5ce | 2025-03-18 16:33:11 | [diff] [blame] | 82 | std::variant<scoped_refptr<HttpProxySocketParams>, |
| 83 | scoped_refptr<SOCKSSocketParams>, |
| 84 | scoped_refptr<TransportSocketParams>, |
| 85 | scoped_refptr<SSLSocketParams>> |
Dustin J. Mitchell | 5daf919 | 2024-04-15 14:38:09 | [diff] [blame] | 86 | params_; |
| 87 | }; |
| 88 | |
| 89 | } // namespace net |
| 90 | |
| 91 | #endif // NET_SOCKET_CONNECT_JOB_PARAMS_H_ |