OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/socket/client_socket_pool_manager_impl.h" | 5 #include "net/socket/client_socket_pool_manager_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "net/base/ssl_config_service.h" | 9 #include "net/base/ssl_config_service.h" |
10 #include "net/http/http_proxy_client_socket_pool.h" | 10 #include "net/http/http_proxy_client_socket_pool.h" |
| 11 #include "net/http/http_network_session.h" |
11 #include "net/socket/socks_client_socket_pool.h" | 12 #include "net/socket/socks_client_socket_pool.h" |
12 #include "net/socket/ssl_client_socket_pool.h" | 13 #include "net/socket/ssl_client_socket_pool.h" |
13 #include "net/socket/transport_client_socket_pool.h" | 14 #include "net/socket/transport_client_socket_pool.h" |
14 | 15 |
15 namespace net { | 16 namespace net { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Appends information about all |socket_pools| to the end of |list|. | 20 // Appends information about all |socket_pools| to the end of |list|. |
20 template <class MapType> | 21 template <class MapType> |
(...skipping 14 matching lines...) Expand all Loading... |
35 ClientSocketPoolManagerImpl::ClientSocketPoolManagerImpl( | 36 ClientSocketPoolManagerImpl::ClientSocketPoolManagerImpl( |
36 NetLog* net_log, | 37 NetLog* net_log, |
37 ClientSocketFactory* socket_factory, | 38 ClientSocketFactory* socket_factory, |
38 HostResolver* host_resolver, | 39 HostResolver* host_resolver, |
39 CertVerifier* cert_verifier, | 40 CertVerifier* cert_verifier, |
40 ServerBoundCertService* server_bound_cert_service, | 41 ServerBoundCertService* server_bound_cert_service, |
41 TransportSecurityState* transport_security_state, | 42 TransportSecurityState* transport_security_state, |
42 SSLHostInfoFactory* ssl_host_info_factory, | 43 SSLHostInfoFactory* ssl_host_info_factory, |
43 const std::string& ssl_session_cache_shard, | 44 const std::string& ssl_session_cache_shard, |
44 ProxyService* proxy_service, | 45 ProxyService* proxy_service, |
45 SSLConfigService* ssl_config_service) | 46 SSLConfigService* ssl_config_service, |
| 47 HttpNetworkSession::SocketPoolType pool_type) |
46 : net_log_(net_log), | 48 : net_log_(net_log), |
47 socket_factory_(socket_factory), | 49 socket_factory_(socket_factory), |
48 host_resolver_(host_resolver), | 50 host_resolver_(host_resolver), |
49 cert_verifier_(cert_verifier), | 51 cert_verifier_(cert_verifier), |
50 server_bound_cert_service_(server_bound_cert_service), | 52 server_bound_cert_service_(server_bound_cert_service), |
51 transport_security_state_(transport_security_state), | 53 transport_security_state_(transport_security_state), |
52 ssl_host_info_factory_(ssl_host_info_factory), | 54 ssl_host_info_factory_(ssl_host_info_factory), |
53 ssl_session_cache_shard_(ssl_session_cache_shard), | 55 ssl_session_cache_shard_(ssl_session_cache_shard), |
54 proxy_service_(proxy_service), | 56 proxy_service_(proxy_service), |
55 ssl_config_service_(ssl_config_service), | 57 ssl_config_service_(ssl_config_service), |
| 58 pool_type_(pool_type), |
56 transport_pool_histograms_("TCP"), | 59 transport_pool_histograms_("TCP"), |
57 transport_socket_pool_(new TransportClientSocketPool( | 60 transport_socket_pool_(new TransportClientSocketPool( |
58 max_sockets_per_pool(), max_sockets_per_group(), | 61 max_sockets_per_pool(pool_type), max_sockets_per_group(pool_type), |
59 &transport_pool_histograms_, | 62 &transport_pool_histograms_, |
60 host_resolver, | 63 host_resolver, |
61 socket_factory_, | 64 socket_factory_, |
62 net_log)), | 65 net_log)), |
63 ssl_pool_histograms_("SSL2"), | 66 ssl_pool_histograms_("SSL2"), |
64 ssl_socket_pool_(new SSLClientSocketPool( | 67 ssl_socket_pool_(new SSLClientSocketPool( |
65 max_sockets_per_pool(), max_sockets_per_group(), | 68 max_sockets_per_pool(pool_type), max_sockets_per_group(pool_type), |
66 &ssl_pool_histograms_, | 69 &ssl_pool_histograms_, |
67 host_resolver, | 70 host_resolver, |
68 cert_verifier, | 71 cert_verifier, |
69 server_bound_cert_service, | 72 server_bound_cert_service, |
70 transport_security_state, | 73 transport_security_state, |
71 ssl_host_info_factory, | 74 ssl_host_info_factory, |
72 ssl_session_cache_shard, | 75 ssl_session_cache_shard, |
73 socket_factory, | 76 socket_factory, |
74 transport_socket_pool_.get(), | 77 transport_socket_pool_.get(), |
75 NULL /* no socks proxy */, | 78 NULL /* no socks proxy */, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 return it->second; | 209 return it->second; |
207 } | 210 } |
208 | 211 |
209 DCHECK(!ContainsKey(transport_socket_pools_for_socks_proxies_, socks_proxy)); | 212 DCHECK(!ContainsKey(transport_socket_pools_for_socks_proxies_, socks_proxy)); |
210 | 213 |
211 std::pair<TransportSocketPoolMap::iterator, bool> tcp_ret = | 214 std::pair<TransportSocketPoolMap::iterator, bool> tcp_ret = |
212 transport_socket_pools_for_socks_proxies_.insert( | 215 transport_socket_pools_for_socks_proxies_.insert( |
213 std::make_pair( | 216 std::make_pair( |
214 socks_proxy, | 217 socks_proxy, |
215 new TransportClientSocketPool( | 218 new TransportClientSocketPool( |
216 max_sockets_per_proxy_server(), | 219 max_sockets_per_proxy_server(pool_type_), |
217 max_sockets_per_group(), | 220 max_sockets_per_group(pool_type_), |
218 &transport_for_socks_pool_histograms_, | 221 &transport_for_socks_pool_histograms_, |
219 host_resolver_, | 222 host_resolver_, |
220 socket_factory_, | 223 socket_factory_, |
221 net_log_))); | 224 net_log_))); |
222 DCHECK(tcp_ret.second); | 225 DCHECK(tcp_ret.second); |
223 | 226 |
224 std::pair<SOCKSSocketPoolMap::iterator, bool> ret = | 227 std::pair<SOCKSSocketPoolMap::iterator, bool> ret = |
225 socks_socket_pools_.insert( | 228 socks_socket_pools_.insert( |
226 std::make_pair(socks_proxy, new SOCKSClientSocketPool( | 229 std::make_pair(socks_proxy, new SOCKSClientSocketPool( |
227 max_sockets_per_proxy_server(), | 230 max_sockets_per_proxy_server(pool_type_), |
228 max_sockets_per_group(), | 231 max_sockets_per_group(pool_type_), |
229 &socks_pool_histograms_, | 232 &socks_pool_histograms_, |
230 host_resolver_, | 233 host_resolver_, |
231 tcp_ret.first->second, | 234 tcp_ret.first->second, |
232 net_log_))); | 235 net_log_))); |
233 | 236 |
234 return ret.first->second; | 237 return ret.first->second; |
235 } | 238 } |
236 | 239 |
237 HttpProxyClientSocketPool* | 240 HttpProxyClientSocketPool* |
238 ClientSocketPoolManagerImpl::GetSocketPoolForHTTPProxy( | 241 ClientSocketPoolManagerImpl::GetSocketPoolForHTTPProxy( |
239 const HostPortPair& http_proxy) { | 242 const HostPortPair& http_proxy) { |
240 HTTPProxySocketPoolMap::const_iterator it = | 243 HTTPProxySocketPoolMap::const_iterator it = |
241 http_proxy_socket_pools_.find(http_proxy); | 244 http_proxy_socket_pools_.find(http_proxy); |
242 if (it != http_proxy_socket_pools_.end()) { | 245 if (it != http_proxy_socket_pools_.end()) { |
243 DCHECK(ContainsKey(transport_socket_pools_for_http_proxies_, http_proxy)); | 246 DCHECK(ContainsKey(transport_socket_pools_for_http_proxies_, http_proxy)); |
244 DCHECK(ContainsKey(transport_socket_pools_for_https_proxies_, http_proxy)); | 247 DCHECK(ContainsKey(transport_socket_pools_for_https_proxies_, http_proxy)); |
245 DCHECK(ContainsKey(ssl_socket_pools_for_https_proxies_, http_proxy)); | 248 DCHECK(ContainsKey(ssl_socket_pools_for_https_proxies_, http_proxy)); |
246 return it->second; | 249 return it->second; |
247 } | 250 } |
248 | 251 |
249 DCHECK(!ContainsKey(transport_socket_pools_for_http_proxies_, http_proxy)); | 252 DCHECK(!ContainsKey(transport_socket_pools_for_http_proxies_, http_proxy)); |
250 DCHECK(!ContainsKey(transport_socket_pools_for_https_proxies_, http_proxy)); | 253 DCHECK(!ContainsKey(transport_socket_pools_for_https_proxies_, http_proxy)); |
251 DCHECK(!ContainsKey(ssl_socket_pools_for_https_proxies_, http_proxy)); | 254 DCHECK(!ContainsKey(ssl_socket_pools_for_https_proxies_, http_proxy)); |
252 | 255 |
253 std::pair<TransportSocketPoolMap::iterator, bool> tcp_http_ret = | 256 std::pair<TransportSocketPoolMap::iterator, bool> tcp_http_ret = |
254 transport_socket_pools_for_http_proxies_.insert( | 257 transport_socket_pools_for_http_proxies_.insert( |
255 std::make_pair( | 258 std::make_pair( |
256 http_proxy, | 259 http_proxy, |
257 new TransportClientSocketPool( | 260 new TransportClientSocketPool( |
258 max_sockets_per_proxy_server(), | 261 max_sockets_per_proxy_server(pool_type_), |
259 max_sockets_per_group(), | 262 max_sockets_per_group(pool_type_), |
260 &transport_for_http_proxy_pool_histograms_, | 263 &transport_for_http_proxy_pool_histograms_, |
261 host_resolver_, | 264 host_resolver_, |
262 socket_factory_, | 265 socket_factory_, |
263 net_log_))); | 266 net_log_))); |
264 DCHECK(tcp_http_ret.second); | 267 DCHECK(tcp_http_ret.second); |
265 | 268 |
266 std::pair<TransportSocketPoolMap::iterator, bool> tcp_https_ret = | 269 std::pair<TransportSocketPoolMap::iterator, bool> tcp_https_ret = |
267 transport_socket_pools_for_https_proxies_.insert( | 270 transport_socket_pools_for_https_proxies_.insert( |
268 std::make_pair( | 271 std::make_pair( |
269 http_proxy, | 272 http_proxy, |
270 new TransportClientSocketPool( | 273 new TransportClientSocketPool( |
271 max_sockets_per_proxy_server(), | 274 max_sockets_per_proxy_server(pool_type_), |
272 max_sockets_per_group(), | 275 max_sockets_per_group(pool_type_), |
273 &transport_for_https_proxy_pool_histograms_, | 276 &transport_for_https_proxy_pool_histograms_, |
274 host_resolver_, | 277 host_resolver_, |
275 socket_factory_, | 278 socket_factory_, |
276 net_log_))); | 279 net_log_))); |
277 DCHECK(tcp_https_ret.second); | 280 DCHECK(tcp_https_ret.second); |
278 | 281 |
279 std::pair<SSLSocketPoolMap::iterator, bool> ssl_https_ret = | 282 std::pair<SSLSocketPoolMap::iterator, bool> ssl_https_ret = |
280 ssl_socket_pools_for_https_proxies_.insert( | 283 ssl_socket_pools_for_https_proxies_.insert( |
281 std::make_pair( | 284 std::make_pair( |
282 http_proxy, | 285 http_proxy, |
283 new SSLClientSocketPool( | 286 new SSLClientSocketPool( |
284 max_sockets_per_proxy_server(), | 287 max_sockets_per_proxy_server(pool_type_), |
285 max_sockets_per_group(), | 288 max_sockets_per_group(pool_type_), |
286 &ssl_for_https_proxy_pool_histograms_, | 289 &ssl_for_https_proxy_pool_histograms_, |
287 host_resolver_, | 290 host_resolver_, |
288 cert_verifier_, | 291 cert_verifier_, |
289 server_bound_cert_service_, | 292 server_bound_cert_service_, |
290 transport_security_state_, | 293 transport_security_state_, |
291 ssl_host_info_factory_, | 294 ssl_host_info_factory_, |
292 ssl_session_cache_shard_, | 295 ssl_session_cache_shard_, |
293 socket_factory_, | 296 socket_factory_, |
294 tcp_https_ret.first->second /* https proxy */, | 297 tcp_https_ret.first->second /* https proxy */, |
295 NULL /* no socks proxy */, | 298 NULL /* no socks proxy */, |
296 NULL /* no http proxy */, | 299 NULL /* no http proxy */, |
297 ssl_config_service_, net_log_))); | 300 ssl_config_service_, net_log_))); |
298 DCHECK(tcp_https_ret.second); | 301 DCHECK(tcp_https_ret.second); |
299 | 302 |
300 std::pair<HTTPProxySocketPoolMap::iterator, bool> ret = | 303 std::pair<HTTPProxySocketPoolMap::iterator, bool> ret = |
301 http_proxy_socket_pools_.insert( | 304 http_proxy_socket_pools_.insert( |
302 std::make_pair( | 305 std::make_pair( |
303 http_proxy, | 306 http_proxy, |
304 new HttpProxyClientSocketPool( | 307 new HttpProxyClientSocketPool( |
305 max_sockets_per_proxy_server(), | 308 max_sockets_per_proxy_server(pool_type_), |
306 max_sockets_per_group(), | 309 max_sockets_per_group(pool_type_), |
307 &http_proxy_pool_histograms_, | 310 &http_proxy_pool_histograms_, |
308 host_resolver_, | 311 host_resolver_, |
309 tcp_http_ret.first->second, | 312 tcp_http_ret.first->second, |
310 ssl_https_ret.first->second, | 313 ssl_https_ret.first->second, |
311 net_log_))); | 314 net_log_))); |
312 | 315 |
313 return ret.first->second; | 316 return ret.first->second; |
314 } | 317 } |
315 | 318 |
316 SSLClientSocketPool* ClientSocketPoolManagerImpl::GetSocketPoolForSSLWithProxy( | 319 SSLClientSocketPool* ClientSocketPoolManagerImpl::GetSocketPoolForSSLWithProxy( |
317 const HostPortPair& proxy_server) { | 320 const HostPortPair& proxy_server) { |
318 SSLSocketPoolMap::const_iterator it = | 321 SSLSocketPoolMap::const_iterator it = |
319 ssl_socket_pools_for_proxies_.find(proxy_server); | 322 ssl_socket_pools_for_proxies_.find(proxy_server); |
320 if (it != ssl_socket_pools_for_proxies_.end()) | 323 if (it != ssl_socket_pools_for_proxies_.end()) |
321 return it->second; | 324 return it->second; |
322 | 325 |
323 SSLClientSocketPool* new_pool = new SSLClientSocketPool( | 326 SSLClientSocketPool* new_pool = new SSLClientSocketPool( |
324 max_sockets_per_proxy_server(), max_sockets_per_group(), | 327 max_sockets_per_proxy_server(pool_type_), |
| 328 max_sockets_per_group(pool_type_), |
325 &ssl_pool_histograms_, | 329 &ssl_pool_histograms_, |
326 host_resolver_, | 330 host_resolver_, |
327 cert_verifier_, | 331 cert_verifier_, |
328 server_bound_cert_service_, | 332 server_bound_cert_service_, |
329 transport_security_state_, | 333 transport_security_state_, |
330 ssl_host_info_factory_, | 334 ssl_host_info_factory_, |
331 ssl_session_cache_shard_, | 335 ssl_session_cache_shard_, |
332 socket_factory_, | 336 socket_factory_, |
333 NULL, /* no tcp pool, we always go through a proxy */ | 337 NULL, /* no tcp pool, we always go through a proxy */ |
334 GetSocketPoolForSOCKSProxy(proxy_server), | 338 GetSocketPoolForSOCKSProxy(proxy_server), |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 // We should not flush the socket pools if we added trust to a | 389 // We should not flush the socket pools if we added trust to a |
386 // cert. | 390 // cert. |
387 // | 391 // |
388 // Since the OnCertTrustChanged method doesn't tell us what | 392 // Since the OnCertTrustChanged method doesn't tell us what |
389 // kind of trust change it is, we have to flush the socket | 393 // kind of trust change it is, we have to flush the socket |
390 // pools to be safe. | 394 // pools to be safe. |
391 FlushSocketPools(); | 395 FlushSocketPools(); |
392 } | 396 } |
393 | 397 |
394 } // namespace net | 398 } // namespace net |
OLD | NEW |