diff options
-rw-r--r-- | net/http/http_cache.cc | 2 | ||||
-rw-r--r-- | net/http/http_network_layer.cc | 3 | ||||
-rw-r--r-- | net/http/http_network_session.cc | 62 | ||||
-rw-r--r-- | net/http/http_network_session.h | 23 | ||||
-rw-r--r-- | net/http/http_network_session_unittest.cc | 103 | ||||
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 11 | ||||
-rw-r--r-- | net/net.gyp | 1 | ||||
-rw-r--r-- | net/socket/client_socket_pool_base.cc | 14 | ||||
-rw-r--r-- | net/socket/client_socket_pool_base.h | 18 | ||||
-rw-r--r-- | net/socket/client_socket_pool_base_unittest.cc | 4 | ||||
-rw-r--r-- | net/socket/socks_client_socket_pool.cc | 6 | ||||
-rw-r--r-- | net/socket/socks_client_socket_pool.h | 3 | ||||
-rw-r--r-- | net/socket/socks_client_socket_pool_unittest.cc | 12 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_pool.cc | 6 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_pool.h | 3 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_pool_unittest.cc | 35 | ||||
-rw-r--r-- | net/spdy/spdy_network_transaction_unittest.cc | 1 | ||||
-rw-r--r-- | net/spdy/spdy_session_unittest.cc | 1 | ||||
-rw-r--r-- | net/spdy/spdy_stream_unittest.cc | 1 |
19 files changed, 127 insertions, 182 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index 5f3c0dc..d6624be 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -411,7 +411,7 @@ void HttpCache::CloseCurrentConnections() { session->tcp_socket_pool()->CloseIdleSockets(); if (session->spdy_session_pool()) session->spdy_session_pool()->CloseAllSessions(); - session->Flush(); + session->ReplaceTCPSocketPool(); } } diff --git a/net/http/http_network_layer.cc b/net/http/http_network_layer.cc index d5ae8e3..09ee5cd 100644 --- a/net/http/http_network_layer.cc +++ b/net/http/http_network_layer.cc @@ -103,9 +103,10 @@ void HttpNetworkLayer::Suspend(bool suspend) { HttpNetworkSession* HttpNetworkLayer::GetSession() { if (!session_) { DCHECK(proxy_service_); + SpdySessionPool* spdy_pool = new SpdySessionPool; session_ = new HttpNetworkSession( network_change_notifier_, host_resolver_, proxy_service_, - socket_factory_, ssl_config_service_, + socket_factory_, ssl_config_service_, spdy_pool, http_auth_handler_factory_); // These were just temps for lazy-initializing HttpNetworkSession. network_change_notifier_ = NULL; diff --git a/net/http/http_network_session.cc b/net/http/http_network_session.cc index 7899828..2d05a55 100644 --- a/net/http/http_network_session.cc +++ b/net/http/http_network_session.cc @@ -35,61 +35,31 @@ 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. HttpNetworkSession::HttpNetworkSession( NetworkChangeNotifier* network_change_notifier, HostResolver* host_resolver, ProxyService* proxy_service, ClientSocketFactory* client_socket_factory, SSLConfigService* ssl_config_service, + SpdySessionPool* spdy_session_pool, HttpAuthHandlerFactory* http_auth_handler_factory) : network_change_notifier_(network_change_notifier), + tcp_socket_pool_(new TCPClientSocketPool( + g_max_sockets, g_max_sockets_per_group, "Transport", + host_resolver, client_socket_factory, network_change_notifier_)), socket_factory_(client_socket_factory), host_resolver_(host_resolver), - tcp_socket_pool_(CreateNewTCPSocketPool()), proxy_service_(proxy_service), ssl_config_service_(ssl_config_service), - spdy_session_pool_(new SpdySessionPool), + spdy_session_pool_(spdy_session_pool), http_auth_handler_factory_(http_auth_handler_factory) { DCHECK(proxy_service); DCHECK(ssl_config_service); - - if (network_change_notifier_) - network_change_notifier_->AddObserver(this); } HttpNetworkSession::~HttpNetworkSession() { - if (network_change_notifier_) - network_change_notifier_->RemoveObserver(this); -} - -void HttpNetworkSession::OnIPAddressChanged() { - Flush(); -} - -void HttpNetworkSession::Flush() { - // TODO(willchan): Flush |host_resolver_|. - tcp_socket_pool()->CloseIdleSockets(); - tcp_socket_pool_ = CreateNewTCPSocketPool(); - for (HTTPProxySocketPoolMap::iterator it = http_proxy_socket_pool_.begin(); - it != http_proxy_socket_pool_.end(); ++it) - it->second->CloseIdleSockets(); - http_proxy_socket_pool_.clear(); - for (SOCKSSocketPoolMap::iterator it = socks_socket_pool_.begin(); - it != socks_socket_pool_.end(); ++it) - it->second->CloseIdleSockets(); - socks_socket_pool_.clear(); - spdy_session_pool_ = new SpdySessionPool; -} - -scoped_refptr<TCPClientSocketPool> -HttpNetworkSession::CreateNewTCPSocketPool() { - // TODO(vandebo) when we've completely converted to pools, the base TCP - // pool name should get changed to TCP instead of Transport. - return new TCPClientSocketPool(g_max_sockets, - g_max_sockets_per_group, - "Transport", - host_resolver_, - socket_factory_); } const scoped_refptr<TCPClientSocketPool>& @@ -105,7 +75,8 @@ HttpNetworkSession::GetSocketPoolForHTTPProxy(const HostPortPair& http_proxy) { http_proxy, new TCPClientSocketPool( g_max_sockets_per_proxy_server, g_max_sockets_per_group, - "HTTPProxy", host_resolver_, socket_factory_))); + "HTTPProxy", host_resolver_, socket_factory_, + network_change_notifier_))); return ret.first->second; } @@ -127,7 +98,9 @@ HttpNetworkSession::GetSocketPoolForSOCKSProxy( new TCPClientSocketPool(g_max_sockets_per_proxy_server, g_max_sockets_per_group, "TCPForSOCKS", host_resolver_, - socket_factory_)))); + socket_factory_, + network_change_notifier_), + network_change_notifier_))); return ret.first->second; } @@ -160,4 +133,15 @@ 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(g_max_sockets, + g_max_sockets_per_group, + "Transport", + host_resolver_, + socket_factory_, + network_change_notifier_); +} + } // namespace net diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h index b8edd71..9674b21 100644 --- a/net/http/http_network_session.h +++ b/net/http/http_network_session.h @@ -10,7 +10,6 @@ #include "base/scoped_ptr.h" #include "net/base/host_port_pair.h" #include "net/base/host_resolver.h" -#include "net/base/network_change_notifier.h" #include "net/base/ssl_client_auth_cache.h" #include "net/base/ssl_config_service.h" #include "net/http/http_alternate_protocols.h" @@ -29,9 +28,7 @@ class NetworkChangeNotifier; class SpdySessionPool; // This class holds session objects used by HttpNetworkTransaction objects. -class HttpNetworkSession - : public base::RefCounted<HttpNetworkSession>, - public NetworkChangeNotifier::Observer { +class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> { public: HttpNetworkSession( NetworkChangeNotifier* network_change_notifier, @@ -39,15 +36,9 @@ class HttpNetworkSession ProxyService* proxy_service, ClientSocketFactory* client_socket_factory, SSLConfigService* ssl_config_service, + SpdySessionPool* spdy_session_pool, HttpAuthHandlerFactory* http_auth_handler_factory); - // NetworkChangeNotifier::Observer methods: - virtual void OnIPAddressChanged(); - - // Flushes cached data in the HttpNetworkSession. Typically called on IP - // address change. - void Flush(); - HttpAuthCache* auth_cache() { return &auth_cache_; } SSLClientAuthCache* ssl_client_auth_cache() { return &ssl_client_auth_cache_; @@ -91,6 +82,10 @@ class HttpNetworkSession return http_auth_handler_factory_; } + // Replace the current socket pool with a new one. This effectively + // abandons the current pool. This is only used for debugging. + void ReplaceTCPSocketPool(); + static void set_max_sockets_per_group(int socket_count); static uint16 fixed_http_port(); @@ -110,17 +105,15 @@ class HttpNetworkSession ~HttpNetworkSession(); - scoped_refptr<TCPClientSocketPool> CreateNewTCPSocketPool(); - HttpAuthCache auth_cache_; SSLClientAuthCache ssl_client_auth_cache_; HttpAlternateProtocols alternate_protocols_; NetworkChangeNotifier* const network_change_notifier_; - ClientSocketFactory* socket_factory_; - scoped_refptr<HostResolver> host_resolver_; scoped_refptr<TCPClientSocketPool> tcp_socket_pool_; HTTPProxySocketPoolMap http_proxy_socket_pool_; SOCKSSocketPoolMap socks_socket_pool_; + ClientSocketFactory* socket_factory_; + scoped_refptr<HostResolver> host_resolver_; scoped_refptr<ProxyService> proxy_service_; scoped_refptr<SSLConfigService> ssl_config_service_; scoped_refptr<SpdySessionPool> spdy_session_pool_; diff --git a/net/http/http_network_session_unittest.cc b/net/http/http_network_session_unittest.cc deleted file mode 100644 index 6601a32..0000000 --- a/net/http/http_network_session_unittest.cc +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "net/http/http_network_session.h" - -#include "base/ref_counted.h" -#include "net/base/mock_host_resolver.h" -#include "net/base/mock_network_change_notifier.h" -#include "net/base/ssl_config_service_defaults.h" -#include "net/base/test_completion_callback.h" -#include "net/http/http_auth_handler_factory.h" -#include "net/proxy/proxy_service.h" -#include "net/socket/client_socket_handle.h" -#include "net/socket/socket_test_util.h" -#include "net/socket/tcp_client_socket_pool.h" -#include "net/spdy/spdy_session.h" -#include "net/spdy/spdy_session_pool.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace net { -namespace { - -TEST(HttpNetworkSessionTest, FlushOnNetworkChange) { - MockNetworkChangeNotifier mock_notifier; - scoped_refptr<MockCachingHostResolver> mock_resolver( - new MockCachingHostResolver); - MockClientSocketFactory mock_factory; - scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory( - HttpAuthHandlerFactory::CreateDefault()); - scoped_refptr<HttpNetworkSession> session( - new HttpNetworkSession(&mock_notifier, - mock_resolver, - ProxyService::CreateNull(), - &mock_factory, - new SSLConfigServiceDefaults, - auth_handler_factory.get())); - - scoped_refptr<TCPClientSocketPool> tcp_socket_pool( - session->tcp_socket_pool()); - - // Start up one socket to leave idle in the pool. - StaticSocketDataProvider data; - mock_factory.AddSocketDataProvider(&data); - TestCompletionCallback callback; - ClientSocketHandle handle; - TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); - int rv = handle.Init( - "1", dest, LOW, &callback, tcp_socket_pool, BoundNetLog()); - EXPECT_EQ(ERR_IO_PENDING, rv); - EXPECT_FALSE(handle.is_initialized()); - EXPECT_FALSE(handle.socket()); - EXPECT_EQ(OK, callback.WaitForResult()); - EXPECT_TRUE(handle.is_initialized()); - EXPECT_TRUE(handle.socket()); - - // Need to run all pending to release the socket back to the pool. - handle.Reset(); - MessageLoop::current()->RunAllPending(); - - // Now we should have 1 idle socket. - EXPECT_EQ(1, tcp_socket_pool->IdleSocketCount()); - - // Start up another socket to keep as active. Hold onto it until after the IP - // address change causes a session flush. - StaticSocketDataProvider data2; - mock_factory.AddSocketDataProvider(&data2); - rv = handle.Init("2", dest, LOW, &callback, tcp_socket_pool, BoundNetLog()); - EXPECT_EQ(ERR_IO_PENDING, rv); - EXPECT_FALSE(handle.is_initialized()); - EXPECT_FALSE(handle.socket()); - EXPECT_EQ(OK, callback.WaitForResult()); - EXPECT_TRUE(handle.is_initialized()); - EXPECT_TRUE(handle.socket()); - - HostPortPair host_port_pair("www.google.com", 80); - - scoped_refptr<SpdySessionPool> - spdy_session_pool(session->spdy_session_pool()); - scoped_refptr<SpdySession> spdy_session(session->spdy_session_pool()->Get( - host_port_pair, session, BoundNetLog())); - - EXPECT_TRUE(spdy_session_pool->HasSession(host_port_pair)); - - // After an IP address change, we should have 0 idle sockets in the old pool - // and we should have replaced all the pools. - mock_notifier.NotifyIPAddressChange(); - EXPECT_EQ(0, tcp_socket_pool->IdleSocketCount()); - EXPECT_NE(tcp_socket_pool, session->tcp_socket_pool()); - EXPECT_EQ(0, session->tcp_socket_pool()->IdleSocketCount()); - EXPECT_FALSE(session->spdy_session_pool()->HasSession(host_port_pair)); - EXPECT_NE(session->spdy_session_pool(), spdy_session_pool); - - // Release all the handles to old objects. Run all pending tasks afterwards - // to flush pending tasks such as releasing sockets. - tcp_socket_pool = NULL; - spdy_session_pool = NULL; - handle.Reset(); - MessageLoop::current()->RunAllPending(); -} - -} // namespace -} // namespace net diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index 9985d94..6dac810 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -82,20 +82,23 @@ class SessionDependencies { : host_resolver(new MockHostResolver), proxy_service(ProxyService::CreateNull()), ssl_config_service(new SSLConfigServiceDefaults), - http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()) {} + http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), + spdy_session_pool(new SpdySessionPool) {} // Custom proxy service dependency. explicit SessionDependencies(ProxyService* proxy_service) : host_resolver(new MockHostResolver), proxy_service(proxy_service), ssl_config_service(new SSLConfigServiceDefaults), - http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()) {} + http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), + spdy_session_pool(new SpdySessionPool) {} scoped_refptr<MockHostResolverBase> host_resolver; scoped_refptr<ProxyService> proxy_service; scoped_refptr<SSLConfigService> ssl_config_service; MockClientSocketFactory socket_factory; scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; + scoped_refptr<SpdySessionPool> spdy_session_pool; }; ProxyService* CreateFixedProxyService(const std::string& proxy) { @@ -110,6 +113,7 @@ HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { session_deps->proxy_service, &session_deps->socket_factory, session_deps->ssl_config_service, + session_deps->spdy_session_pool, session_deps->http_auth_handler_factory.get()); } @@ -235,7 +239,8 @@ class CaptureGroupNameSocketPool : public EmulatedClientSocketPool { public: CaptureGroupNameSocketPool(HttpNetworkSession* session) : EmulatedClientSocketPool(0, 0, "CaptureGroupNameTestPool", - session->host_resolver(), NULL) {} + session->host_resolver(), NULL, + NULL) {} const std::string last_group_name_received() const { return last_group_name_; } diff --git a/net/net.gyp b/net/net.gyp index b98483fd..90f99e6 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -686,7 +686,6 @@ 'http/http_cache_unittest.cc', 'http/http_chunked_decoder_unittest.cc', 'http/http_network_layer_unittest.cc', - 'http/http_network_session_unittest.cc', 'http/http_network_transaction_unittest.cc', 'http/http_request_headers_unittest.cc', 'http/http_response_headers_unittest.cc', diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc index b008c54..99011be 100644 --- a/net/socket/client_socket_pool_base.cc +++ b/net/socket/client_socket_pool_base.cc @@ -112,7 +112,8 @@ ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( int max_sockets_per_group, base::TimeDelta unused_idle_socket_timeout, base::TimeDelta used_idle_socket_timeout, - ConnectJobFactory* connect_job_factory) + ConnectJobFactory* connect_job_factory, + NetworkChangeNotifier* network_change_notifier) : idle_socket_count_(0), connecting_socket_count_(0), handed_out_socket_count_(0), @@ -123,10 +124,14 @@ ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( used_idle_socket_timeout_(used_idle_socket_timeout), may_have_stalled_group_(false), connect_job_factory_(connect_job_factory), + network_change_notifier_(network_change_notifier), backup_jobs_enabled_(false), ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { DCHECK_LE(0, max_sockets_per_group); DCHECK_LE(max_sockets_per_group, max_sockets); + + if (network_change_notifier_) + network_change_notifier_->AddObserver(this); } ClientSocketPoolBaseHelper::~ClientSocketPoolBaseHelper() { @@ -138,6 +143,9 @@ ClientSocketPoolBaseHelper::~ClientSocketPoolBaseHelper() { CloseIdleSockets(); CHECK(group_map_.empty()); DCHECK_EQ(0, connecting_socket_count_); + + if (network_change_notifier_) + network_change_notifier_->RemoveObserver(this); } // InsertRequestIntoQueue inserts the request into the queue based on @@ -602,6 +610,10 @@ void ClientSocketPoolBaseHelper::OnConnectJobComplete( } } +void ClientSocketPoolBaseHelper::OnIPAddressChanged() { + CloseIdleSockets(); +} + void ClientSocketPoolBaseHelper::RemoveConnectJob(const ConnectJob *job, Group* group) { CHECK_GT(connecting_socket_count_, 0); diff --git a/net/socket/client_socket_pool_base.h b/net/socket/client_socket_pool_base.h index 55ce7f7..89bdb78 100644 --- a/net/socket/client_socket_pool_base.h +++ b/net/socket/client_socket_pool_base.h @@ -39,6 +39,7 @@ #include "net/base/load_states.h" #include "net/base/net_errors.h" #include "net/base/net_log.h" +#include "net/base/network_change_notifier.h" #include "net/base/request_priority.h" #include "net/socket/client_socket.h" #include "net/socket/client_socket_pool.h" @@ -123,7 +124,8 @@ namespace internal { // ClientSocketPoolBase instead. class ClientSocketPoolBaseHelper : public base::RefCounted<ClientSocketPoolBaseHelper>, - public ConnectJob::Delegate { + public ConnectJob::Delegate, + public NetworkChangeNotifier::Observer { public: class Request { public: @@ -170,7 +172,8 @@ class ClientSocketPoolBaseHelper int max_sockets_per_group, base::TimeDelta unused_idle_socket_timeout, base::TimeDelta used_idle_socket_timeout, - ConnectJobFactory* connect_job_factory); + ConnectJobFactory* connect_job_factory, + NetworkChangeNotifier* network_change_notifier); // See ClientSocketPool::RequestSocket for documentation on this function. // ClientSocketPoolBaseHelper takes ownership of |request|, which must be @@ -210,6 +213,9 @@ class ClientSocketPoolBaseHelper // ConnectJob::Delegate methods: virtual void OnConnectJobComplete(int result, ConnectJob* job); + // NetworkChangeNotifier::Observer methods: + virtual void OnIPAddressChanged(); + // For testing. bool may_have_stalled_group() const { return may_have_stalled_group_; } @@ -433,6 +439,8 @@ class ClientSocketPoolBaseHelper const scoped_ptr<ConnectJobFactory> connect_job_factory_; + NetworkChangeNotifier* const network_change_notifier_; + // TODO(vandebo) Remove when backup jobs move to TCPClientSocketPool bool backup_jobs_enabled_; @@ -499,12 +507,14 @@ class ClientSocketPoolBase { const std::string& name, base::TimeDelta unused_idle_socket_timeout, base::TimeDelta used_idle_socket_timeout, - ConnectJobFactory* connect_job_factory) + ConnectJobFactory* connect_job_factory, + NetworkChangeNotifier* network_change_notifier) : name_(name), helper_(new internal::ClientSocketPoolBaseHelper( max_sockets, max_sockets_per_group, unused_idle_socket_timeout, used_idle_socket_timeout, - new ConnectJobFactoryAdaptor(connect_job_factory))) {} + new ConnectJobFactoryAdaptor(connect_job_factory), + network_change_notifier)) {} virtual ~ClientSocketPoolBase() {} diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc index 6d68097..f21ee55 100644 --- a/net/socket/client_socket_pool_base_unittest.cc +++ b/net/socket/client_socket_pool_base_unittest.cc @@ -26,7 +26,7 @@ namespace { const int kDefaultMaxSockets = 4; const int kDefaultMaxSocketsPerGroup = 2; -const RequestPriority kDefaultPriority = MEDIUM; +const net::RequestPriority kDefaultPriority = MEDIUM; typedef const void* TestSocketParams; typedef ClientSocketPoolBase<TestSocketParams> TestClientSocketPoolBase; @@ -288,7 +288,7 @@ class TestClientSocketPool : public ClientSocketPool { TestClientSocketPoolBase::ConnectJobFactory* connect_job_factory) : base_(max_sockets, max_sockets_per_group, name, unused_idle_socket_timeout, used_idle_socket_timeout, - connect_job_factory) {} + connect_job_factory, NULL) {} virtual int RequestSocket( const std::string& group_name, diff --git a/net/socket/socks_client_socket_pool.cc b/net/socket/socks_client_socket_pool.cc index febcdbf..b98f9fd 100644 --- a/net/socket/socks_client_socket_pool.cc +++ b/net/socket/socks_client_socket_pool.cc @@ -161,11 +161,13 @@ SOCKSClientSocketPool::SOCKSClientSocketPool( int max_sockets_per_group, const std::string& name, const scoped_refptr<HostResolver>& host_resolver, - const scoped_refptr<TCPClientSocketPool>& tcp_pool) + const scoped_refptr<TCPClientSocketPool>& tcp_pool, + NetworkChangeNotifier* network_change_notifier) : base_(max_sockets, max_sockets_per_group, name, base::TimeDelta::FromSeconds(kUnusedIdleSocketTimeout), base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout), - new SOCKSConnectJobFactory(tcp_pool, host_resolver)) {} + new SOCKSConnectJobFactory(tcp_pool, host_resolver), + network_change_notifier) {} SOCKSClientSocketPool::~SOCKSClientSocketPool() {} diff --git a/net/socket/socks_client_socket_pool.h b/net/socket/socks_client_socket_pool.h index 5b91ad3..a786dc1 100644 --- a/net/socket/socks_client_socket_pool.h +++ b/net/socket/socks_client_socket_pool.h @@ -109,7 +109,8 @@ class SOCKSClientSocketPool : public ClientSocketPool { int max_sockets_per_group, const std::string& name, const scoped_refptr<HostResolver>& host_resolver, - const scoped_refptr<TCPClientSocketPool>& tcp_pool); + const scoped_refptr<TCPClientSocketPool>& tcp_pool, + NetworkChangeNotifier* network_change_notifier); // ClientSocketPool methods: virtual int RequestSocket(const std::string& group_name, diff --git a/net/socket/socks_client_socket_pool_unittest.cc b/net/socket/socks_client_socket_pool_unittest.cc index 335f289..6072ad3 100644 --- a/net/socket/socks_client_socket_pool_unittest.cc +++ b/net/socket/socks_client_socket_pool_unittest.cc @@ -10,6 +10,7 @@ #include "base/compiler_specific.h" #include "base/time.h" #include "net/base/mock_host_resolver.h" +#include "net/base/mock_network_change_notifier.h" #include "net/base/net_errors.h" #include "net/base/test_completion_callback.h" #include "net/socket/client_socket_factory.h" @@ -82,9 +83,10 @@ class MockTCPClientSocketPool : public TCPClientSocketPool { MockTCPClientSocketPool(int max_sockets, int max_sockets_per_group, const std::string& name, - ClientSocketFactory* socket_factory) + ClientSocketFactory* socket_factory, + NetworkChangeNotifier* network_change_notifier) : TCPClientSocketPool(max_sockets, max_sockets_per_group, name, - NULL, NULL), + NULL, NULL, network_change_notifier), client_socket_factory_(socket_factory), release_count_(0), cancel_count_(0) {} @@ -169,13 +171,13 @@ class SOCKSClientSocketPoolTest : public ClientSocketPoolTest { HostPortPair("proxy", 80), MEDIUM, GURL(), false), tcp_socket_pool_(new MockTCPClientSocketPool( kMaxSockets, kMaxSocketsPerGroup, "MockTCP", - &tcp_client_socket_factory_)), + &tcp_client_socket_factory_, &tcp_notifier_)), ignored_socket_params_(ignored_tcp_socket_params_, true, HostPortPair("host", 80), MEDIUM, GURL()), pool_(new SOCKSClientSocketPool( kMaxSockets, kMaxSocketsPerGroup, "SOCKSUnitTest", NULL, - tcp_socket_pool_.get())) { + tcp_socket_pool_.get(), &socks_notifier_)) { } int StartRequest(const std::string& group_name, RequestPriority priority) { @@ -185,9 +187,11 @@ class SOCKSClientSocketPoolTest : public ClientSocketPoolTest { TCPSocketParams ignored_tcp_socket_params_; MockClientSocketFactory tcp_client_socket_factory_; + MockNetworkChangeNotifier tcp_notifier_; scoped_refptr<MockTCPClientSocketPool> tcp_socket_pool_; SOCKSSocketParams ignored_socket_params_; + MockNetworkChangeNotifier socks_notifier_; scoped_refptr<SOCKSClientSocketPool> pool_; }; diff --git a/net/socket/tcp_client_socket_pool.cc b/net/socket/tcp_client_socket_pool.cc index 2f8e7675..74841cf 100644 --- a/net/socket/tcp_client_socket_pool.cc +++ b/net/socket/tcp_client_socket_pool.cc @@ -177,11 +177,13 @@ TCPClientSocketPool::TCPClientSocketPool( int max_sockets_per_group, const std::string& name, HostResolver* host_resolver, - ClientSocketFactory* client_socket_factory) + ClientSocketFactory* client_socket_factory, + NetworkChangeNotifier* network_change_notifier) : base_(max_sockets, max_sockets_per_group, name, base::TimeDelta::FromSeconds(kUnusedIdleSocketTimeout), base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout), - new TCPConnectJobFactory(client_socket_factory, host_resolver)) { + new TCPConnectJobFactory(client_socket_factory, host_resolver), + network_change_notifier) { base_.enable_backup_jobs(); } diff --git a/net/socket/tcp_client_socket_pool.h b/net/socket/tcp_client_socket_pool.h index 8a62a06..30158f6 100644 --- a/net/socket/tcp_client_socket_pool.h +++ b/net/socket/tcp_client_socket_pool.h @@ -116,7 +116,8 @@ class TCPClientSocketPool : public ClientSocketPool { int max_sockets_per_group, const std::string& name, HostResolver* host_resolver, - ClientSocketFactory* client_socket_factory); + ClientSocketFactory* client_socket_factory, + NetworkChangeNotifier* network_change_notifier); // ClientSocketPool methods: diff --git a/net/socket/tcp_client_socket_pool_unittest.cc b/net/socket/tcp_client_socket_pool_unittest.cc index 9fd1c8a..e6d435a 100644 --- a/net/socket/tcp_client_socket_pool_unittest.cc +++ b/net/socket/tcp_client_socket_pool_unittest.cc @@ -8,6 +8,7 @@ #include "base/compiler_specific.h" #include "base/message_loop.h" #include "net/base/mock_host_resolver.h" +#include "net/base/mock_network_change_notifier.h" #include "net/base/net_errors.h" #include "net/base/test_completion_callback.h" #include "net/socket/client_socket.h" @@ -268,7 +269,9 @@ class TCPClientSocketPoolTest : public ClientSocketPoolTest { kMaxSocketsPerGroup, "TCPUnitTest", host_resolver_, - &client_socket_factory_)) {} + &client_socket_factory_, + ¬ifier_)) { + } int StartRequest(const std::string& group_name, RequestPriority priority) { return StartRequestUsingPool( @@ -278,6 +281,7 @@ class TCPClientSocketPoolTest : public ClientSocketPoolTest { TCPSocketParams ignored_socket_params_; scoped_refptr<MockHostResolver> host_resolver_; MockClientSocketFactory client_socket_factory_; + MockNetworkChangeNotifier notifier_; scoped_refptr<TCPClientSocketPool> pool_; }; @@ -654,6 +658,32 @@ TEST_F(TCPClientSocketPoolTest, FailingActiveRequestWithPendingRequests) { EXPECT_EQ(ERR_CONNECTION_FAILED, requests_[i]->WaitForResult()); } +TEST_F(TCPClientSocketPoolTest, ResetIdleSocketsOnIPAddressChange) { + TestCompletionCallback callback; + ClientSocketHandle handle; + TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); + int rv = handle.Init("a", dest, LOW, &callback, pool_, BoundNetLog()); + EXPECT_EQ(ERR_IO_PENDING, rv); + EXPECT_FALSE(handle.is_initialized()); + EXPECT_FALSE(handle.socket()); + + EXPECT_EQ(OK, callback.WaitForResult()); + EXPECT_TRUE(handle.is_initialized()); + EXPECT_TRUE(handle.socket()); + + handle.Reset(); + + // Need to run all pending to release the socket back to the pool. + MessageLoop::current()->RunAllPending(); + + // Now we should have 1 idle socket. + EXPECT_EQ(1, pool_->IdleSocketCount()); + + // After an IP address change, we should have 0 idle sockets. + notifier_.NotifyIPAddressChange(); + EXPECT_EQ(0, pool_->IdleSocketCount()); +} + TEST_F(TCPClientSocketPoolTest, BackupSocketConnect) { // Case 1 tests the first socket stalling, and the backup connecting. MockClientSocketFactory::ClientSocketType case1_types[] = { @@ -712,7 +742,8 @@ TEST_F(TCPClientSocketPoolTest, BackupSocketConnect) { kMaxSocketsPerGroup, "TCPUnitTest", host_resolver_, - &client_socket_factory_); + &client_socket_factory_, + NULL); } } diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc index e4279b0..add273b 100644 --- a/net/spdy/spdy_network_transaction_unittest.cc +++ b/net/spdy/spdy_network_transaction_unittest.cc @@ -86,6 +86,7 @@ HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { session_deps->proxy_service, &session_deps->socket_factory, session_deps->ssl_config_service, + session_deps->spdy_session_pool, session_deps->http_auth_handler_factory.get()); } diff --git a/net/spdy/spdy_session_unittest.cc b/net/spdy/spdy_session_unittest.cc index c5a5d0d..ab7b12c 100644 --- a/net/spdy/spdy_session_unittest.cc +++ b/net/spdy/spdy_session_unittest.cc @@ -54,6 +54,7 @@ HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { session_deps->proxy_service, &session_deps->socket_factory, session_deps->ssl_config_service, + session_deps->spdy_session_pool, NULL); } diff --git a/net/spdy/spdy_stream_unittest.cc b/net/spdy/spdy_stream_unittest.cc index 5d226c7..3da9da73 100644 --- a/net/spdy/spdy_stream_unittest.cc +++ b/net/spdy/spdy_stream_unittest.cc @@ -77,6 +77,7 @@ HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { session_deps->proxy_service, &session_deps->socket_factory, session_deps->ssl_config_service, + session_deps->spdy_session_pool, session_deps->http_auth_handler_factory.get()); } |