Chromium Code Reviews| 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.h" | 5 #include "net/socket/client_socket_pool_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 kDefaultMaxSocketsPerProxyServer, // NORMAL_SOCKET_POOL | 59 kDefaultMaxSocketsPerProxyServer, // NORMAL_SOCKET_POOL |
| 60 kDefaultMaxSocketsPerProxyServer // WEBSOCKET_SOCKET_POOL | 60 kDefaultMaxSocketsPerProxyServer // WEBSOCKET_SOCKET_POOL |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 static_assert(arraysize(g_max_sockets_per_proxy_server) == | 63 static_assert(arraysize(g_max_sockets_per_proxy_server) == |
| 64 HttpNetworkSession::NUM_SOCKET_POOL_TYPES, | 64 HttpNetworkSession::NUM_SOCKET_POOL_TYPES, |
| 65 "max sockets per proxy server length mismatch"); | 65 "max sockets per proxy server length mismatch"); |
| 66 | 66 |
| 67 // The meat of the implementation for the InitSocketHandleForHttpRequest, | 67 // The meat of the implementation for the InitSocketHandleForHttpRequest, |
| 68 // InitSocketHandleForRawConnect and PreconnectSocketsForHttpRequest methods. | 68 // InitSocketHandleForRawConnect and PreconnectSocketsForHttpRequest methods. |
| 69 int InitSocketPoolHelper(const GURL& request_url, | 69 int InitSocketPoolHelper(ClientSocketPoolManager::SocketGroupType group_type, |
| 70 const HostPortPair endpoint, | |
| 70 const HttpRequestHeaders& request_extra_headers, | 71 const HttpRequestHeaders& request_extra_headers, |
| 71 int request_load_flags, | 72 int request_load_flags, |
| 72 RequestPriority request_priority, | 73 RequestPriority request_priority, |
| 73 HttpNetworkSession* session, | 74 HttpNetworkSession* session, |
| 74 const ProxyInfo& proxy_info, | 75 const ProxyInfo& proxy_info, |
| 75 bool force_spdy_over_ssl, | 76 bool force_spdy_over_ssl, |
| 76 bool want_spdy_over_npn, | 77 bool want_spdy_over_npn, |
| 77 const SSLConfig& ssl_config_for_origin, | 78 const SSLConfig& ssl_config_for_origin, |
| 78 const SSLConfig& ssl_config_for_proxy, | 79 const SSLConfig& ssl_config_for_proxy, |
| 79 bool force_tunnel, | 80 bool force_tunnel, |
| 80 PrivacyMode privacy_mode, | 81 PrivacyMode privacy_mode, |
| 81 const BoundNetLog& net_log, | 82 const BoundNetLog& net_log, |
| 82 int num_preconnect_streams, | 83 int num_preconnect_streams, |
| 83 ClientSocketHandle* socket_handle, | 84 ClientSocketHandle* socket_handle, |
| 84 HttpNetworkSession::SocketPoolType socket_pool_type, | 85 HttpNetworkSession::SocketPoolType socket_pool_type, |
| 85 const OnHostResolutionCallback& resolution_callback, | 86 const OnHostResolutionCallback& resolution_callback, |
| 86 const CompletionCallback& callback) { | 87 const CompletionCallback& callback) { |
| 87 scoped_refptr<HttpProxySocketParams> http_proxy_params; | 88 scoped_refptr<HttpProxySocketParams> http_proxy_params; |
| 88 scoped_refptr<SOCKSSocketParams> socks_params; | 89 scoped_refptr<SOCKSSocketParams> socks_params; |
| 89 scoped_ptr<HostPortPair> proxy_host_port; | 90 scoped_ptr<HostPortPair> proxy_host_port; |
| 90 | 91 |
| 91 bool using_ssl = request_url.SchemeIs("https") || | 92 bool using_ssl = |
| 92 request_url.SchemeIs("wss") || force_spdy_over_ssl; | 93 group_type == ClientSocketPoolManager::SSL_GROUP || force_spdy_over_ssl; |
|
mmenke
2015/04/07 16:36:58
This seems kinda weird. We use the group type the
Ryan Hamilton
2015/04/07 19:07:30
Oh goodness, this is hideous. You're right. I've p
mmenke
2015/04/07 19:24:16
I'm fine with keeping it for now, think we should
| |
| 93 | 94 HostPortPair origin_host_port = endpoint; |
| 94 HostPortPair origin_host_port = HostPortPair::FromURL(request_url); | |
| 95 | 95 |
| 96 if (!using_ssl && session->params().testing_fixed_http_port != 0) { | 96 if (!using_ssl && session->params().testing_fixed_http_port != 0) { |
| 97 origin_host_port.set_port(session->params().testing_fixed_http_port); | 97 origin_host_port.set_port(session->params().testing_fixed_http_port); |
| 98 } else if (using_ssl && session->params().testing_fixed_https_port != 0) { | 98 } else if (using_ssl && session->params().testing_fixed_https_port != 0) { |
| 99 origin_host_port.set_port(session->params().testing_fixed_https_port); | 99 origin_host_port.set_port(session->params().testing_fixed_https_port); |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool disable_resolver_cache = | 102 bool disable_resolver_cache = |
| 103 request_load_flags & LOAD_BYPASS_CACHE || | 103 request_load_flags & LOAD_BYPASS_CACHE || |
| 104 request_load_flags & LOAD_VALIDATE_CACHE || | 104 request_load_flags & LOAD_VALIDATE_CACHE || |
| 105 request_load_flags & LOAD_DISABLE_CACHE; | 105 request_load_flags & LOAD_DISABLE_CACHE; |
| 106 | 106 |
| 107 int load_flags = request_load_flags; | 107 int load_flags = request_load_flags; |
| 108 if (session->params().ignore_certificate_errors) | 108 if (session->params().ignore_certificate_errors) |
| 109 load_flags |= LOAD_IGNORE_ALL_CERT_ERRORS; | 109 load_flags |= LOAD_IGNORE_ALL_CERT_ERRORS; |
| 110 | 110 |
| 111 // Build the string used to uniquely identify connections of this type. | 111 // Build the string used to uniquely identify connections of this type. |
| 112 // Determine the host and port to connect to. | 112 // Determine the host and port to connect to. |
| 113 std::string connection_group = origin_host_port.ToString(); | 113 std::string connection_group = origin_host_port.ToString(); |
| 114 DCHECK(!connection_group.empty()); | 114 DCHECK(!connection_group.empty()); |
| 115 if (request_url.SchemeIs("ftp")) { | 115 if (group_type == ClientSocketPoolManager::FTP_GROUP) { |
| 116 // Combining FTP with forced SPDY over SSL would be a "path to madness". | 116 // Combining FTP with forced SPDY over SSL would be a "path to madness". |
| 117 // Make sure we never do that. | 117 // Make sure we never do that. |
| 118 DCHECK(!using_ssl); | 118 DCHECK(!using_ssl); |
| 119 connection_group = "ftp/" + connection_group; | 119 connection_group = "ftp/" + connection_group; |
| 120 } | 120 } |
| 121 if (using_ssl) { | 121 if (using_ssl) { |
| 122 // All connections in a group should use the same SSLConfig settings. | 122 // All connections in a group should use the same SSLConfig settings. |
| 123 // Encode version_max in the connection group's name, unless it's the | 123 // Encode version_max in the connection group's name, unless it's the |
| 124 // default version_max. (We want the common case to use the shortest | 124 // default version_max. (We want the common case to use the shortest |
| 125 // encoding). A version_max of TLS 1.1 is encoded as "ssl(max:3.2)/" | 125 // encoding). A version_max of TLS 1.1 is encoded as "ssl(max:3.2)/" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 return OK; | 321 return OK; |
| 322 } | 322 } |
| 323 | 323 |
| 324 return socket_handle->Init(connection_group, tcp_params, | 324 return socket_handle->Init(connection_group, tcp_params, |
| 325 request_priority, callback, | 325 request_priority, callback, |
| 326 pool, net_log); | 326 pool, net_log); |
| 327 } | 327 } |
| 328 | 328 |
| 329 } // namespace | 329 } // namespace |
| 330 | 330 |
| 331 // static | |
| 332 ClientSocketPoolManager::SocketGroupType | |
| 333 ClientSocketPoolManager::GroupTypeFromScheme(const std::string& scheme) { | |
| 334 if (scheme == "ftp") | |
| 335 return FTP_GROUP; | |
| 336 | |
| 337 if (scheme == "https" || scheme == "wss") | |
| 338 return SSL_GROUP; | |
| 339 | |
| 340 return NORMAL_GROUP; | |
| 341 } | |
| 342 | |
| 331 ClientSocketPoolManager::ClientSocketPoolManager() {} | 343 ClientSocketPoolManager::ClientSocketPoolManager() {} |
| 332 ClientSocketPoolManager::~ClientSocketPoolManager() {} | 344 ClientSocketPoolManager::~ClientSocketPoolManager() {} |
| 333 | 345 |
| 334 // static | 346 // static |
| 335 int ClientSocketPoolManager::max_sockets_per_pool( | 347 int ClientSocketPoolManager::max_sockets_per_pool( |
| 336 HttpNetworkSession::SocketPoolType pool_type) { | 348 HttpNetworkSession::SocketPoolType pool_type) { |
| 337 DCHECK_LT(pool_type, HttpNetworkSession::NUM_SOCKET_POOL_TYPES); | 349 DCHECK_LT(pool_type, HttpNetworkSession::NUM_SOCKET_POOL_TYPES); |
| 338 return g_max_sockets_per_pool[pool_type]; | 350 return g_max_sockets_per_pool[pool_type]; |
| 339 } | 351 } |
| 340 | 352 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 DCHECK_LT(0, socket_count); | 399 DCHECK_LT(0, socket_count); |
| 388 DCHECK_GT(100, socket_count); // Sanity check. | 400 DCHECK_GT(100, socket_count); // Sanity check. |
| 389 DCHECK_LT(pool_type, HttpNetworkSession::NUM_SOCKET_POOL_TYPES); | 401 DCHECK_LT(pool_type, HttpNetworkSession::NUM_SOCKET_POOL_TYPES); |
| 390 // Assert this case early on. The max number of sockets per group cannot | 402 // Assert this case early on. The max number of sockets per group cannot |
| 391 // exceed the max number of sockets per proxy server. | 403 // exceed the max number of sockets per proxy server. |
| 392 DCHECK_LE(g_max_sockets_per_group[pool_type], socket_count); | 404 DCHECK_LE(g_max_sockets_per_group[pool_type], socket_count); |
| 393 g_max_sockets_per_proxy_server[pool_type] = socket_count; | 405 g_max_sockets_per_proxy_server[pool_type] = socket_count; |
| 394 } | 406 } |
| 395 | 407 |
| 396 int InitSocketHandleForHttpRequest( | 408 int InitSocketHandleForHttpRequest( |
| 397 const GURL& request_url, | 409 ClientSocketPoolManager::SocketGroupType group_type, |
| 410 const HostPortPair& endpoint, | |
| 398 const HttpRequestHeaders& request_extra_headers, | 411 const HttpRequestHeaders& request_extra_headers, |
| 399 int request_load_flags, | 412 int request_load_flags, |
| 400 RequestPriority request_priority, | 413 RequestPriority request_priority, |
| 401 HttpNetworkSession* session, | 414 HttpNetworkSession* session, |
| 402 const ProxyInfo& proxy_info, | 415 const ProxyInfo& proxy_info, |
| 403 bool force_spdy_over_ssl, | 416 bool force_spdy_over_ssl, |
| 404 bool want_spdy_over_npn, | 417 bool want_spdy_over_npn, |
| 405 const SSLConfig& ssl_config_for_origin, | 418 const SSLConfig& ssl_config_for_origin, |
| 406 const SSLConfig& ssl_config_for_proxy, | 419 const SSLConfig& ssl_config_for_proxy, |
| 407 PrivacyMode privacy_mode, | 420 PrivacyMode privacy_mode, |
| 408 const BoundNetLog& net_log, | 421 const BoundNetLog& net_log, |
| 409 ClientSocketHandle* socket_handle, | 422 ClientSocketHandle* socket_handle, |
| 410 const OnHostResolutionCallback& resolution_callback, | 423 const OnHostResolutionCallback& resolution_callback, |
| 411 const CompletionCallback& callback) { | 424 const CompletionCallback& callback) { |
| 412 DCHECK(socket_handle); | 425 DCHECK(socket_handle); |
| 413 return InitSocketPoolHelper( | 426 return InitSocketPoolHelper( |
| 414 request_url, request_extra_headers, request_load_flags, request_priority, | 427 group_type, endpoint, request_extra_headers, request_load_flags, |
| 415 session, proxy_info, force_spdy_over_ssl, want_spdy_over_npn, | 428 request_priority, session, proxy_info, force_spdy_over_ssl, |
| 416 ssl_config_for_origin, ssl_config_for_proxy, false, privacy_mode, net_log, | 429 want_spdy_over_npn, ssl_config_for_origin, ssl_config_for_proxy, false, |
| 417 0, socket_handle, HttpNetworkSession::NORMAL_SOCKET_POOL, | 430 privacy_mode, net_log, 0, socket_handle, |
| 418 resolution_callback, callback); | 431 HttpNetworkSession::NORMAL_SOCKET_POOL, resolution_callback, callback); |
| 419 } | 432 } |
| 420 | 433 |
| 421 int InitSocketHandleForWebSocketRequest( | 434 int InitSocketHandleForWebSocketRequest( |
| 422 const GURL& request_url, | 435 ClientSocketPoolManager::SocketGroupType group_type, |
| 436 const HostPortPair& endpoint, | |
| 423 const HttpRequestHeaders& request_extra_headers, | 437 const HttpRequestHeaders& request_extra_headers, |
| 424 int request_load_flags, | 438 int request_load_flags, |
| 425 RequestPriority request_priority, | 439 RequestPriority request_priority, |
| 426 HttpNetworkSession* session, | 440 HttpNetworkSession* session, |
| 427 const ProxyInfo& proxy_info, | 441 const ProxyInfo& proxy_info, |
| 428 bool force_spdy_over_ssl, | 442 bool force_spdy_over_ssl, |
| 429 bool want_spdy_over_npn, | 443 bool want_spdy_over_npn, |
| 430 const SSLConfig& ssl_config_for_origin, | 444 const SSLConfig& ssl_config_for_origin, |
| 431 const SSLConfig& ssl_config_for_proxy, | 445 const SSLConfig& ssl_config_for_proxy, |
| 432 PrivacyMode privacy_mode, | 446 PrivacyMode privacy_mode, |
| 433 const BoundNetLog& net_log, | 447 const BoundNetLog& net_log, |
| 434 ClientSocketHandle* socket_handle, | 448 ClientSocketHandle* socket_handle, |
| 435 const OnHostResolutionCallback& resolution_callback, | 449 const OnHostResolutionCallback& resolution_callback, |
| 436 const CompletionCallback& callback) { | 450 const CompletionCallback& callback) { |
| 437 DCHECK(socket_handle); | 451 DCHECK(socket_handle); |
| 438 return InitSocketPoolHelper( | 452 return InitSocketPoolHelper( |
| 439 request_url, request_extra_headers, request_load_flags, request_priority, | 453 group_type, endpoint, request_extra_headers, request_load_flags, |
| 440 session, proxy_info, force_spdy_over_ssl, want_spdy_over_npn, | 454 request_priority, session, proxy_info, force_spdy_over_ssl, |
| 441 ssl_config_for_origin, ssl_config_for_proxy, true, privacy_mode, net_log, | 455 want_spdy_over_npn, ssl_config_for_origin, ssl_config_for_proxy, true, |
| 442 0, socket_handle, HttpNetworkSession::WEBSOCKET_SOCKET_POOL, | 456 privacy_mode, net_log, 0, socket_handle, |
| 443 resolution_callback, callback); | 457 HttpNetworkSession::WEBSOCKET_SOCKET_POOL, resolution_callback, callback); |
| 444 } | 458 } |
| 445 | 459 |
| 446 int InitSocketHandleForRawConnect( | 460 int InitSocketHandleForRawConnect( |
| 447 const HostPortPair& host_port_pair, | 461 const HostPortPair& host_port_pair, |
| 448 HttpNetworkSession* session, | 462 HttpNetworkSession* session, |
| 449 const ProxyInfo& proxy_info, | 463 const ProxyInfo& proxy_info, |
| 450 const SSLConfig& ssl_config_for_origin, | 464 const SSLConfig& ssl_config_for_origin, |
| 451 const SSLConfig& ssl_config_for_proxy, | 465 const SSLConfig& ssl_config_for_proxy, |
| 452 PrivacyMode privacy_mode, | 466 PrivacyMode privacy_mode, |
| 453 const BoundNetLog& net_log, | 467 const BoundNetLog& net_log, |
| 454 ClientSocketHandle* socket_handle, | 468 ClientSocketHandle* socket_handle, |
| 455 const CompletionCallback& callback) { | 469 const CompletionCallback& callback) { |
| 456 DCHECK(socket_handle); | 470 DCHECK(socket_handle); |
| 457 // Synthesize an HttpRequestInfo. | |
| 458 GURL request_url = GURL("http://" + host_port_pair.ToString()); | |
| 459 HttpRequestHeaders request_extra_headers; | 471 HttpRequestHeaders request_extra_headers; |
| 460 int request_load_flags = 0; | 472 int request_load_flags = 0; |
| 461 RequestPriority request_priority = MEDIUM; | 473 RequestPriority request_priority = MEDIUM; |
| 462 | |
| 463 return InitSocketPoolHelper( | 474 return InitSocketPoolHelper( |
| 464 request_url, request_extra_headers, request_load_flags, request_priority, | 475 ClientSocketPoolManager::NORMAL_GROUP, host_port_pair, |
| 465 session, proxy_info, false, false, ssl_config_for_origin, | 476 request_extra_headers, request_load_flags, request_priority, session, |
| 466 ssl_config_for_proxy, true, privacy_mode, net_log, 0, socket_handle, | 477 proxy_info, false, false, ssl_config_for_origin, ssl_config_for_proxy, |
| 478 true, privacy_mode, net_log, 0, socket_handle, | |
| 467 HttpNetworkSession::NORMAL_SOCKET_POOL, OnHostResolutionCallback(), | 479 HttpNetworkSession::NORMAL_SOCKET_POOL, OnHostResolutionCallback(), |
| 468 callback); | 480 callback); |
| 469 } | 481 } |
| 470 | 482 |
| 471 int InitSocketHandleForTlsConnect( | 483 int InitSocketHandleForTlsConnect(const HostPortPair& endpoint, |
| 472 const HostPortPair& host_port_pair, | 484 HttpNetworkSession* session, |
| 473 HttpNetworkSession* session, | 485 const ProxyInfo& proxy_info, |
| 474 const ProxyInfo& proxy_info, | 486 const SSLConfig& ssl_config_for_origin, |
| 475 const SSLConfig& ssl_config_for_origin, | 487 const SSLConfig& ssl_config_for_proxy, |
| 476 const SSLConfig& ssl_config_for_proxy, | 488 PrivacyMode privacy_mode, |
| 477 PrivacyMode privacy_mode, | 489 const BoundNetLog& net_log, |
| 478 const BoundNetLog& net_log, | 490 ClientSocketHandle* socket_handle, |
| 479 ClientSocketHandle* socket_handle, | 491 const CompletionCallback& callback) { |
| 480 const CompletionCallback& callback) { | |
| 481 DCHECK(socket_handle); | 492 DCHECK(socket_handle); |
| 482 // Synthesize an HttpRequestInfo. | |
| 483 GURL request_url = GURL("https://" + host_port_pair.ToString()); | |
| 484 HttpRequestHeaders request_extra_headers; | 493 HttpRequestHeaders request_extra_headers; |
| 485 int request_load_flags = 0; | 494 int request_load_flags = 0; |
| 486 RequestPriority request_priority = MEDIUM; | 495 RequestPriority request_priority = MEDIUM; |
| 487 | |
| 488 return InitSocketPoolHelper( | 496 return InitSocketPoolHelper( |
| 489 request_url, request_extra_headers, request_load_flags, request_priority, | 497 ClientSocketPoolManager::SSL_GROUP, endpoint, request_extra_headers, |
| 490 session, proxy_info, false, false, ssl_config_for_origin, | 498 request_load_flags, request_priority, session, proxy_info, false, false, |
| 491 ssl_config_for_proxy, true, privacy_mode, net_log, 0, socket_handle, | 499 ssl_config_for_origin, ssl_config_for_proxy, true, privacy_mode, net_log, |
| 492 HttpNetworkSession::NORMAL_SOCKET_POOL, OnHostResolutionCallback(), | 500 0, socket_handle, HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 493 callback); | 501 OnHostResolutionCallback(), callback); |
| 494 } | 502 } |
| 495 | 503 |
| 496 int PreconnectSocketsForHttpRequest( | 504 int PreconnectSocketsForHttpRequest( |
| 497 const GURL& request_url, | 505 ClientSocketPoolManager::SocketGroupType group_type, |
| 506 const HostPortPair& endpoint, | |
| 498 const HttpRequestHeaders& request_extra_headers, | 507 const HttpRequestHeaders& request_extra_headers, |
| 499 int request_load_flags, | 508 int request_load_flags, |
| 500 RequestPriority request_priority, | 509 RequestPriority request_priority, |
| 501 HttpNetworkSession* session, | 510 HttpNetworkSession* session, |
| 502 const ProxyInfo& proxy_info, | 511 const ProxyInfo& proxy_info, |
| 503 bool force_spdy_over_ssl, | 512 bool force_spdy_over_ssl, |
| 504 bool want_spdy_over_npn, | 513 bool want_spdy_over_npn, |
| 505 const SSLConfig& ssl_config_for_origin, | 514 const SSLConfig& ssl_config_for_origin, |
| 506 const SSLConfig& ssl_config_for_proxy, | 515 const SSLConfig& ssl_config_for_proxy, |
| 507 PrivacyMode privacy_mode, | 516 PrivacyMode privacy_mode, |
| 508 const BoundNetLog& net_log, | 517 const BoundNetLog& net_log, |
| 509 int num_preconnect_streams) { | 518 int num_preconnect_streams) { |
| 510 return InitSocketPoolHelper( | 519 return InitSocketPoolHelper( |
| 511 request_url, request_extra_headers, request_load_flags, request_priority, | 520 group_type, endpoint, request_extra_headers, request_load_flags, |
| 512 session, proxy_info, force_spdy_over_ssl, want_spdy_over_npn, | 521 request_priority, session, proxy_info, force_spdy_over_ssl, |
| 513 ssl_config_for_origin, ssl_config_for_proxy, false, privacy_mode, net_log, | 522 want_spdy_over_npn, ssl_config_for_origin, ssl_config_for_proxy, false, |
| 514 num_preconnect_streams, NULL, HttpNetworkSession::NORMAL_SOCKET_POOL, | 523 privacy_mode, net_log, num_preconnect_streams, NULL, |
| 515 OnHostResolutionCallback(), CompletionCallback()); | 524 HttpNetworkSession::NORMAL_SOCKET_POOL, OnHostResolutionCallback(), |
| 525 CompletionCallback()); | |
| 516 } | 526 } |
| 517 | 527 |
| 518 } // namespace net | 528 } // namespace net |
| OLD | NEW |