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_
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"
24 class ClientSocketFactory
;
25 class ClientSocketPoolHistograms
;
27 class HttpProxyClientSocketPool
;
30 class ServerBoundCertService
;
32 class SOCKSClientSocketPool
;
33 class SSLClientSocketPool
;
34 class SSLConfigService
;
35 class TransportClientSocketPool
;
36 class TransportSecurityState
;
40 // A helper class for auto-deleting Values in the destructor.
41 template <typename Key
, typename Value
>
42 class OwnedPoolMap
: public std::map
<Key
, Value
> {
45 COMPILE_ASSERT(base::is_pointer
<Value
>::value
,
46 value_must_be_a_pointer
);
50 STLDeleteValues(this);
54 } // namespace internal
56 class ClientSocketPoolManagerImpl
: public base::NonThreadSafe
,
57 public ClientSocketPoolManager
,
58 public CertDatabase::Observer
{
60 ClientSocketPoolManagerImpl(NetLog
* net_log
,
61 ClientSocketFactory
* socket_factory
,
62 HostResolver
* host_resolver
,
63 CertVerifier
* cert_verifier
,
64 ServerBoundCertService
* server_bound_cert_service
,
65 TransportSecurityState
* transport_security_state
,
66 CTVerifier
* cert_transparency_verifier
,
67 const std::string
& ssl_session_cache_shard
,
68 ProxyService
* proxy_service
,
69 SSLConfigService
* ssl_config_service
,
70 HttpNetworkSession::SocketPoolType pool_type
);
71 virtual ~ClientSocketPoolManagerImpl();
73 virtual void FlushSocketPoolsWithError(int error
) OVERRIDE
;
74 virtual void CloseIdleSockets() OVERRIDE
;
76 virtual TransportClientSocketPool
* GetTransportSocketPool() OVERRIDE
;
78 virtual SSLClientSocketPool
* GetSSLSocketPool() OVERRIDE
;
80 virtual SOCKSClientSocketPool
* GetSocketPoolForSOCKSProxy(
81 const HostPortPair
& socks_proxy
) OVERRIDE
;
83 virtual HttpProxyClientSocketPool
* GetSocketPoolForHTTPProxy(
84 const HostPortPair
& http_proxy
) OVERRIDE
;
86 virtual SSLClientSocketPool
* GetSocketPoolForSSLWithProxy(
87 const HostPortPair
& proxy_server
) OVERRIDE
;
89 // Creates a Value summary of the state of the socket pools. The caller is
90 // responsible for deleting the returned value.
91 virtual base::Value
* SocketPoolInfoToValue() const OVERRIDE
;
93 // CertDatabase::Observer methods:
94 virtual void OnCertAdded(const X509Certificate
* cert
) OVERRIDE
;
95 virtual void OnCACertChanged(const X509Certificate
* cert
) OVERRIDE
;
98 typedef internal::OwnedPoolMap
<HostPortPair
, TransportClientSocketPool
*>
99 TransportSocketPoolMap
;
100 typedef internal::OwnedPoolMap
<HostPortPair
, SOCKSClientSocketPool
*>
102 typedef internal::OwnedPoolMap
<HostPortPair
, HttpProxyClientSocketPool
*>
103 HTTPProxySocketPoolMap
;
104 typedef internal::OwnedPoolMap
<HostPortPair
, SSLClientSocketPool
*>
107 NetLog
* const net_log_
;
108 ClientSocketFactory
* const socket_factory_
;
109 HostResolver
* const host_resolver_
;
110 CertVerifier
* const cert_verifier_
;
111 ServerBoundCertService
* const server_bound_cert_service_
;
112 TransportSecurityState
* const transport_security_state_
;
113 CTVerifier
* const cert_transparency_verifier_
;
114 const std::string ssl_session_cache_shard_
;
115 ProxyService
* const proxy_service_
;
116 const scoped_refptr
<SSLConfigService
> ssl_config_service_
;
117 const HttpNetworkSession::SocketPoolType pool_type_
;
119 // Note: this ordering is important.
121 ClientSocketPoolHistograms transport_pool_histograms_
;
122 scoped_ptr
<TransportClientSocketPool
> transport_socket_pool_
;
124 ClientSocketPoolHistograms ssl_pool_histograms_
;
125 scoped_ptr
<SSLClientSocketPool
> ssl_socket_pool_
;
127 ClientSocketPoolHistograms transport_for_socks_pool_histograms_
;
128 TransportSocketPoolMap transport_socket_pools_for_socks_proxies_
;
130 ClientSocketPoolHistograms socks_pool_histograms_
;
131 SOCKSSocketPoolMap socks_socket_pools_
;
133 ClientSocketPoolHistograms transport_for_http_proxy_pool_histograms_
;
134 TransportSocketPoolMap transport_socket_pools_for_http_proxies_
;
136 ClientSocketPoolHistograms transport_for_https_proxy_pool_histograms_
;
137 TransportSocketPoolMap transport_socket_pools_for_https_proxies_
;
139 ClientSocketPoolHistograms ssl_for_https_proxy_pool_histograms_
;
140 SSLSocketPoolMap ssl_socket_pools_for_https_proxies_
;
142 ClientSocketPoolHistograms http_proxy_pool_histograms_
;
143 HTTPProxySocketPoolMap http_proxy_socket_pools_
;
145 ClientSocketPoolHistograms ssl_socket_pool_for_proxies_histograms_
;
146 SSLSocketPoolMap ssl_socket_pools_for_proxies_
;
148 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolManagerImpl
);
153 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_IMPL_H_