xref: /aosp_15_r20/external/cronet/net/socket/client_socket_factory.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2012 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 #include "net/socket/client_socket_factory.h"
6 
7 #include <utility>
8 
9 #include "base/lazy_instance.h"
10 #include "build/build_config.h"
11 #include "net/socket/ssl_client_socket.h"
12 #include "net/socket/tcp_client_socket.h"
13 #include "net/socket/udp_client_socket.h"
14 
15 namespace net {
16 
17 class X509Certificate;
18 
19 namespace {
20 
21 class DefaultClientSocketFactory : public ClientSocketFactory {
22  public:
23   DefaultClientSocketFactory() = default;
24 
25   // Note: This code never runs, as the factory is defined as a Leaky singleton.
26   ~DefaultClientSocketFactory() override = default;
27 
CreateDatagramClientSocket(DatagramSocket::BindType bind_type,NetLog * net_log,const NetLogSource & source)28   std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket(
29       DatagramSocket::BindType bind_type,
30       NetLog* net_log,
31       const NetLogSource& source) override {
32     return std::make_unique<UDPClientSocket>(bind_type, net_log, source);
33   }
34 
CreateTransportClientSocket(const AddressList & addresses,std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher,NetworkQualityEstimator * network_quality_estimator,NetLog * net_log,const NetLogSource & source)35   std::unique_ptr<TransportClientSocket> CreateTransportClientSocket(
36       const AddressList& addresses,
37       std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher,
38       NetworkQualityEstimator* network_quality_estimator,
39       NetLog* net_log,
40       const NetLogSource& source) override {
41     return std::make_unique<TCPClientSocket>(
42         addresses, std::move(socket_performance_watcher),
43         network_quality_estimator, net_log, source);
44   }
45 
CreateSSLClientSocket(SSLClientContext * context,std::unique_ptr<StreamSocket> stream_socket,const HostPortPair & host_and_port,const SSLConfig & ssl_config)46   std::unique_ptr<SSLClientSocket> CreateSSLClientSocket(
47       SSLClientContext* context,
48       std::unique_ptr<StreamSocket> stream_socket,
49       const HostPortPair& host_and_port,
50       const SSLConfig& ssl_config) override {
51     return context->CreateSSLClientSocket(std::move(stream_socket),
52                                           host_and_port, ssl_config);
53   }
54 };
55 
56 static base::LazyInstance<DefaultClientSocketFactory>::Leaky
57     g_default_client_socket_factory = LAZY_INSTANCE_INITIALIZER;
58 
59 }  // namespace
60 
61 // static
GetDefaultFactory()62 ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() {
63   return g_default_client_socket_factory.Pointer();
64 }
65 
66 }  // namespace net
67