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 8 #include "base/memory/scoped_refptr.h" 9 #include "net/base/net_export.h" 10 #include "third_party/abseil-cpp/absl/types/variant.h" 11 12 namespace net { 13 14 class HttpProxySocketParams; 15 class SOCKSSocketParams; 16 class TransportSocketParams; 17 class SSLSocketParams; 18 19 // Abstraction over the param types for various connect jobs. 20 class NET_EXPORT_PRIVATE ConnectJobParams { 21 public: 22 ConnectJobParams(); 23 explicit ConnectJobParams(scoped_refptr<HttpProxySocketParams> params); 24 explicit ConnectJobParams(scoped_refptr<SOCKSSocketParams> params); 25 explicit ConnectJobParams(scoped_refptr<TransportSocketParams> params); 26 explicit ConnectJobParams(scoped_refptr<SSLSocketParams> params); 27 ~ConnectJobParams(); 28 29 ConnectJobParams(ConnectJobParams&); 30 ConnectJobParams& operator=(ConnectJobParams&); 31 ConnectJobParams(ConnectJobParams&&); 32 ConnectJobParams& operator=(ConnectJobParams&&); 33 is_http_proxy()34 bool is_http_proxy() const { 35 return absl::holds_alternative<scoped_refptr<HttpProxySocketParams>>( 36 params_); 37 } 38 is_socks()39 bool is_socks() const { 40 return absl::holds_alternative<scoped_refptr<SOCKSSocketParams>>(params_); 41 } 42 is_transport()43 bool is_transport() const { 44 return absl::holds_alternative<scoped_refptr<TransportSocketParams>>( 45 params_); 46 } 47 is_ssl()48 bool is_ssl() const { 49 return absl::holds_alternative<scoped_refptr<SSLSocketParams>>(params_); 50 } 51 52 // Get lvalue references to the contained params. http_proxy()53 const scoped_refptr<HttpProxySocketParams>& http_proxy() const { 54 return get<scoped_refptr<HttpProxySocketParams>>(params_); 55 } socks()56 const scoped_refptr<SOCKSSocketParams>& socks() const { 57 return get<scoped_refptr<SOCKSSocketParams>>(params_); 58 } transport()59 const scoped_refptr<TransportSocketParams>& transport() const { 60 return get<scoped_refptr<TransportSocketParams>>(params_); 61 } ssl()62 const scoped_refptr<SSLSocketParams>& ssl() const { 63 return get<scoped_refptr<SSLSocketParams>>(params_); 64 } 65 66 // Take params out of this value. take_http_proxy()67 scoped_refptr<HttpProxySocketParams>&& take_http_proxy() { 68 return get<scoped_refptr<HttpProxySocketParams>>(std::move(params_)); 69 } take_socks()70 scoped_refptr<SOCKSSocketParams>&& take_socks() { 71 return get<scoped_refptr<SOCKSSocketParams>>(std::move(params_)); 72 } take_transport()73 scoped_refptr<TransportSocketParams>&& take_transport() { 74 return get<scoped_refptr<TransportSocketParams>>(std::move(params_)); 75 } take_ssl()76 scoped_refptr<SSLSocketParams>&& take_ssl() { 77 return get<scoped_refptr<SSLSocketParams>>(std::move(params_)); 78 } 79 80 private: 81 absl::variant<scoped_refptr<HttpProxySocketParams>, 82 scoped_refptr<SOCKSSocketParams>, 83 scoped_refptr<TransportSocketParams>, 84 scoped_refptr<SSLSocketParams>> 85 params_; 86 }; 87 88 } // namespace net 89 90 #endif // NET_SOCKET_CONNECT_JOB_PARAMS_H_ 91