Chromium Code Reviews| Index: net/http/http_network_session.cc |
| diff --git a/net/http/http_network_session.cc b/net/http/http_network_session.cc |
| index 5f19ce2db74bc19328ea8f47a356cd344975a616..2d05a55da3fc4e02caaa33562eead80621c2f892 100644 |
| --- a/net/http/http_network_session.cc |
| +++ b/net/http/http_network_session.cc |
| @@ -4,22 +4,36 @@ |
| #include "net/http/http_network_session.h" |
| +#include <utility> |
| + |
| #include "base/logging.h" |
| +#include "base/stl_util-inl.h" |
| +#include "base/string_util.h" |
| #include "net/http/http_auth_handler_factory.h" |
| #include "net/http/url_security_manager.h" |
| #include "net/spdy/spdy_session_pool.h" |
| namespace net { |
| -// static |
| -int HttpNetworkSession::max_sockets_ = 256; |
| +namespace { |
| -// static |
| -int HttpNetworkSession::max_sockets_per_group_ = 6; |
| +// Total limit of sockets. |
| +int g_max_sockets = 256; |
| -// static |
| -uint16 HttpNetworkSession::g_fixed_http_port = 0; |
| -uint16 HttpNetworkSession::g_fixed_https_port = 0; |
| +// Default to allow up to 6 connections per host. Experiment and tuning may |
| +// try other values (greater than 0). Too large may cause many problems, such |
| +// as home routers blocking the connections!?!? See http://crbug.com/12066. |
| +int g_max_sockets_per_group = 6; |
| + |
| +// The max number of sockets to allow per proxy server. This applies both to |
| +// http and SOCKS proxies. See http://crbug.com/12066 for details about proxy |
| +// server connection limits. |
| +int g_max_sockets_per_proxy_server = 15; |
|
wtc
2010/05/03 19:01:53
I would use 16, since 15 is so close to a power of
|
| + |
| +uint16 g_fixed_http_port = 0; |
| +uint16 g_fixed_https_port = 0; |
| + |
| +} // namespace |
| // TODO(vandebo) when we've completely converted to pools, the base TCP |
| // pool name should get changed to TCP instead of Transport. |
| @@ -33,15 +47,8 @@ HttpNetworkSession::HttpNetworkSession( |
| HttpAuthHandlerFactory* http_auth_handler_factory) |
| : network_change_notifier_(network_change_notifier), |
| tcp_socket_pool_(new TCPClientSocketPool( |
| - max_sockets_, max_sockets_per_group_, "Transport", |
| + g_max_sockets, g_max_sockets_per_group, "Transport", |
| host_resolver, client_socket_factory, network_change_notifier_)), |
| - socks_socket_pool_(new SOCKSClientSocketPool( |
| - max_sockets_, max_sockets_per_group_, "SOCKS", host_resolver, |
| - new TCPClientSocketPool(max_sockets_, max_sockets_per_group_, |
| - "TCPForSOCKS", host_resolver, |
| - client_socket_factory, |
| - network_change_notifier_), |
| - network_change_notifier_)), |
| socket_factory_(client_socket_factory), |
| host_resolver_(host_resolver), |
| proxy_service_(proxy_service), |
| @@ -55,19 +62,82 @@ HttpNetworkSession::HttpNetworkSession( |
| HttpNetworkSession::~HttpNetworkSession() { |
| } |
| +const scoped_refptr<TCPClientSocketPool>& |
| +HttpNetworkSession::GetSocketPoolForHTTPProxy(const HostPortPair& http_proxy) { |
| + HTTPProxySocketPoolMap::const_iterator it = |
| + http_proxy_socket_pool_.find(http_proxy); |
| + if (it != http_proxy_socket_pool_.end()) |
| + return it->second; |
| + |
| + std::pair<HTTPProxySocketPoolMap::iterator, bool> ret = |
| + http_proxy_socket_pool_.insert( |
| + std::make_pair( |
| + http_proxy, |
| + new TCPClientSocketPool( |
| + g_max_sockets_per_proxy_server, g_max_sockets_per_group, |
| + "HTTPProxy", host_resolver_, socket_factory_, |
| + network_change_notifier_))); |
| + |
| + return ret.first->second; |
| +} |
| + |
| +const scoped_refptr<SOCKSClientSocketPool>& |
| +HttpNetworkSession::GetSocketPoolForSOCKSProxy( |
| + const HostPortPair& socks_proxy) { |
| + SOCKSSocketPoolMap::const_iterator it = socks_socket_pool_.find(socks_proxy); |
| + if (it != socks_socket_pool_.end()) |
| + return it->second; |
| + |
| + std::pair<SOCKSSocketPoolMap::iterator, bool> ret = |
| + socks_socket_pool_.insert( |
| + std::make_pair( |
| + socks_proxy, |
| + new SOCKSClientSocketPool( |
| + g_max_sockets_per_proxy_server, g_max_sockets_per_group, |
| + "SOCKS", host_resolver_, |
| + new TCPClientSocketPool(g_max_sockets_per_proxy_server, |
| + g_max_sockets_per_group, |
| + "TCPForSOCKS", host_resolver_, |
| + socket_factory_, |
| + network_change_notifier_), |
| + network_change_notifier_))); |
| + |
| + return ret.first->second; |
| +} |
| + |
| // static |
| void HttpNetworkSession::set_max_sockets_per_group(int socket_count) { |
| - DCHECK(0 < socket_count); |
| + DCHECK_LT(0, socket_count); |
| // The following is a sanity check... but we should NEVER be near this value. |
| - DCHECK(100 > socket_count); |
| - max_sockets_per_group_ = socket_count; |
| + DCHECK_GT(100, socket_count); |
| + g_max_sockets_per_group = socket_count; |
| +} |
| + |
| +// static |
| +uint16 HttpNetworkSession::fixed_http_port() { |
| + return g_fixed_http_port; |
| +} |
| + |
| +// static |
| +void HttpNetworkSession::set_fixed_http_port(uint16 port) { |
| + g_fixed_http_port = port; |
| +} |
| + |
| +// static |
| +uint16 HttpNetworkSession::fixed_https_port() { |
| + return g_fixed_https_port; |
| +} |
| + |
| +// static |
| +void HttpNetworkSession::set_fixed_https_port(uint16 port) { |
| + g_fixed_https_port = port; |
| } |
| // TODO(vandebo) when we've completely converted to pools, the base TCP |
| // pool name should get changed to TCP instead of Transport. |
| void HttpNetworkSession::ReplaceTCPSocketPool() { |
| - tcp_socket_pool_ = new TCPClientSocketPool(max_sockets_, |
| - max_sockets_per_group_, |
| + tcp_socket_pool_ = new TCPClientSocketPool(g_max_sockets, |
| + g_max_sockets_per_group, |
| "Transport", |
| host_resolver_, |
| socket_factory_, |