Chromecast: adds class to help record complex histograms.
[chromium-blink-merge.git] / net / socket / client_socket_pool_manager_impl.h
blob94fd55ddd79558fb6d44153e1ce5e712b265e0fc
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 ProxyDelegate;
32 class ProxyService;
33 class SOCKSClientSocketPool;
34 class SSLClientSocketPool;
35 class SSLConfigService;
36 class TransportClientSocketPool;
37 class TransportSecurityState;
39 namespace internal {
41 // A helper class for auto-deleting Values in the destructor.
42 template <typename Key, typename Value>
43 class OwnedPoolMap : public std::map<Key, Value> {
44 public:
45 OwnedPoolMap() {
46 COMPILE_ASSERT(base::is_pointer<Value>::value,
47 value_must_be_a_pointer);
50 ~OwnedPoolMap() {
51 STLDeleteValues(this);
55 } // namespace internal
57 class ClientSocketPoolManagerImpl : public base::NonThreadSafe,
58 public ClientSocketPoolManager,
59 public CertDatabase::Observer {
60 public:
61 ClientSocketPoolManagerImpl(NetLog* net_log,
62 ClientSocketFactory* socket_factory,
63 HostResolver* host_resolver,
64 CertVerifier* cert_verifier,
65 ChannelIDService* channel_id_service,
66 TransportSecurityState* transport_security_state,
67 CTVerifier* cert_transparency_verifier,
68 const std::string& ssl_session_cache_shard,
69 ProxyService* proxy_service,
70 SSLConfigService* ssl_config_service,
71 bool enable_ssl_connect_job_waiting,
72 ProxyDelegate* proxy_delegate,
73 HttpNetworkSession::SocketPoolType pool_type);
74 virtual ~ClientSocketPoolManagerImpl();
76 virtual void FlushSocketPoolsWithError(int error) override;
77 virtual void CloseIdleSockets() override;
79 virtual TransportClientSocketPool* GetTransportSocketPool() override;
81 virtual SSLClientSocketPool* GetSSLSocketPool() override;
83 virtual SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy(
84 const HostPortPair& socks_proxy) override;
86 virtual HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy(
87 const HostPortPair& http_proxy) override;
89 virtual SSLClientSocketPool* GetSocketPoolForSSLWithProxy(
90 const HostPortPair& proxy_server) override;
92 // Creates a Value summary of the state of the socket pools. The caller is
93 // responsible for deleting the returned value.
94 virtual base::Value* SocketPoolInfoToValue() const override;
96 // CertDatabase::Observer methods:
97 virtual void OnCertAdded(const X509Certificate* cert) override;
98 virtual void OnCACertChanged(const X509Certificate* cert) override;
100 private:
101 typedef internal::OwnedPoolMap<HostPortPair, TransportClientSocketPool*>
102 TransportSocketPoolMap;
103 typedef internal::OwnedPoolMap<HostPortPair, SOCKSClientSocketPool*>
104 SOCKSSocketPoolMap;
105 typedef internal::OwnedPoolMap<HostPortPair, HttpProxyClientSocketPool*>
106 HTTPProxySocketPoolMap;
107 typedef internal::OwnedPoolMap<HostPortPair, SSLClientSocketPool*>
108 SSLSocketPoolMap;
110 NetLog* const net_log_;
111 ClientSocketFactory* const socket_factory_;
112 HostResolver* const host_resolver_;
113 CertVerifier* const cert_verifier_;
114 ChannelIDService* const channel_id_service_;
115 TransportSecurityState* const transport_security_state_;
116 CTVerifier* const cert_transparency_verifier_;
117 const std::string ssl_session_cache_shard_;
118 ProxyService* const proxy_service_;
119 const scoped_refptr<SSLConfigService> ssl_config_service_;
120 bool enable_ssl_connect_job_waiting_;
121 const HttpNetworkSession::SocketPoolType pool_type_;
123 // Note: this ordering is important.
125 ClientSocketPoolHistograms transport_pool_histograms_;
126 scoped_ptr<TransportClientSocketPool> transport_socket_pool_;
128 ClientSocketPoolHistograms ssl_pool_histograms_;
129 scoped_ptr<SSLClientSocketPool> ssl_socket_pool_;
131 ClientSocketPoolHistograms transport_for_socks_pool_histograms_;
132 TransportSocketPoolMap transport_socket_pools_for_socks_proxies_;
134 ClientSocketPoolHistograms socks_pool_histograms_;
135 SOCKSSocketPoolMap socks_socket_pools_;
137 ClientSocketPoolHistograms transport_for_http_proxy_pool_histograms_;
138 TransportSocketPoolMap transport_socket_pools_for_http_proxies_;
140 ClientSocketPoolHistograms transport_for_https_proxy_pool_histograms_;
141 TransportSocketPoolMap transport_socket_pools_for_https_proxies_;
143 ClientSocketPoolHistograms ssl_for_https_proxy_pool_histograms_;
144 SSLSocketPoolMap ssl_socket_pools_for_https_proxies_;
146 ClientSocketPoolHistograms http_proxy_pool_histograms_;
147 HTTPProxySocketPoolMap http_proxy_socket_pools_;
149 ClientSocketPoolHistograms ssl_socket_pool_for_proxies_histograms_;
150 SSLSocketPoolMap ssl_socket_pools_for_proxies_;
152 const ProxyDelegate* proxy_delegate_;
154 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolManagerImpl);
157 } // namespace net
159 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_IMPL_H_