Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // 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 | 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 // ClientSocketPoolManager manages access to all ClientSocketPools. It's a | 5 // ClientSocketPoolManager manages access to all ClientSocketPools. It's a |
| 6 // simple container for all of them. Most importantly, it handles the lifetime | 6 // simple container for all of them. Most importantly, it handles the lifetime |
| 7 // and destruction order properly. | 7 // and destruction order properly. |
| 8 | 8 |
| 9 #include "net/socket/client_socket_pool_manager.h" | 9 #include "net/socket/client_socket_pool_manager.h" |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "net/base/ssl_config_service.h" | 16 #include "net/base/ssl_config_service.h" |
| 17 #include "net/http/http_network_session.h" | 17 #include "net/http/http_network_session.h" |
| 18 #include "net/http/http_proxy_client_socket_pool.h" | 18 #include "net/http/http_proxy_client_socket_pool.h" |
| 19 #include "net/http/http_request_info.h" | 19 #include "net/http/http_request_info.h" |
| 20 #include "net/proxy/proxy_service.h" | 20 #include "net/proxy/proxy_service.h" |
| 21 #include "net/socket/client_socket_factory.h" | 21 #include "net/socket/client_socket_factory.h" |
| 22 #include "net/socket/client_socket_handle.h" | 22 #include "net/socket/client_socket_handle.h" |
| 23 #include "net/socket/client_socket_pool_histograms.h" | 23 #include "net/socket/client_socket_pool_histograms.h" |
| 24 #include "net/socket/sctp_client_socket_pool.h" | |
| 25 #include "net/socket/sctp_support.h" | |
| 24 #include "net/socket/socks_client_socket_pool.h" | 26 #include "net/socket/socks_client_socket_pool.h" |
| 25 #include "net/socket/ssl_client_socket_pool.h" | 27 #include "net/socket/ssl_client_socket_pool.h" |
| 26 #include "net/socket/tcp_client_socket_pool.h" | 28 #include "net/socket/tcp_client_socket_pool.h" |
| 27 | 29 |
| 28 namespace net { | 30 namespace net { |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 // Total limit of sockets. | 34 // Total limit of sockets. |
| 33 int g_max_sockets = 256; | 35 int g_max_sockets = 256; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 63 const ProxyInfo& proxy_info, | 65 const ProxyInfo& proxy_info, |
| 64 bool force_spdy_over_ssl, | 66 bool force_spdy_over_ssl, |
| 65 bool want_spdy_over_npn, | 67 bool want_spdy_over_npn, |
| 66 const SSLConfig& ssl_config_for_origin, | 68 const SSLConfig& ssl_config_for_origin, |
| 67 const SSLConfig& ssl_config_for_proxy, | 69 const SSLConfig& ssl_config_for_proxy, |
| 68 const BoundNetLog& net_log, | 70 const BoundNetLog& net_log, |
| 69 int num_preconnect_streams, | 71 int num_preconnect_streams, |
| 70 ClientSocketHandle* socket_handle, | 72 ClientSocketHandle* socket_handle, |
| 71 CompletionCallback* callback) { | 73 CompletionCallback* callback) { |
| 72 scoped_refptr<TCPSocketParams> tcp_params; | 74 scoped_refptr<TCPSocketParams> tcp_params; |
| 75 scoped_refptr<SCTPSocketParams> sctp_params; | |
| 73 scoped_refptr<HttpProxySocketParams> http_proxy_params; | 76 scoped_refptr<HttpProxySocketParams> http_proxy_params; |
| 74 scoped_refptr<SOCKSSocketParams> socks_params; | 77 scoped_refptr<SOCKSSocketParams> socks_params; |
| 75 scoped_ptr<HostPortPair> proxy_host_port; | 78 scoped_ptr<HostPortPair> proxy_host_port; |
| 76 | 79 |
| 77 bool using_ssl = request_info.url.SchemeIs("https") || force_spdy_over_ssl; | 80 bool using_ssl = request_info.url.SchemeIs("https") || force_spdy_over_ssl; |
| 81 if (using_ssl && sctp_enabled()) { | |
| 82 printf("InitSocketPoolHelper: forcing using_ssl = false\n"); | |
|
Mike Belshe
2011/04/06 18:32:53
nix this
| |
| 83 using_ssl = false; | |
| 84 } | |
| 78 | 85 |
| 79 HostPortPair origin_host_port = | 86 HostPortPair origin_host_port = |
| 80 HostPortPair(request_info.url.HostNoBrackets(), | 87 HostPortPair(request_info.url.HostNoBrackets(), |
| 81 request_info.url.EffectiveIntPort()); | 88 request_info.url.EffectiveIntPort()); |
| 82 | 89 |
| 83 bool disable_resolver_cache = | 90 bool disable_resolver_cache = |
| 84 request_info.load_flags & LOAD_BYPASS_CACHE || | 91 request_info.load_flags & LOAD_BYPASS_CACHE || |
| 85 request_info.load_flags & LOAD_VALIDATE_CACHE || | 92 request_info.load_flags & LOAD_VALIDATE_CACHE || |
| 86 request_info.load_flags & LOAD_DISABLE_CACHE; | 93 request_info.load_flags & LOAD_DISABLE_CACHE; |
| 87 | 94 |
| 88 int load_flags = request_info.load_flags; | 95 int load_flags = request_info.load_flags; |
| 89 if (HttpStreamFactory::ignore_certificate_errors()) | 96 if (HttpStreamFactory::ignore_certificate_errors()) |
| 90 load_flags |= LOAD_IGNORE_ALL_CERT_ERRORS; | 97 load_flags |= LOAD_IGNORE_ALL_CERT_ERRORS; |
| 91 | 98 |
| 92 // Build the string used to uniquely identify connections of this type. | 99 // Build the string used to uniquely identify connections of this type. |
| 93 // Determine the host and port to connect to. | 100 // Determine the host and port to connect to. |
| 94 std::string connection_group = origin_host_port.ToString(); | 101 std::string connection_group = origin_host_port.ToString(); |
| 95 DCHECK(!connection_group.empty()); | 102 DCHECK(!connection_group.empty()); |
| 96 if (using_ssl) | 103 if (using_ssl) |
| 97 connection_group = base::StringPrintf("ssl/%s", connection_group.c_str()); | 104 connection_group = base::StringPrintf("ssl/%s", connection_group.c_str()); |
| 98 | 105 |
| 99 bool ignore_limits = (request_info.load_flags & LOAD_IGNORE_LIMITS) != 0; | 106 bool ignore_limits = (request_info.load_flags & LOAD_IGNORE_LIMITS) != 0; |
| 100 if (proxy_info.is_direct()) { | 107 if (proxy_info.is_direct()) { |
| 101 tcp_params = new TCPSocketParams(origin_host_port, | 108 if (sctp_enabled()) { |
| 102 request_info.priority, | 109 sctp_params = new SCTPSocketParams(origin_host_port, |
| 103 request_info.referrer, | 110 request_info.priority, |
| 104 disable_resolver_cache, | 111 request_info.referrer, |
| 105 ignore_limits); | 112 disable_resolver_cache, |
| 113 ignore_limits); | |
| 114 } else { | |
| 115 tcp_params = new TCPSocketParams(origin_host_port, | |
| 116 request_info.priority, | |
| 117 request_info.referrer, | |
| 118 disable_resolver_cache, | |
| 119 ignore_limits); | |
| 120 } | |
| 106 } else { | 121 } else { |
| 107 ProxyServer proxy_server = proxy_info.proxy_server(); | 122 ProxyServer proxy_server = proxy_info.proxy_server(); |
| 108 proxy_host_port.reset(new HostPortPair(proxy_server.host_port_pair())); | 123 proxy_host_port.reset(new HostPortPair(proxy_server.host_port_pair())); |
| 109 scoped_refptr<TCPSocketParams> proxy_tcp_params( | 124 scoped_refptr<TCPSocketParams> proxy_tcp_params( |
| 110 new TCPSocketParams(*proxy_host_port, | 125 new TCPSocketParams(*proxy_host_port, |
| 111 request_info.priority, | 126 request_info.priority, |
| 112 request_info.referrer, | 127 request_info.referrer, |
| 113 disable_resolver_cache, | 128 disable_resolver_cache, |
| 114 ignore_limits)); | 129 ignore_limits)); |
| 115 | 130 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 return OK; | 228 return OK; |
| 214 } | 229 } |
| 215 | 230 |
| 216 return socket_handle->Init(connection_group, socks_params, | 231 return socket_handle->Init(connection_group, socks_params, |
| 217 request_info.priority, callback, pool, | 232 request_info.priority, callback, pool, |
| 218 net_log); | 233 net_log); |
| 219 } | 234 } |
| 220 | 235 |
| 221 DCHECK(proxy_info.is_direct()); | 236 DCHECK(proxy_info.is_direct()); |
| 222 | 237 |
| 223 TCPClientSocketPool* pool = session->tcp_socket_pool(); | 238 if (sctp_enabled()) { |
| 224 if (num_preconnect_streams) { | 239 SCTPClientSocketPool* pool = session->sctp_socket_pool(); |
| 225 RequestSocketsForPool(pool, connection_group, tcp_params, | 240 if (num_preconnect_streams) { |
| 226 num_preconnect_streams, net_log); | 241 RequestSocketsForPool(pool, connection_group, sctp_params, |
| 227 return OK; | 242 num_preconnect_streams, net_log); |
| 243 return OK; | |
| 244 } | |
| 245 | |
| 246 return socket_handle->Init(connection_group, sctp_params, | |
| 247 request_info.priority, callback, | |
| 248 pool, net_log); | |
| 249 } else { | |
| 250 TCPClientSocketPool* pool = session->tcp_socket_pool(); | |
| 251 if (num_preconnect_streams) { | |
| 252 RequestSocketsForPool(pool, connection_group, tcp_params, | |
| 253 num_preconnect_streams, net_log); | |
| 254 return OK; | |
| 255 } | |
| 256 | |
| 257 return socket_handle->Init(connection_group, tcp_params, | |
| 258 request_info.priority, callback, | |
| 259 pool, net_log); | |
| 228 } | 260 } |
| 229 | |
| 230 return socket_handle->Init(connection_group, tcp_params, | |
| 231 request_info.priority, callback, | |
| 232 pool, net_log); | |
| 233 } | 261 } |
| 234 | 262 |
| 235 } // namespace | 263 } // namespace |
| 236 | 264 |
| 237 ClientSocketPoolManager::ClientSocketPoolManager( | 265 ClientSocketPoolManager::ClientSocketPoolManager( |
| 238 NetLog* net_log, | 266 NetLog* net_log, |
| 239 ClientSocketFactory* socket_factory, | 267 ClientSocketFactory* socket_factory, |
| 240 HostResolver* host_resolver, | 268 HostResolver* host_resolver, |
| 241 CertVerifier* cert_verifier, | 269 CertVerifier* cert_verifier, |
| 242 DnsRRResolver* dnsrr_resolver, | 270 DnsRRResolver* dnsrr_resolver, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 253 ssl_host_info_factory_(ssl_host_info_factory), | 281 ssl_host_info_factory_(ssl_host_info_factory), |
| 254 proxy_service_(proxy_service), | 282 proxy_service_(proxy_service), |
| 255 ssl_config_service_(ssl_config_service), | 283 ssl_config_service_(ssl_config_service), |
| 256 tcp_pool_histograms_("TCP"), | 284 tcp_pool_histograms_("TCP"), |
| 257 tcp_socket_pool_(new TCPClientSocketPool( | 285 tcp_socket_pool_(new TCPClientSocketPool( |
| 258 g_max_sockets, g_max_sockets_per_group, | 286 g_max_sockets, g_max_sockets_per_group, |
| 259 &tcp_pool_histograms_, | 287 &tcp_pool_histograms_, |
| 260 host_resolver, | 288 host_resolver, |
| 261 socket_factory_, | 289 socket_factory_, |
| 262 net_log)), | 290 net_log)), |
| 291 sctp_pool_histograms_("SCTP"), | |
| 292 sctp_socket_pool_(new SCTPClientSocketPool( | |
| 293 g_max_sockets, g_max_sockets_per_group, | |
| 294 &sctp_pool_histograms_, | |
| 295 host_resolver, | |
| 296 socket_factory_, | |
| 297 net_log)), | |
| 263 ssl_pool_histograms_("SSL2"), | 298 ssl_pool_histograms_("SSL2"), |
| 264 ssl_socket_pool_(new SSLClientSocketPool( | 299 ssl_socket_pool_(new SSLClientSocketPool( |
| 265 g_max_sockets, g_max_sockets_per_group, | 300 g_max_sockets, g_max_sockets_per_group, |
| 266 &ssl_pool_histograms_, | 301 &ssl_pool_histograms_, |
| 267 host_resolver, | 302 host_resolver, |
| 268 cert_verifier, | 303 cert_verifier, |
| 269 dnsrr_resolver, | 304 dnsrr_resolver, |
| 270 dns_cert_checker, | 305 dns_cert_checker, |
| 271 ssl_host_info_factory, | 306 ssl_host_info_factory, |
| 272 socket_factory, | 307 socket_factory, |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 int ClientSocketPoolManager::max_sockets_per_group() { | 563 int ClientSocketPoolManager::max_sockets_per_group() { |
| 529 return g_max_sockets_per_group; | 564 return g_max_sockets_per_group; |
| 530 } | 565 } |
| 531 | 566 |
| 532 // static | 567 // static |
| 533 void ClientSocketPoolManager::set_max_sockets_per_group(int socket_count) { | 568 void ClientSocketPoolManager::set_max_sockets_per_group(int socket_count) { |
| 534 DCHECK_LT(0, socket_count); | 569 DCHECK_LT(0, socket_count); |
| 535 // The following is a sanity check... but we should NEVER be near this value. | 570 // The following is a sanity check... but we should NEVER be near this value. |
| 536 DCHECK_GT(100, socket_count); | 571 DCHECK_GT(100, socket_count); |
| 537 g_max_sockets_per_group = socket_count; | 572 g_max_sockets_per_group = socket_count; |
| 573 // TODO(jtl): Remove this - it's only used for testing SCTP. | |
| 574 g_max_sockets_per_group = 1; | |
|
Mike Belshe
2011/04/06 18:32:53
can this be
if (sctp_enabled())
g_max_sock
| |
| 538 | 575 |
| 539 DCHECK_GE(g_max_sockets, g_max_sockets_per_group); | 576 DCHECK_GE(g_max_sockets, g_max_sockets_per_group); |
| 540 DCHECK_GE(g_max_sockets_per_proxy_server, g_max_sockets_per_group); | 577 DCHECK_GE(g_max_sockets_per_proxy_server, g_max_sockets_per_group); |
| 541 } | 578 } |
| 542 | 579 |
| 543 // static | 580 // static |
| 544 void ClientSocketPoolManager::set_max_sockets_per_proxy_server( | 581 void ClientSocketPoolManager::set_max_sockets_per_proxy_server( |
| 545 int socket_count) { | 582 int socket_count) { |
| 546 DCHECK_LT(0, socket_count); | 583 DCHECK_LT(0, socket_count); |
| 547 DCHECK_GT(100, socket_count); // Sanity check. | 584 DCHECK_GT(100, socket_count); // Sanity check. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 655 ssl_config_for_origin, | 692 ssl_config_for_origin, |
| 656 ssl_config_for_proxy, | 693 ssl_config_for_proxy, |
| 657 net_log, | 694 net_log, |
| 658 num_preconnect_streams, | 695 num_preconnect_streams, |
| 659 NULL, | 696 NULL, |
| 660 NULL); | 697 NULL); |
| 661 } | 698 } |
| 662 | 699 |
| 663 | 700 |
| 664 } // namespace net | 701 } // namespace net |
| OLD | NEW |