blob: 12eb56af2f4814fc1f2d84bf02cfc74240aa13e9 [file] [log] [blame]
Dustin J. Mitchell5daf9192024-04-15 14:38:091// 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 Silvac6de5ce2025-03-18 16:33:118#include <variant>
9
Dustin J. Mitchell5daf9192024-04-15 14:38:0910#include "base/memory/scoped_refptr.h"
11#include "net/base/net_export.h"
Dustin J. Mitchell5daf9192024-04-15 14:38:0912
13namespace net {
14
15class HttpProxySocketParams;
16class SOCKSSocketParams;
17class TransportSocketParams;
18class SSLSocketParams;
19
20// Abstraction over the param types for various connect jobs.
21class 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 Silvac6de5ce2025-03-18 16:33:1136 return std::holds_alternative<scoped_refptr<HttpProxySocketParams>>(
Dustin J. Mitchell5daf9192024-04-15 14:38:0937 params_);
38 }
39
40 bool is_socks() const {
Victor Hugo Vianna Silvac6de5ce2025-03-18 16:33:1141 return std::holds_alternative<scoped_refptr<SOCKSSocketParams>>(params_);
Dustin J. Mitchell5daf9192024-04-15 14:38:0942 }
43
44 bool is_transport() const {
Victor Hugo Vianna Silvac6de5ce2025-03-18 16:33:1145 return std::holds_alternative<scoped_refptr<TransportSocketParams>>(
Dustin J. Mitchell5daf9192024-04-15 14:38:0946 params_);
47 }
48
49 bool is_ssl() const {
Victor Hugo Vianna Silvac6de5ce2025-03-18 16:33:1150 return std::holds_alternative<scoped_refptr<SSLSocketParams>>(params_);
Dustin J. Mitchell5daf9192024-04-15 14:38:0951 }
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 Silvac6de5ce2025-03-18 16:33:1182 std::variant<scoped_refptr<HttpProxySocketParams>,
83 scoped_refptr<SOCKSSocketParams>,
84 scoped_refptr<TransportSocketParams>,
85 scoped_refptr<SSLSocketParams>>
Dustin J. Mitchell5daf9192024-04-15 14:38:0986 params_;
87};
88
89} // namespace net
90
91#endif // NET_SOCKET_CONNECT_JOB_PARAMS_H_