blob: cc2a243c91aa2494a33337010b2c98a8c02d4ebc [file] [log] [blame]
[email protected]80c75f682012-05-26 16:22:171// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit586acc5fe2008-07-26 22:42:524
[email protected]f7984fc62009-06-22 23:26:445#include "net/socket/client_socket_factory.h"
initial.commit586acc5fe2008-07-26 22:42:526
dchengc7eeda422015-12-26 03:56:487#include <utility>
8
[email protected]625332e02010-12-14 07:48:499#include "base/lazy_instance.h"
[email protected]68bf9152008-09-25 19:47:3010#include "build/build_config.h"
[email protected]6e7845ae2013-03-29 21:48:1111#include "net/cert/cert_database.h"
[email protected]e60e47a2010-07-14 03:37:1812#include "net/socket/client_socket_handle.h"
[email protected]f7984fc62009-06-22 23:26:4413#include "net/socket/tcp_client_socket.h"
[email protected]98b0e582011-06-22 14:31:4114#include "net/udp/udp_client_socket.h"
initial.commit586acc5fe2008-07-26 22:42:5215
davidbenf72d28c2015-09-30 15:27:1216#if defined(USE_OPENSSL)
17#include "net/socket/ssl_client_socket_openssl.h"
18#else
19#include "net/socket/ssl_client_socket_nss.h"
20#endif
21
initial.commit586acc5fe2008-07-26 22:42:5222namespace net {
23
[email protected]62635c72011-03-10 04:16:2524class X509Certificate;
25
[email protected]abe48d32010-02-03 02:09:3626namespace {
27
[email protected]62635c72011-03-10 04:16:2528class DefaultClientSocketFactory : public ClientSocketFactory,
29 public CertDatabase::Observer {
initial.commit586acc5fe2008-07-26 22:42:5230 public:
[email protected]62635c72011-03-10 04:16:2531 DefaultClientSocketFactory() {
[email protected]7fda9a402012-09-10 14:11:0732 CertDatabase::GetInstance()->AddObserver(this);
[email protected]62635c72011-03-10 04:16:2533 }
34
dchengb03027d2014-10-21 12:00:2035 ~DefaultClientSocketFactory() override {
[email protected]53998282012-06-06 22:08:5236 // Note: This code never runs, as the factory is defined as a Leaky
37 // singleton.
[email protected]7fda9a402012-09-10 14:11:0738 CertDatabase::GetInstance()->RemoveObserver(this);
[email protected]62635c72011-03-10 04:16:2539 }
40
dchengb03027d2014-10-21 12:00:2041 void OnCertAdded(const X509Certificate* cert) override {
[email protected]c940d372011-04-13 17:20:1842 ClearSSLSessionCache();
43 }
44
dchengb03027d2014-10-21 12:00:2045 void OnCACertChanged(const X509Certificate* cert) override {
[email protected]c940d372011-04-13 17:20:1846 // Per wtc, we actually only need to flush when trust is reduced.
[email protected]c157b2e22013-10-31 01:38:3347 // Always flush now because OnCACertChanged does not tell us this.
48 // See comments in ClientSocketPoolManager::OnCACertChanged.
[email protected]62635c72011-03-10 04:16:2549 ClearSSLSessionCache();
50 }
51
dchengb03027d2014-10-21 12:00:2052 scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket(
[email protected]5370c012011-06-29 03:47:0453 DatagramSocket::BindType bind_type,
54 const RandIntCallback& rand_int_cb,
[email protected]98b0e582011-06-22 14:31:4155 NetLog* net_log,
mostynbba063d6032014-10-09 11:01:1356 const NetLog::Source& source) override {
[email protected]18ccfdb2013-08-15 00:13:4457 return scoped_ptr<DatagramClientSocket>(
58 new UDPClientSocket(bind_type, rand_int_cb, net_log, source));
[email protected]98b0e582011-06-22 14:31:4159 }
60
dchengb03027d2014-10-21 12:00:2061 scoped_ptr<StreamSocket> CreateTransportClientSocket(
[email protected]0a0b7682010-08-25 17:08:0762 const AddressList& addresses,
63 NetLog* net_log,
mostynbba063d6032014-10-09 11:01:1364 const NetLog::Source& source) override {
[email protected]18ccfdb2013-08-15 00:13:4465 return scoped_ptr<StreamSocket>(
66 new TCPClientSocket(addresses, net_log, source));
initial.commit586acc5fe2008-07-26 22:42:5267 }
68
dchengb03027d2014-10-21 12:00:2069 scoped_ptr<SSLClientSocket> CreateSSLClientSocket(
[email protected]18ccfdb2013-08-15 00:13:4470 scoped_ptr<ClientSocketHandle> transport_socket,
[email protected]4f4de7e62010-11-12 19:55:2771 const HostPortPair& host_and_port,
[email protected]7ab5bbd12010-10-19 13:33:2172 const SSLConfig& ssl_config,
mostynbba063d6032014-10-09 11:01:1373 const SSLClientSocketContext& context) override {
[email protected]53998282012-06-06 22:08:5274#if defined(USE_OPENSSL)
dchengc7eeda422015-12-26 03:56:4875 return scoped_ptr<SSLClientSocket>(new SSLClientSocketOpenSSL(
76 std::move(transport_socket), host_and_port, ssl_config, context));
[email protected]2380f372011-02-23 21:35:1977#else
davidbenf72d28c2015-09-30 15:27:1278 return scoped_ptr<SSLClientSocket>(new SSLClientSocketNSS(
79 transport_socket.Pass(), host_and_port, ssl_config, context));
[email protected]2380f372011-02-23 21:35:1980#endif
initial.commit586acc5fe2008-07-26 22:42:5281 }
[email protected]25f47352011-02-25 16:31:5982
dchengb03027d2014-10-21 12:00:2083 void ClearSSLSessionCache() override { SSLClientSocket::ClearSessionCache(); }
initial.commit586acc5fe2008-07-26 22:42:5284};
85
[email protected]53998282012-06-06 22:08:5286static base::LazyInstance<DefaultClientSocketFactory>::Leaky
[email protected]6de0fd1d2011-11-15 13:31:4987 g_default_client_socket_factory = LAZY_INSTANCE_INITIALIZER;
[email protected]625332e02010-12-14 07:48:4988
[email protected]abe48d32010-02-03 02:09:3689} // namespace
90
[email protected]d100e44f2011-01-26 22:47:1191// static
92ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() {
93 return g_default_client_socket_factory.Pointer();
94}
95
initial.commit586acc5fe2008-07-26 22:42:5296} // namespace net