[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 5 | #include "net/socket/client_socket_factory.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 6 | |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 9 | #include "base/lazy_instance.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 10 | #include "build/build_config.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 11 | #include "net/cert/cert_database.h" |
Helen Li | ac3c51e | 2018-04-24 00:02:13 | [diff] [blame] | 12 | #include "net/http/http_proxy_client_socket.h" |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 13 | #include "net/socket/client_socket_handle.h" |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 14 | #include "net/socket/ssl_client_socket_impl.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 15 | #include "net/socket/tcp_client_socket.h" |
tfarina | 5dd13c2 | 2016-11-16 12:08:26 | [diff] [blame] | 16 | #include "net/socket/udp_client_socket.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 17 | |
| 18 | namespace net { |
| 19 | |
[email protected] | 62635c7 | 2011-03-10 04:16:25 | [diff] [blame] | 20 | class X509Certificate; |
| 21 | |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 22 | namespace { |
| 23 | |
[email protected] | 62635c7 | 2011-03-10 04:16:25 | [diff] [blame] | 24 | class DefaultClientSocketFactory : public ClientSocketFactory, |
| 25 | public CertDatabase::Observer { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 26 | public: |
[email protected] | 62635c7 | 2011-03-10 04:16:25 | [diff] [blame] | 27 | DefaultClientSocketFactory() { |
[email protected] | 7fda9a40 | 2012-09-10 14:11:07 | [diff] [blame] | 28 | CertDatabase::GetInstance()->AddObserver(this); |
[email protected] | 62635c7 | 2011-03-10 04:16:25 | [diff] [blame] | 29 | } |
| 30 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 31 | ~DefaultClientSocketFactory() override { |
[email protected] | 5399828 | 2012-06-06 22:08:52 | [diff] [blame] | 32 | // Note: This code never runs, as the factory is defined as a Leaky |
| 33 | // singleton. |
[email protected] | 7fda9a40 | 2012-09-10 14:11:07 | [diff] [blame] | 34 | CertDatabase::GetInstance()->RemoveObserver(this); |
[email protected] | 62635c7 | 2011-03-10 04:16:25 | [diff] [blame] | 35 | } |
| 36 | |
mattm | fd05a1f | 2017-02-18 06:18:44 | [diff] [blame] | 37 | void OnCertDBChanged() override { |
rsleevi | 1778469 | 2016-10-12 01:36:20 | [diff] [blame] | 38 | // Flush sockets whenever CA trust changes. |
[email protected] | 62635c7 | 2011-03-10 04:16:25 | [diff] [blame] | 39 | ClearSSLSessionCache(); |
| 40 | } |
| 41 | |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 42 | std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
[email protected] | 5370c01 | 2011-06-29 03:47:04 | [diff] [blame] | 43 | DatagramSocket::BindType bind_type, |
[email protected] | 98b0e58 | 2011-06-22 14:31:41 | [diff] [blame] | 44 | NetLog* net_log, |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 45 | const NetLogSource& source) override { |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 46 | return std::unique_ptr<DatagramClientSocket>( |
Sergey Ulanov | cbdfc885 | 2018-03-16 20:13:28 | [diff] [blame] | 47 | new UDPClientSocket(bind_type, net_log, source)); |
[email protected] | 98b0e58 | 2011-06-22 14:31:41 | [diff] [blame] | 48 | } |
| 49 | |
Helen Li | d5bb922 | 2018-04-12 15:33:09 | [diff] [blame] | 50 | std::unique_ptr<TransportClientSocket> CreateTransportClientSocket( |
[email protected] | 0a0b768 | 2010-08-25 17:08:07 | [diff] [blame] | 51 | const AddressList& addresses, |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 52 | std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
[email protected] | 0a0b768 | 2010-08-25 17:08:07 | [diff] [blame] | 53 | NetLog* net_log, |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 54 | const NetLogSource& source) override { |
Helen Li | d5bb922 | 2018-04-12 15:33:09 | [diff] [blame] | 55 | return std::make_unique<TCPClientSocket>( |
| 56 | addresses, std::move(socket_performance_watcher), net_log, source); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 57 | } |
| 58 | |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 59 | std::unique_ptr<SSLClientSocket> CreateSSLClientSocket( |
| 60 | std::unique_ptr<ClientSocketHandle> transport_socket, |
[email protected] | 4f4de7e6 | 2010-11-12 19:55:27 | [diff] [blame] | 61 | const HostPortPair& host_and_port, |
[email protected] | 7ab5bbd1 | 2010-10-19 13:33:21 | [diff] [blame] | 62 | const SSLConfig& ssl_config, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 63 | const SSLClientSocketContext& context) override { |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 64 | return std::unique_ptr<SSLClientSocket>(new SSLClientSocketImpl( |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 65 | std::move(transport_socket), host_and_port, ssl_config, context)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 66 | } |
[email protected] | 25f4735 | 2011-02-25 16:31:59 | [diff] [blame] | 67 | |
Helen Li | ac3c51e | 2018-04-24 00:02:13 | [diff] [blame] | 68 | std::unique_ptr<ProxyClientSocket> CreateProxyClientSocket( |
| 69 | std::unique_ptr<ClientSocketHandle> transport_socket, |
| 70 | const std::string& user_agent, |
| 71 | const HostPortPair& endpoint, |
| 72 | HttpAuthController* http_auth_controller, |
| 73 | bool tunnel, |
| 74 | bool using_spdy, |
| 75 | NextProto negotiated_protocol, |
| 76 | bool is_https_proxy, |
| 77 | const NetworkTrafficAnnotationTag& traffic_annotation) override { |
| 78 | return std::make_unique<HttpProxyClientSocket>( |
| 79 | std::move(transport_socket), user_agent, endpoint, http_auth_controller, |
| 80 | tunnel, using_spdy, negotiated_protocol, is_https_proxy, |
| 81 | traffic_annotation); |
| 82 | } |
| 83 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 84 | void ClearSSLSessionCache() override { SSLClientSocket::ClearSessionCache(); } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 85 | }; |
| 86 | |
[email protected] | 5399828 | 2012-06-06 22:08:52 | [diff] [blame] | 87 | static base::LazyInstance<DefaultClientSocketFactory>::Leaky |
[email protected] | 6de0fd1d | 2011-11-15 13:31:49 | [diff] [blame] | 88 | g_default_client_socket_factory = LAZY_INSTANCE_INITIALIZER; |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 89 | |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 90 | } // namespace |
| 91 | |
[email protected] | d100e44f | 2011-01-26 22:47:11 | [diff] [blame] | 92 | // static |
| 93 | ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { |
| 94 | return g_default_client_socket_factory.Pointer(); |
| 95 | } |
| 96 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 97 | } // namespace net |