blob: 96caa314a4139bd3d22ed2311b63395ef5203d80 [file] [log] [blame]
[email protected]a42dbd142011-11-17 16:42:021// Copyright (c) 2011 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.
4
5#ifndef NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_IMPL_H_
6#define NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_IMPL_H_
7#pragma once
8
9#include <map>
10#include "base/basictypes.h"
11#include "base/compiler_specific.h"
12#include "base/memory/ref_counted.h"
13#include "base/memory/scoped_ptr.h"
14#include "base/stl_util.h"
15#include "base/template_util.h"
16#include "base/threading/non_thread_safe.h"
17#include "net/base/cert_database.h"
18#include "net/socket/client_socket_pool_histograms.h"
19#include "net/socket/client_socket_pool_manager.h"
20
21namespace net {
22
23class CertVerifier;
24class ClientSocketFactory;
25class ClientSocketPoolHistograms;
[email protected]a42dbd142011-11-17 16:42:0226class HttpProxyClientSocketPool;
27class HostResolver;
28class NetLog;
29class OriginBoundCertService;
30class ProxyService;
31class SOCKSClientSocketPool;
32class SSLClientSocketPool;
33class SSLConfigService;
34class SSLHostInfoFactory;
35class TransportClientSocketPool;
[email protected]a2a41972011-12-07 17:47:2736class TransportSecurityState;
[email protected]a42dbd142011-11-17 16:42:0237
38namespace internal {
39
40// A helper class for auto-deleting Values in the destructor.
41template <typename Key, typename Value>
42class OwnedPoolMap : public std::map<Key, Value> {
43 public:
44 OwnedPoolMap() {
45 COMPILE_ASSERT(base::is_pointer<Value>::value,
46 value_must_be_a_pointer);
47 }
48
49 ~OwnedPoolMap() {
50 STLDeleteValues(this);
51 }
52};
53
54} // namespace internal
55
56class 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 OriginBoundCertService* origin_bound_cert_service,
[email protected]a2a41972011-12-07 17:47:2765 TransportSecurityState* transport_security_state,
[email protected]a42dbd142011-11-17 16:42:0266 SSLHostInfoFactory* ssl_host_info_factory,
[email protected]c3456bb2011-12-12 22:22:1967 const std::string& ssl_session_cache_shard,
[email protected]a42dbd142011-11-17 16:42:0268 ProxyService* proxy_service,
69 SSLConfigService* ssl_config_service);
70 virtual ~ClientSocketPoolManagerImpl();
71
72 virtual void FlushSocketPools() OVERRIDE;
73 virtual void CloseIdleSockets() OVERRIDE;
74
75 virtual TransportClientSocketPool* GetTransportSocketPool() OVERRIDE;
76
77 virtual SSLClientSocketPool* GetSSLSocketPool() OVERRIDE;
78
79 virtual SOCKSClientSocketPool* GetSocketPoolForSOCKSProxy(
80 const HostPortPair& socks_proxy) OVERRIDE;
81
82 virtual HttpProxyClientSocketPool* GetSocketPoolForHTTPProxy(
83 const HostPortPair& http_proxy) OVERRIDE;
84
85 virtual SSLClientSocketPool* GetSocketPoolForSSLWithProxy(
86 const HostPortPair& proxy_server) OVERRIDE;
87
88 // Creates a Value summary of the state of the socket pools. The caller is
89 // responsible for deleting the returned value.
90 virtual base::Value* SocketPoolInfoToValue() const OVERRIDE;
91
92 // CertDatabase::Observer methods:
93 virtual void OnUserCertAdded(const X509Certificate* cert) OVERRIDE;
94 virtual void OnCertTrustChanged(const X509Certificate* cert) OVERRIDE;
95
96 private:
97 typedef internal::OwnedPoolMap<HostPortPair, TransportClientSocketPool*>
98 TransportSocketPoolMap;
99 typedef internal::OwnedPoolMap<HostPortPair, SOCKSClientSocketPool*>
100 SOCKSSocketPoolMap;
101 typedef internal::OwnedPoolMap<HostPortPair, HttpProxyClientSocketPool*>
102 HTTPProxySocketPoolMap;
103 typedef internal::OwnedPoolMap<HostPortPair, SSLClientSocketPool*>
104 SSLSocketPoolMap;
105
106 NetLog* const net_log_;
107 ClientSocketFactory* const socket_factory_;
108 HostResolver* const host_resolver_;
109 CertVerifier* const cert_verifier_;
110 OriginBoundCertService* const origin_bound_cert_service_;
[email protected]a2a41972011-12-07 17:47:27111 TransportSecurityState* const transport_security_state_;
[email protected]a42dbd142011-11-17 16:42:02112 SSLHostInfoFactory* const ssl_host_info_factory_;
[email protected]c3456bb2011-12-12 22:22:19113 const std::string ssl_session_cache_shard_;
[email protected]a42dbd142011-11-17 16:42:02114 ProxyService* const proxy_service_;
115 const scoped_refptr<SSLConfigService> ssl_config_service_;
116
117 // Note: this ordering is important.
118
119 ClientSocketPoolHistograms transport_pool_histograms_;
120 scoped_ptr<TransportClientSocketPool> transport_socket_pool_;
121
122 ClientSocketPoolHistograms ssl_pool_histograms_;
123 scoped_ptr<SSLClientSocketPool> ssl_socket_pool_;
124
125 ClientSocketPoolHistograms transport_for_socks_pool_histograms_;
126 TransportSocketPoolMap transport_socket_pools_for_socks_proxies_;
127
128 ClientSocketPoolHistograms socks_pool_histograms_;
129 SOCKSSocketPoolMap socks_socket_pools_;
130
131 ClientSocketPoolHistograms transport_for_http_proxy_pool_histograms_;
132 TransportSocketPoolMap transport_socket_pools_for_http_proxies_;
133
134 ClientSocketPoolHistograms transport_for_https_proxy_pool_histograms_;
135 TransportSocketPoolMap transport_socket_pools_for_https_proxies_;
136
137 ClientSocketPoolHistograms ssl_for_https_proxy_pool_histograms_;
138 SSLSocketPoolMap ssl_socket_pools_for_https_proxies_;
139
140 ClientSocketPoolHistograms http_proxy_pool_histograms_;
141 HTTPProxySocketPoolMap http_proxy_socket_pools_;
142
143 ClientSocketPoolHistograms ssl_socket_pool_for_proxies_histograms_;
144 SSLSocketPoolMap ssl_socket_pools_for_proxies_;
145
146 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolManagerImpl);
147};
148
149} // namespace net
150
151#endif // NET_SOCKET_CLIENT_SOCKET_POOL_MANAGER_IMPL_H_