Show Pages in chrome://md-settings
[chromium-blink-merge.git] / net / socket / client_socket_pool_manager_impl.h
blob1c6295b287d6b4bfd8293191a9cf02f7174f7c94
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_IMPL_H_
6 #define NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_IMPL_H_
8 #include <map>
9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/stl_util.h"
14 #include "base/template_util.h"
15 #include "base/threading/non_thread_safe.h"
16 #include "net/cert/cert_database.h"
17 #include "net/http/http_network_session.h"
18 #include "net/socket/client_socket_pool_histograms.h"
19 #include "net/socket/client_socket_pool_manager.h"
21 namespace net {
23 class CertVerifier;
24 class ChannelIDService;
25 class ClientSocketFactory;
26 class ClientSocketPoolHistograms;
27 class CTVerifier;
28 class HttpProxyClientSocketPool;
29 class HostResolver;
30 class NetLog;
31 class SOCKSClientSocketPool;
32 class SSLClientSocketPool;
33 class SSLConfigService;
34 class TransportClientSocketPool;
35 class TransportSecurityState;
37 namespace internal {
39 // A helper class for auto-deleting Values in the destructor.
40 template <typename Key, typename Value>
41 class OwnedPoolMap : public std::map<Key, Value> {
42 public:
43 OwnedPoolMap() {
44 static_assert(base::is_pointer<Value>::value, "value must be a pointer");
47 ~OwnedPoolMap() {
48 STLDeleteValues(this);
52 } // namespace internal
54 class ClientSocketPoolManagerImpl : public base::NonThreadSafe,
55 public ClientSocketPoolManager,
56 public CertDatabase::Observer {
57 public:
58 ClientSocketPoolManagerImpl(NetLog* net_log,
59 ClientSocketFactory* socket_factory,
60 HostResolver* host_resolver,
61 CertVerifier* cert_verifier,
62 ChannelIDService* channel_id_service,
63 TransportSecurityState* transport_security_state,
64 CTVerifier* cert_transparency_verifier,
65 CertPolicyEnforcer* cert_policy_enforcer,
66 const std::string& ssl_session_cache_shard,
67 SSLConfigService* ssl_config_service,
68 HttpNetworkSession::SocketPoolType pool_type);
69 ~ClientSocketPoolManagerImpl() override;
71 void FlushSocketPoolsWithError(int error) override;
72 void CloseIdleSockets() override;
74 TransportClientSocketPool* GetTransportSocketPool() override;
76 SSLClientSocketPool* GetSSLSocketPool() override;
78 SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy(
79 const HostPortPair& socks_proxy) override;
81 HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy(
82 const HostPortPair& http_proxy) override;
84 SSLClientSocketPool* GetSocketPoolForSSLWithProxy(
85 const HostPortPair& proxy_server) override;
87 // Creates a Value summary of the state of the socket pools. The caller is
88 // responsible for deleting the returned value.
89 base::Value* SocketPoolInfoToValue() const override;
91 // CertDatabase::Observer methods:
92 void OnCertAdded(const X509Certificate* cert) override;
93 void OnCACertChanged(const X509Certificate* cert) override;
95 private:
96 typedef internal::OwnedPoolMap<HostPortPair, TransportClientSocketPool*>
97 TransportSocketPoolMap;
98 typedef internal::OwnedPoolMap<HostPortPair, SOCKSClientSocketPool*>
99 SOCKSSocketPoolMap;
100 typedef internal::OwnedPoolMap<HostPortPair, HttpProxyClientSocketPool*>
101 HTTPProxySocketPoolMap;
102 typedef internal::OwnedPoolMap<HostPortPair, SSLClientSocketPool*>
103 SSLSocketPoolMap;
105 NetLog* const net_log_;
106 ClientSocketFactory* const socket_factory_;
107 HostResolver* const host_resolver_;
108 CertVerifier* const cert_verifier_;
109 ChannelIDService* const channel_id_service_;
110 TransportSecurityState* const transport_security_state_;
111 CTVerifier* const cert_transparency_verifier_;
112 CertPolicyEnforcer* const cert_policy_enforcer_;
113 const std::string ssl_session_cache_shard_;
114 const scoped_refptr<SSLConfigService> ssl_config_service_;
115 const HttpNetworkSession::SocketPoolType pool_type_;
117 // Note: this ordering is important.
119 ClientSocketPoolHistograms transport_pool_histograms_;
120 scoped_ptr<TransportClientSocketPool> transport_socket_pool_;
122 ClientSocketPoolHistograms ssl_pool_histograms_;
123 scoped_ptr<SSLClientSocketPool> ssl_socket_pool_;
125 ClientSocketPoolHistograms transport_for_socks_pool_histograms_;
126 TransportSocketPoolMap transport_socket_pools_for_socks_proxies_;
128 ClientSocketPoolHistograms socks_pool_histograms_;
129 SOCKSSocketPoolMap socks_socket_pools_;
131 ClientSocketPoolHistograms transport_for_http_proxy_pool_histograms_;
132 TransportSocketPoolMap transport_socket_pools_for_http_proxies_;
134 ClientSocketPoolHistograms transport_for_https_proxy_pool_histograms_;
135 TransportSocketPoolMap transport_socket_pools_for_https_proxies_;
137 ClientSocketPoolHistograms ssl_for_https_proxy_pool_histograms_;
138 SSLSocketPoolMap ssl_socket_pools_for_https_proxies_;
140 ClientSocketPoolHistograms http_proxy_pool_histograms_;
141 HTTPProxySocketPoolMap http_proxy_socket_pools_;
143 ClientSocketPoolHistograms ssl_socket_pool_for_proxies_histograms_;
144 SSLSocketPoolMap ssl_socket_pools_for_proxies_;
146 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolManagerImpl);
149 } // namespace net
151 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_IMPL_H_