xref: /aosp_15_r20/external/cronet/net/socket/client_socket_factory.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2011 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_CLIENT_SOCKET_FACTORY_H_
6 #define NET_SOCKET_CLIENT_SOCKET_FACTORY_H_
7 
8 #include <memory>
9 #include <string>
10 
11 #include "net/base/net_export.h"
12 #include "net/http/proxy_client_socket.h"
13 #include "net/socket/datagram_socket.h"
14 #include "net/socket/socket_performance_watcher.h"
15 #include "net/socket/transport_client_socket.h"
16 #include "net/traffic_annotation/network_traffic_annotation.h"
17 
18 namespace net {
19 
20 class AddressList;
21 class DatagramClientSocket;
22 class HostPortPair;
23 class NetLog;
24 struct NetLogSource;
25 class SSLClientContext;
26 class SSLClientSocket;
27 struct SSLConfig;
28 class NetworkQualityEstimator;
29 
30 // An interface used to instantiate StreamSocket objects.  Used to facilitate
31 // testing code with mock socket implementations.
32 class NET_EXPORT ClientSocketFactory {
33  public:
34   virtual ~ClientSocketFactory() = default;
35 
36   // |source| is the NetLogSource for the entity trying to create the socket,
37   // if it has one.
38   virtual std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket(
39       DatagramSocket::BindType bind_type,
40       NetLog* net_log,
41       const NetLogSource& source) = 0;
42 
43   // |network_quality_estimator| is optional. If not specified, the network
44   // quality will not be considered when determining TCP connect handshake
45   // timeouts, or when histogramming the handshake duration.
46   virtual std::unique_ptr<TransportClientSocket> CreateTransportClientSocket(
47       const AddressList& addresses,
48       std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher,
49       NetworkQualityEstimator* network_quality_estimator,
50       NetLog* net_log,
51       const NetLogSource& source) = 0;
52 
53   // It is allowed to pass in a StreamSocket that is not obtained from a
54   // socket pool. The caller could create a StreamSocket directly.
55   virtual std::unique_ptr<SSLClientSocket> CreateSSLClientSocket(
56       SSLClientContext* context,
57       std::unique_ptr<StreamSocket> stream_socket,
58       const HostPortPair& host_and_port,
59       const SSLConfig& ssl_config) = 0;
60 
61   // Returns the default ClientSocketFactory.
62   static ClientSocketFactory* GetDefaultFactory();
63 };
64 
65 }  // namespace net
66 
67 #endif  // NET_SOCKET_CLIENT_SOCKET_FACTORY_H_
68