blob: 2ddce225705a7a285610bdb27e15758bd355237a [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"
Helen Liac3c51e2018-04-24 00:02:1312#include "net/http/http_proxy_client_socket.h"
[email protected]e60e47a2010-07-14 03:37:1813#include "net/socket/client_socket_handle.h"
svaldeze83af292016-04-26 14:33:3714#include "net/socket/ssl_client_socket_impl.h"
[email protected]f7984fc62009-06-22 23:26:4415#include "net/socket/tcp_client_socket.h"
tfarina5dd13c22016-11-16 12:08:2616#include "net/socket/udp_client_socket.h"
initial.commit586acc5fe2008-07-26 22:42:5217
18namespace net {
19
[email protected]62635c72011-03-10 04:16:2520class X509Certificate;
21
[email protected]abe48d32010-02-03 02:09:3622namespace {
23
[email protected]62635c72011-03-10 04:16:2524class DefaultClientSocketFactory : public ClientSocketFactory,
25 public CertDatabase::Observer {
initial.commit586acc5fe2008-07-26 22:42:5226 public:
[email protected]62635c72011-03-10 04:16:2527 DefaultClientSocketFactory() {
[email protected]7fda9a402012-09-10 14:11:0728 CertDatabase::GetInstance()->AddObserver(this);
[email protected]62635c72011-03-10 04:16:2529 }
30
dchengb03027d2014-10-21 12:00:2031 ~DefaultClientSocketFactory() override {
[email protected]53998282012-06-06 22:08:5232 // Note: This code never runs, as the factory is defined as a Leaky
33 // singleton.
[email protected]7fda9a402012-09-10 14:11:0734 CertDatabase::GetInstance()->RemoveObserver(this);
[email protected]62635c72011-03-10 04:16:2535 }
36
mattmfd05a1f2017-02-18 06:18:4437 void OnCertDBChanged() override {
rsleevi17784692016-10-12 01:36:2038 // Flush sockets whenever CA trust changes.
[email protected]62635c72011-03-10 04:16:2539 ClearSSLSessionCache();
40 }
41
danakj655b66c2016-04-16 00:51:3842 std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket(
[email protected]5370c012011-06-29 03:47:0443 DatagramSocket::BindType bind_type,
[email protected]98b0e582011-06-22 14:31:4144 NetLog* net_log,
mikecironef22f9812016-10-04 03:40:1945 const NetLogSource& source) override {
danakj655b66c2016-04-16 00:51:3846 return std::unique_ptr<DatagramClientSocket>(
Sergey Ulanovcbdfc8852018-03-16 20:13:2847 new UDPClientSocket(bind_type, net_log, source));
[email protected]98b0e582011-06-22 14:31:4148 }
49
Helen Lid5bb9222018-04-12 15:33:0950 std::unique_ptr<TransportClientSocket> CreateTransportClientSocket(
[email protected]0a0b7682010-08-25 17:08:0751 const AddressList& addresses,
danakj655b66c2016-04-16 00:51:3852 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher,
[email protected]0a0b7682010-08-25 17:08:0753 NetLog* net_log,
mikecironef22f9812016-10-04 03:40:1954 const NetLogSource& source) override {
Helen Lid5bb9222018-04-12 15:33:0955 return std::make_unique<TCPClientSocket>(
56 addresses, std::move(socket_performance_watcher), net_log, source);
initial.commit586acc5fe2008-07-26 22:42:5257 }
58
danakj655b66c2016-04-16 00:51:3859 std::unique_ptr<SSLClientSocket> CreateSSLClientSocket(
60 std::unique_ptr<ClientSocketHandle> transport_socket,
[email protected]4f4de7e62010-11-12 19:55:2761 const HostPortPair& host_and_port,
[email protected]7ab5bbd12010-10-19 13:33:2162 const SSLConfig& ssl_config,
mostynbba063d6032014-10-09 11:01:1363 const SSLClientSocketContext& context) override {
svaldeze83af292016-04-26 14:33:3764 return std::unique_ptr<SSLClientSocket>(new SSLClientSocketImpl(
dchengc7eeda422015-12-26 03:56:4865 std::move(transport_socket), host_and_port, ssl_config, context));
initial.commit586acc5fe2008-07-26 22:42:5266 }
[email protected]25f47352011-02-25 16:31:5967
Helen Liac3c51e2018-04-24 00:02:1368 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
dchengb03027d2014-10-21 12:00:2084 void ClearSSLSessionCache() override { SSLClientSocket::ClearSessionCache(); }
initial.commit586acc5fe2008-07-26 22:42:5285};
86
[email protected]53998282012-06-06 22:08:5287static base::LazyInstance<DefaultClientSocketFactory>::Leaky
[email protected]6de0fd1d2011-11-15 13:31:4988 g_default_client_socket_factory = LAZY_INSTANCE_INITIALIZER;
[email protected]625332e02010-12-14 07:48:4989
[email protected]abe48d32010-02-03 02:09:3690} // namespace
91
[email protected]d100e44f2011-01-26 22:47:1192// static
93ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() {
94 return g_default_client_socket_factory.Pointer();
95}
96
initial.commit586acc5fe2008-07-26 22:42:5297} // namespace net