[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" |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 12 | #include "net/socket/client_socket_handle.h" |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 13 | #include "net/socket/ssl_client_socket_impl.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 14 | #include "net/socket/tcp_client_socket.h" |
tfarina | 5dd13c2 | 2016-11-16 12:08:26 | [diff] [blame] | 15 | #include "net/socket/udp_client_socket.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 16 | |
| 17 | namespace net { |
| 18 | |
[email protected] | 62635c7 | 2011-03-10 04:16:25 | [diff] [blame] | 19 | class X509Certificate; |
| 20 | |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 21 | namespace { |
| 22 | |
[email protected] | 62635c7 | 2011-03-10 04:16:25 | [diff] [blame] | 23 | class DefaultClientSocketFactory : public ClientSocketFactory, |
| 24 | public CertDatabase::Observer { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 25 | public: |
[email protected] | 62635c7 | 2011-03-10 04:16:25 | [diff] [blame] | 26 | DefaultClientSocketFactory() { |
[email protected] | 7fda9a40 | 2012-09-10 14:11:07 | [diff] [blame] | 27 | CertDatabase::GetInstance()->AddObserver(this); |
[email protected] | 62635c7 | 2011-03-10 04:16:25 | [diff] [blame] | 28 | } |
| 29 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 30 | ~DefaultClientSocketFactory() override { |
[email protected] | 5399828 | 2012-06-06 22:08:52 | [diff] [blame] | 31 | // Note: This code never runs, as the factory is defined as a Leaky |
| 32 | // singleton. |
[email protected] | 7fda9a40 | 2012-09-10 14:11:07 | [diff] [blame] | 33 | CertDatabase::GetInstance()->RemoveObserver(this); |
[email protected] | 62635c7 | 2011-03-10 04:16:25 | [diff] [blame] | 34 | } |
| 35 | |
mattm | fd05a1f | 2017-02-18 06:18:44 | [diff] [blame^] | 36 | void OnCertDBChanged() override { |
rsleevi | 1778469 | 2016-10-12 01:36:20 | [diff] [blame] | 37 | // Flush sockets whenever CA trust changes. |
[email protected] | 62635c7 | 2011-03-10 04:16:25 | [diff] [blame] | 38 | ClearSSLSessionCache(); |
| 39 | } |
| 40 | |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 41 | std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
[email protected] | 5370c01 | 2011-06-29 03:47:04 | [diff] [blame] | 42 | DatagramSocket::BindType bind_type, |
| 43 | const RandIntCallback& rand_int_cb, |
[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>( |
[email protected] | 18ccfdb | 2013-08-15 00:13:44 | [diff] [blame] | 47 | new UDPClientSocket(bind_type, rand_int_cb, net_log, source)); |
[email protected] | 98b0e58 | 2011-06-22 14:31:41 | [diff] [blame] | 48 | } |
| 49 | |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 50 | std::unique_ptr<StreamSocket> 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 { |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 55 | return std::unique_ptr<StreamSocket>(new TCPClientSocket( |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 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 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 68 | void ClearSSLSessionCache() override { SSLClientSocket::ClearSessionCache(); } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 69 | }; |
| 70 | |
[email protected] | 5399828 | 2012-06-06 22:08:52 | [diff] [blame] | 71 | static base::LazyInstance<DefaultClientSocketFactory>::Leaky |
[email protected] | 6de0fd1d | 2011-11-15 13:31:49 | [diff] [blame] | 72 | g_default_client_socket_factory = LAZY_INSTANCE_INITIALIZER; |
[email protected] | 625332e0 | 2010-12-14 07:48:49 | [diff] [blame] | 73 | |
[email protected] | abe48d3 | 2010-02-03 02:09:36 | [diff] [blame] | 74 | } // namespace |
| 75 | |
[email protected] | d100e44f | 2011-01-26 22:47:11 | [diff] [blame] | 76 | // static |
| 77 | ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { |
| 78 | return g_default_client_socket_factory.Pointer(); |
| 79 | } |
| 80 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 81 | } // namespace net |