Adding Baseframework of the ResourceManager (all hooks and observers)
[chromium-blink-merge.git] / net / socket / client_socket_pool_manager_impl.h
blob8fc6c49ef8439ccf36aaee2ed10650a2f3c7b6b8
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 ProxyService;
32 class SOCKSClientSocketPool;
33 class SSLClientSocketPool;
34 class SSLConfigService;
35 class TransportClientSocketPool;
36 class TransportSecurityState;
38 namespace internal {
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> {
43 public:
44 OwnedPoolMap() {
45 COMPILE_ASSERT(base::is_pointer<Value>::value,
46 value_must_be_a_pointer);
49 ~OwnedPoolMap() {
50 STLDeleteValues(this);
54 } // namespace internal
56 class ClientSocketPoolManagerImpl : public base::NonThreadSafe,
57 public ClientSocketPoolManager,
58 public CertDatabase::Observer {
59 public:
60 ClientSocketPoolManagerImpl(NetLog* net_log,
61 ClientSocketFactory* socket_factory,
62 HostResolver* host_resolver,
63 CertVerifier* cert_verifier,
64 ChannelIDService* channel_id_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 bool enable_ssl_connect_job_waiting,
71 HttpNetworkSession::SocketPoolType pool_type);
72 virtual ~ClientSocketPoolManagerImpl();
74 virtual void FlushSocketPoolsWithError(int error) OVERRIDE;
75 virtual void CloseIdleSockets() OVERRIDE;
77 virtual TransportClientSocketPool* GetTransportSocketPool() OVERRIDE;
79 virtual SSLClientSocketPool* GetSSLSocketPool() OVERRIDE;
81 virtual SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy(
82 const HostPortPair& socks_proxy) OVERRIDE;
84 virtual HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy(
85 const HostPortPair& http_proxy) OVERRIDE;
87 virtual SSLClientSocketPool* GetSocketPoolForSSLWithProxy(
88 const HostPortPair& proxy_server) OVERRIDE;
90 // Creates a Value summary of the state of the socket pools. The caller is
91 // responsible for deleting the returned value.
92 virtual base::Value* SocketPoolInfoToValue() const OVERRIDE;
94 // CertDatabase::Observer methods:
95 virtual void OnCertAdded(const X509Certificate* cert) OVERRIDE;
96 virtual void OnCACertChanged(const X509Certificate* cert) OVERRIDE;
98 private:
99 typedef internal::OwnedPoolMap<HostPortPair, TransportClientSocketPool*>
100 TransportSocketPoolMap;
101 typedef internal::OwnedPoolMap<HostPortPair, SOCKSClientSocketPool*>
102 SOCKSSocketPoolMap;
103 typedef internal::OwnedPoolMap<HostPortPair, HttpProxyClientSocketPool*>
104 HTTPProxySocketPoolMap;
105 typedef internal::OwnedPoolMap<HostPortPair, SSLClientSocketPool*>
106 SSLSocketPoolMap;
108 NetLog* const net_log_;
109 ClientSocketFactory* const socket_factory_;
110 HostResolver* const host_resolver_;
111 CertVerifier* const cert_verifier_;
112 ChannelIDService* const channel_id_service_;
113 TransportSecurityState* const transport_security_state_;
114 CTVerifier* const cert_transparency_verifier_;
115 const std::string ssl_session_cache_shard_;
116 ProxyService* const proxy_service_;
117 const scoped_refptr<SSLConfigService> ssl_config_service_;
118 bool enable_ssl_connect_job_waiting_;
119 const HttpNetworkSession::SocketPoolType pool_type_;
121 // Note: this ordering is important.
123 ClientSocketPoolHistograms transport_pool_histograms_;
124 scoped_ptr<TransportClientSocketPool> transport_socket_pool_;
126 ClientSocketPoolHistograms ssl_pool_histograms_;
127 scoped_ptr<SSLClientSocketPool> ssl_socket_pool_;
129 ClientSocketPoolHistograms transport_for_socks_pool_histograms_;
130 TransportSocketPoolMap transport_socket_pools_for_socks_proxies_;
132 ClientSocketPoolHistograms socks_pool_histograms_;
133 SOCKSSocketPoolMap socks_socket_pools_;
135 ClientSocketPoolHistograms transport_for_http_proxy_pool_histograms_;
136 TransportSocketPoolMap transport_socket_pools_for_http_proxies_;
138 ClientSocketPoolHistograms transport_for_https_proxy_pool_histograms_;
139 TransportSocketPoolMap transport_socket_pools_for_https_proxies_;
141 ClientSocketPoolHistograms ssl_for_https_proxy_pool_histograms_;
142 SSLSocketPoolMap ssl_socket_pools_for_https_proxies_;
144 ClientSocketPoolHistograms http_proxy_pool_histograms_;
145 HTTPProxySocketPoolMap http_proxy_socket_pools_;
147 ClientSocketPoolHistograms ssl_socket_pool_for_proxies_histograms_;
148 SSLSocketPoolMap ssl_socket_pools_for_proxies_;
150 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolManagerImpl);
153 } // namespace net
155 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_IMPL_H_