diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-08 01:48:31 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-08 01:48:31 +0000 |
commit | 9b3ef464c036a62a58a073e14b79cf9ecb790578 (patch) | |
tree | 816e67d3cf423e3f27997a3fc259d7cf855883d3 | |
parent | 65695a1fa1d175e85663eeb8ae0f1942c3d09703 (diff) | |
download | chromium_src-9b3ef464c036a62a58a073e14b79cf9ecb790578.zip chromium_src-9b3ef464c036a62a58a073e14b79cf9ecb790578.tar.gz chromium_src-9b3ef464c036a62a58a073e14b79cf9ecb790578.tar.bz2 |
Flush socket pools and SPDY session pool properly on explicit requests and network changes.
BUG=40455,40457
Review URL: http://codereview.chromium.org/1615005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43908 0039d316-1c4b-4281-b951-d872f2087c98
27 files changed, 185 insertions, 191 deletions
diff --git a/net/base/host_resolver.h b/net/base/host_resolver.h index 8f7bd09..a65bc6b 100644 --- a/net/base/host_resolver.h +++ b/net/base/host_resolver.h @@ -156,6 +156,9 @@ class HostResolver : public base::RefCountedThreadSafe<HostResolver> { // Unregisters an observer previously added by AddObserver(). virtual void RemoveObserver(Observer* observer) = 0; + // Gives the HostResolver an opportunity to flush state. + virtual void Flush() {} + // Sets the default AddressFamily to use when requests have left it // unspecified. For example, this could be used to restrict resolution // results to AF_INET by passing in ADDRESS_FAMILY_IPV4, or to diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc index 44bbe41..a891920 100644 --- a/net/base/host_resolver_impl.cc +++ b/net/base/host_resolver_impl.cc @@ -679,8 +679,6 @@ HostResolverImpl::HostResolverImpl( #if defined(OS_WIN) EnsureWinsockInit(); #endif - if (network_change_notifier_) - network_change_notifier_->AddObserver(this); } HostResolverImpl::~HostResolverImpl() { @@ -695,9 +693,6 @@ HostResolverImpl::~HostResolverImpl() { if (cur_completing_job_) cur_completing_job_->Cancel(); - if (network_change_notifier_) - network_change_notifier_->RemoveObserver(this); - // Delete the job pools. for (size_t i = 0u; i < arraysize(job_pools_); ++i) delete job_pools_[i]; @@ -841,7 +836,7 @@ void HostResolverImpl::SetDefaultAddressFamily(AddressFamily address_family) { void HostResolverImpl::ProbeIPv6Support() { DCHECK(!ipv6_probe_monitoring_); ipv6_probe_monitoring_ = true; - OnIPAddressChanged(); // Give initial setup call. + Flush(); // Give initial setup call. } void HostResolverImpl::Shutdown() { @@ -1074,7 +1069,7 @@ void HostResolverImpl::OnCancelRequest(const BoundNetLog& net_log, net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL); } -void HostResolverImpl::OnIPAddressChanged() { +void HostResolverImpl::Flush() { if (cache_.get()) cache_->clear(); if (ipv6_probe_monitoring_) { diff --git a/net/base/host_resolver_impl.h b/net/base/host_resolver_impl.h index 9652072..1a87dfe 100644 --- a/net/base/host_resolver_impl.h +++ b/net/base/host_resolver_impl.h @@ -47,8 +47,7 @@ namespace net { // // Requests are ordered in the queue based on their priority. -class HostResolverImpl : public HostResolver, - public NetworkChangeNotifier::Observer { +class HostResolverImpl : public HostResolver { public: // The index into |job_pools_| for the various job pools. Pools with a higher // index have lower priority. @@ -88,6 +87,7 @@ class HostResolverImpl : public HostResolver, virtual void CancelRequest(RequestHandle req); virtual void AddObserver(HostResolver::Observer* observer); virtual void RemoveObserver(HostResolver::Observer* observer); + virtual void Flush(); // Set address family, and disable IPv6 probe support. virtual void SetDefaultAddressFamily(AddressFamily address_family); @@ -180,9 +180,6 @@ class HostResolverImpl : public HostResolver, int request_id, const RequestInfo& info); - // NetworkChangeNotifier::Observer methods: - virtual void OnIPAddressChanged(); - // Notify IPv6ProbeJob not to call back, and discard reference to the job. void DiscardIPv6ProbeJob(); diff --git a/net/base/host_resolver_impl_unittest.cc b/net/base/host_resolver_impl_unittest.cc index bd19f0b..e439491 100644 --- a/net/base/host_resolver_impl_unittest.cc +++ b/net/base/host_resolver_impl_unittest.cc @@ -1039,38 +1039,6 @@ TEST_F(HostResolverImplTest, CancellationObserver) { CapturingObserver::StartOrCancelEntry(1, info)); } -// Test that IP address changes flush the cache. -TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { - MockNetworkChangeNotifier mock_network_change_notifier; - scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(NULL, CreateDefaultCache(), - &mock_network_change_notifier, - kMaxJobs)); - - AddressList addrlist; - - // Resolve "host1". - HostResolver::RequestInfo info1("host1", 70); - TestCompletionCallback callback; - int rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, NULL); - EXPECT_EQ(ERR_IO_PENDING, rv); - EXPECT_EQ(OK, callback.WaitForResult()); - - // Resolve "host1" again -- this time it will be served from cache, but it - // should still notify of completion. - rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, NULL); - ASSERT_EQ(OK, rv); // Should complete synchronously. - - // Flush cache by triggering an IP address change. - mock_network_change_notifier.NotifyIPAddressChange(); - - // Resolve "host1" again -- this time it won't be served from cache, so it - // will complete asynchronously. - rv = host_resolver->Resolve(info1, &addrlist, &callback, NULL, NULL); - ASSERT_EQ(ERR_IO_PENDING, rv); // Should complete asynchronously. - EXPECT_EQ(OK, callback.WaitForResult()); -} - // Tests that when the maximum threads is set to 1, requests are dequeued // in order of priority. TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { diff --git a/net/base/mapped_host_resolver.h b/net/base/mapped_host_resolver.h index 7339f06..890f3072 100644 --- a/net/base/mapped_host_resolver.h +++ b/net/base/mapped_host_resolver.h @@ -32,6 +32,7 @@ class MappedHostResolver : public HostResolver { virtual void CancelRequest(RequestHandle req); virtual void AddObserver(Observer* observer); virtual void RemoveObserver(Observer* observer); + virtual void Flush() { impl_->Flush(); } virtual HostResolverImpl* GetAsHostResolverImpl(); // Adds a rule to this mapper. The format of the rule can be one of: diff --git a/net/base/mock_host_resolver.cc b/net/base/mock_host_resolver.cc index 7f2512f..c079fc1 100644 --- a/net/base/mock_host_resolver.cc +++ b/net/base/mock_host_resolver.cc @@ -66,6 +66,10 @@ void MockHostResolverBase::RemoveObserver(Observer* observer) { impl_->RemoveObserver(observer); } +void MockHostResolverBase::Flush() { + impl_->Flush(); +} + void MockHostResolverBase::Reset(HostResolverProc* interceptor) { synchronous_mode_ = false; diff --git a/net/base/mock_host_resolver.h b/net/base/mock_host_resolver.h index d08dc42..661e2dd 100644 --- a/net/base/mock_host_resolver.h +++ b/net/base/mock_host_resolver.h @@ -47,9 +47,12 @@ class MockHostResolverBase : public HostResolver { virtual void CancelRequest(RequestHandle req); virtual void AddObserver(Observer* observer); virtual void RemoveObserver(Observer* observer); + virtual void Flush(); RuleBasedHostResolverProc* rules() { return rules_; } + const HostCache* cache() const { return impl_->cache(); } + // Controls whether resolutions complete synchronously or asynchronously. void set_synchronous_mode(bool is_synchronous) { synchronous_mode_ = is_synchronous; diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index 8b0811f..8a44565 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -377,12 +377,8 @@ void HttpCache::CloseCurrentConnections() { net::HttpNetworkLayer* network = static_cast<net::HttpNetworkLayer*>(network_layer_.get()); HttpNetworkSession* session = network->GetSession(); - if (session) { - session->tcp_socket_pool()->CloseIdleSockets(); - if (session->spdy_session_pool()) - session->spdy_session_pool()->CloseAllSessions(); - session->ReplaceTCPSocketPool(); - } + if (session) + session->Flush(); } //----------------------------------------------------------------------------- diff --git a/net/http/http_network_layer.cc b/net/http/http_network_layer.cc index 068b276..8a22514 100644 --- a/net/http/http_network_layer.cc +++ b/net/http/http_network_layer.cc @@ -12,7 +12,6 @@ #include "net/spdy/spdy_framer.h" #include "net/spdy/spdy_network_transaction.h" #include "net/spdy/spdy_session.h" -#include "net/spdy/spdy_session_pool.h" namespace net { @@ -57,7 +56,6 @@ HttpNetworkLayer::HttpNetworkLayer( proxy_service_(proxy_service), ssl_config_service_(ssl_config_service), session_(NULL), - spdy_session_pool_(NULL), http_auth_handler_factory_(http_auth_handler_factory), suspended_(false) { DCHECK(proxy_service_); @@ -69,7 +67,6 @@ HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) network_change_notifier_(NULL), ssl_config_service_(NULL), session_(session), - spdy_session_pool_(session->spdy_session_pool()), http_auth_handler_factory_(NULL), suspended_(false) { DCHECK(session_.get()); @@ -97,16 +94,15 @@ void HttpNetworkLayer::Suspend(bool suspend) { suspended_ = suspend; if (suspend && session_) - session_->tcp_socket_pool()->CloseIdleSockets(); + session_->Flush(); } 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_, spdy_pool, + socket_factory_, ssl_config_service_, http_auth_handler_factory_); // These were just temps for lazy-initializing HttpNetworkSession. network_change_notifier_ = NULL; diff --git a/net/http/http_network_layer.h b/net/http/http_network_layer.h index 2d4130d..63df00b 100644 --- a/net/http/http_network_layer.h +++ b/net/http/http_network_layer.h @@ -20,7 +20,6 @@ class HttpNetworkSession; class NetworkChangeNotifier; class ProxyInfo; class ProxyService; -class SpdySessionPool; class SSLConfigService; class HttpNetworkLayer : public HttpTransactionFactory { @@ -82,7 +81,6 @@ class HttpNetworkLayer : public HttpTransactionFactory { scoped_refptr<SSLConfigService> ssl_config_service_; scoped_refptr<HttpNetworkSession> session_; - scoped_refptr<SpdySessionPool> spdy_session_pool_; HttpAuthHandlerFactory* http_auth_handler_factory_; diff --git a/net/http/http_network_session.cc b/net/http/http_network_session.cc index 3c44b81..90e865f 100644 --- a/net/http/http_network_session.cc +++ b/net/http/http_network_session.cc @@ -29,30 +29,26 @@ HttpNetworkSession::HttpNetworkSession( 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( - max_sockets_, 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), + tcp_socket_pool_(CreateNewTCPSocketPool()), + socks_socket_pool_(CreateNewSOCKSSocketPool()), proxy_service_(proxy_service), ssl_config_service_(ssl_config_service), - spdy_session_pool_(spdy_session_pool), + spdy_session_pool_(new SpdySessionPool()), 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); } URLSecurityManager* HttpNetworkSession::GetURLSecurityManager() { @@ -67,21 +63,44 @@ URLSecurityManager* HttpNetworkSession::GetURLSecurityManager() { // 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); + DCHECK_GT(100, socket_count); max_sockets_per_group_ = socket_count; } -// 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_, - "Transport", - host_resolver_, - socket_factory_, - network_change_notifier_); +void HttpNetworkSession::Flush() { + host_resolver()->Flush(); + tcp_socket_pool()->CloseIdleSockets(); + tcp_socket_pool_ = CreateNewTCPSocketPool(); + socks_socket_pool()->CloseIdleSockets(); + socks_socket_pool_ = CreateNewSOCKSSocketPool(); + spdy_session_pool_->CloseAllSessions(); + spdy_session_pool_ = new SpdySessionPool; +} + +void HttpNetworkSession::OnIPAddressChanged() { + Flush(); +} + +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(max_sockets_, + max_sockets_per_group_, + "Transport", + host_resolver_, + socket_factory_); +} + +scoped_refptr<SOCKSClientSocketPool> +HttpNetworkSession::CreateNewSOCKSSocketPool() { + return new SOCKSClientSocketPool( + max_sockets_, max_sockets_per_group_, "SOCKS", host_resolver_, + new TCPClientSocketPool(max_sockets_, max_sockets_per_group_, + "TCPForSOCKS", host_resolver_, + socket_factory_)); } } // namespace net diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h index fcfaac4..540c59b 100644 --- a/net/http/http_network_session.h +++ b/net/http/http_network_session.h @@ -8,6 +8,7 @@ #include "base/ref_counted.h" #include "base/scoped_ptr.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" @@ -25,7 +26,9 @@ class NetworkChangeNotifier; class URLSecurityManager; // This class holds session objects used by HttpNetworkTransaction objects. -class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> { +class HttpNetworkSession + : public base::RefCounted<HttpNetworkSession>, + public NetworkChangeNotifier::Observer { public: HttpNetworkSession( NetworkChangeNotifier* network_change_notifier, @@ -33,7 +36,6 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> { ProxyService* proxy_service, ClientSocketFactory* client_socket_factory, SSLConfigService* ssl_config_service, - SpdySessionPool* spdy_session_pool, HttpAuthHandlerFactory* http_auth_handler_factory); HttpAuthCache* auth_cache() { return &auth_cache_; } @@ -70,9 +72,11 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> { // Returns a pointer to the URL security manager. URLSecurityManager* GetURLSecurityManager(); - // Replace the current socket pool with a new one. This effectively - // abandons the current pool. This is only used for debugging. - void ReplaceTCPSocketPool(); + // Flushes cached data in the HttpNetworkSession. + void Flush(); + + // NetworkChangeNotifier::Observer methods: + virtual void OnIPAddressChanged(); static void set_max_sockets_per_group(int socket_count); @@ -88,6 +92,9 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> { ~HttpNetworkSession(); + scoped_refptr<TCPClientSocketPool> CreateNewTCPSocketPool(); + scoped_refptr<SOCKSClientSocketPool> CreateNewSOCKSSocketPool(); + // Total limit of sockets. Not a constant to allow experiments. static int max_sockets_; @@ -103,10 +110,10 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> { SSLClientAuthCache ssl_client_auth_cache_; HttpAlternateProtocols alternate_protocols_; NetworkChangeNotifier* const network_change_notifier_; - scoped_refptr<TCPClientSocketPool> tcp_socket_pool_; - scoped_refptr<SOCKSClientSocketPool> socks_socket_pool_; ClientSocketFactory* socket_factory_; scoped_refptr<HostResolver> host_resolver_; + scoped_refptr<TCPClientSocketPool> tcp_socket_pool_; + scoped_refptr<SOCKSClientSocketPool> socks_socket_pool_; 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 new file mode 100644 index 0000000..329f394c --- /dev/null +++ b/net/http/http_network_session_unittest.cc @@ -0,0 +1,82 @@ +// 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()); + + StaticSocketDataProvider data; + mock_factory.AddSocketDataProvider(&data); + + TestCompletionCallback callback; + ClientSocketHandle handle; + TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); + int rv = handle.Init("a", dest, LOW, &callback, tcp_socket_pool, NULL); + 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, tcp_socket_pool->IdleSocketCount()); + + HostPortPair host_port_pair("www.google.com", 80); + + scoped_refptr<SpdySession> spdy_session(session->spdy_session_pool()->Get( + host_port_pair, session)); + + EXPECT_TRUE(session->spdy_session_pool()->HasSession(host_port_pair)); + + EXPECT_EQ(1u, mock_resolver->cache()->size()); + + // After an IP address change, we should have 0 idle sockets. + mock_notifier.NotifyIPAddressChange(); + EXPECT_EQ(0, tcp_socket_pool->IdleSocketCount()); + EXPECT_FALSE(session->spdy_session_pool()->HasSession(host_port_pair)); + EXPECT_EQ(0u, mock_resolver->cache()->size()); +} + +} // namespace +} // namespace net diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index 02b784e8..aa18df5 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -43,23 +43,20 @@ class SessionDependencies { : host_resolver(new MockHostResolver), proxy_service(ProxyService::CreateNull()), ssl_config_service(new SSLConfigServiceDefaults), - http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), - spdy_session_pool(new SpdySessionPool) {} + http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()) {} // 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()), - spdy_session_pool(new SpdySessionPool) {} + http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()) {} 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) { @@ -75,7 +72,6 @@ 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()); } @@ -189,8 +185,7 @@ class CaptureGroupNameSocketPool : public EmulatedClientSocketPool { CaptureGroupNameSocketPool(HttpNetworkSession* session, SocketSourceType* socket_source) : EmulatedClientSocketPool(0, 0, "CaptureGroupNameTestPool", - session->host_resolver(), socket_source, - NULL) {} + session->host_resolver(), socket_source) {} const std::string last_group_name_received() const { return last_group_name_; } diff --git a/net/net.gyp b/net/net.gyp index d49fc5e..7a34e40 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -676,6 +676,7 @@ '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 4be76ff..9da9a19 100644 --- a/net/socket/client_socket_pool_base.cc +++ b/net/socket/client_socket_pool_base.cc @@ -110,8 +110,7 @@ ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( int max_sockets_per_group, base::TimeDelta unused_idle_socket_timeout, base::TimeDelta used_idle_socket_timeout, - ConnectJobFactory* connect_job_factory, - NetworkChangeNotifier* network_change_notifier) + ConnectJobFactory* connect_job_factory) : idle_socket_count_(0), connecting_socket_count_(0), handed_out_socket_count_(0), @@ -121,14 +120,10 @@ 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() { @@ -140,9 +135,6 @@ 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 @@ -591,10 +583,6 @@ 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 782af6c..1a2a791 100644 --- a/net/socket/client_socket_pool_base.h +++ b/net/socket/client_socket_pool_base.h @@ -39,7 +39,6 @@ #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" @@ -122,8 +121,7 @@ namespace internal { // ClientSocketPoolBase instead. class ClientSocketPoolBaseHelper : public base::RefCounted<ClientSocketPoolBaseHelper>, - public ConnectJob::Delegate, - public NetworkChangeNotifier::Observer { + public ConnectJob::Delegate { public: class Request { public: @@ -170,8 +168,7 @@ class ClientSocketPoolBaseHelper int max_sockets_per_group, base::TimeDelta unused_idle_socket_timeout, base::TimeDelta used_idle_socket_timeout, - ConnectJobFactory* connect_job_factory, - NetworkChangeNotifier* network_change_notifier); + ConnectJobFactory* connect_job_factory); // See ClientSocketPool::RequestSocket for documentation on this function. // Note that |request| must be heap allocated. If ERR_IO_PENDING is returned, @@ -211,9 +208,6 @@ 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_; } @@ -445,8 +439,6 @@ 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_; @@ -513,14 +505,12 @@ class ClientSocketPoolBase { const std::string& name, base::TimeDelta unused_idle_socket_timeout, base::TimeDelta used_idle_socket_timeout, - ConnectJobFactory* connect_job_factory, - NetworkChangeNotifier* network_change_notifier) + ConnectJobFactory* connect_job_factory) : 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), - network_change_notifier)) {} + new ConnectJobFactoryAdaptor(connect_job_factory))) {} virtual ~ClientSocketPoolBase() {} diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc index d2676e8..750a327 100644 --- a/net/socket/client_socket_pool_base_unittest.cc +++ b/net/socket/client_socket_pool_base_unittest.cc @@ -283,7 +283,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, NULL) {} + connect_job_factory) {} 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 246cc20..36d12ba 100644 --- a/net/socket/socks_client_socket_pool.cc +++ b/net/socket/socks_client_socket_pool.cc @@ -161,13 +161,11 @@ SOCKSClientSocketPool::SOCKSClientSocketPool( int max_sockets_per_group, const std::string& name, const scoped_refptr<HostResolver>& host_resolver, - const scoped_refptr<TCPClientSocketPool>& tcp_pool, - NetworkChangeNotifier* network_change_notifier) + const scoped_refptr<TCPClientSocketPool>& tcp_pool) : base_(max_sockets, max_sockets_per_group, name, base::TimeDelta::FromSeconds(kUnusedIdleSocketTimeout), base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout), - new SOCKSConnectJobFactory(tcp_pool, host_resolver), - network_change_notifier) {} + new SOCKSConnectJobFactory(tcp_pool, host_resolver)) {} SOCKSClientSocketPool::~SOCKSClientSocketPool() {} diff --git a/net/socket/socks_client_socket_pool.h b/net/socket/socks_client_socket_pool.h index 2c30600..f74074a 100644 --- a/net/socket/socks_client_socket_pool.h +++ b/net/socket/socks_client_socket_pool.h @@ -108,8 +108,7 @@ 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, - NetworkChangeNotifier* network_change_notifier); + const scoped_refptr<TCPClientSocketPool>& tcp_pool); // 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 4291f3c..cef7ff6 100644 --- a/net/socket/socks_client_socket_pool_unittest.cc +++ b/net/socket/socks_client_socket_pool_unittest.cc @@ -10,7 +10,6 @@ #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" @@ -84,10 +83,9 @@ class MockTCPClientSocketPool : public TCPClientSocketPool { MockTCPClientSocketPool(int max_sockets, int max_sockets_per_group, const std::string& name, - ClientSocketFactory* socket_factory, - NetworkChangeNotifier* network_change_notifier) + ClientSocketFactory* socket_factory) : TCPClientSocketPool(max_sockets, max_sockets_per_group, name, - NULL, NULL, network_change_notifier), + NULL, NULL), client_socket_factory_(socket_factory), release_count_(0), cancel_count_(0) {} @@ -171,11 +169,12 @@ class SOCKSClientSocketPoolTest : public ClientSocketPoolTest { : ignored_tcp_socket_params_("proxy", 80, MEDIUM, GURL(), false), tcp_socket_pool_(new MockTCPClientSocketPool( kMaxSockets, kMaxSocketsPerGroup, "MockTCP", - &tcp_client_socket_factory_, &tcp_notifier_)), + &tcp_client_socket_factory_)), ignored_socket_params_(ignored_tcp_socket_params_, true, "host", 80, MEDIUM, GURL()), - pool_(new SOCKSClientSocketPool(kMaxSockets, kMaxSocketsPerGroup, - "SOCKSUnitTest", NULL, tcp_socket_pool_.get(), &socks_notifier_)) { + pool_(new SOCKSClientSocketPool( + kMaxSockets, kMaxSocketsPerGroup, + "SOCKSUnitTest", NULL, tcp_socket_pool_.get())) { } int StartRequest(const std::string& group_name, RequestPriority priority) { @@ -185,11 +184,9 @@ 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 a833e01..db8a88a 100644 --- a/net/socket/tcp_client_socket_pool.cc +++ b/net/socket/tcp_client_socket_pool.cc @@ -176,13 +176,11 @@ TCPClientSocketPool::TCPClientSocketPool( int max_sockets_per_group, const std::string& name, HostResolver* host_resolver, - ClientSocketFactory* client_socket_factory, - NetworkChangeNotifier* network_change_notifier) + ClientSocketFactory* client_socket_factory) : base_(max_sockets, max_sockets_per_group, name, base::TimeDelta::FromSeconds(kUnusedIdleSocketTimeout), base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout), - new TCPConnectJobFactory(client_socket_factory, host_resolver), - network_change_notifier) { + new TCPConnectJobFactory(client_socket_factory, host_resolver)) { base_.enable_backup_jobs(); } diff --git a/net/socket/tcp_client_socket_pool.h b/net/socket/tcp_client_socket_pool.h index 76950c3..463e765 100644 --- a/net/socket/tcp_client_socket_pool.h +++ b/net/socket/tcp_client_socket_pool.h @@ -103,8 +103,7 @@ class TCPClientSocketPool : public ClientSocketPool { int max_sockets_per_group, const std::string& name, HostResolver* host_resolver, - ClientSocketFactory* client_socket_factory, - NetworkChangeNotifier* network_change_notifier); + ClientSocketFactory* client_socket_factory); // ClientSocketPool methods: diff --git a/net/socket/tcp_client_socket_pool_unittest.cc b/net/socket/tcp_client_socket_pool_unittest.cc index e7c8a9f..a41fb88 100644 --- a/net/socket/tcp_client_socket_pool_unittest.cc +++ b/net/socket/tcp_client_socket_pool_unittest.cc @@ -8,7 +8,6 @@ #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" @@ -247,8 +246,7 @@ class TCPClientSocketPoolTest : public ClientSocketPoolTest { kMaxSocketsPerGroup, "TCPUnitTest", host_resolver_, - &client_socket_factory_, - ¬ifier_)) { + &client_socket_factory_)) { } int StartRequest(const std::string& group_name, RequestPriority priority) { @@ -259,7 +257,6 @@ class TCPClientSocketPoolTest : public ClientSocketPoolTest { TCPSocketParams ignored_socket_params_; scoped_refptr<MockHostResolver> host_resolver_; MockClientSocketFactory client_socket_factory_; - MockNetworkChangeNotifier notifier_; scoped_refptr<TCPClientSocketPool> pool_; }; @@ -628,32 +625,6 @@ 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_, NULL); - 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[] = { diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc index 377c7a5..fb06906 100644 --- a/net/spdy/spdy_network_transaction_unittest.cc +++ b/net/spdy/spdy_network_transaction_unittest.cc @@ -54,8 +54,7 @@ class SessionDependencies { : host_resolver(new MockHostResolver), proxy_service(ProxyService::CreateNull()), ssl_config_service(new SSLConfigServiceDefaults), - http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), - spdy_session_pool(new SpdySessionPool) { + http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()) { // Note: The CancelledTransaction test does cleanup by running all tasks // in the message loop (RunAllPending). Unfortunately, that doesn't clean // up tasks on the host resolver thread; and TCPConnectJob is currently @@ -70,15 +69,13 @@ class SessionDependencies { : host_resolver(new MockHostResolver), proxy_service(proxy_service), ssl_config_service(new SSLConfigServiceDefaults), - http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), - spdy_session_pool(new SpdySessionPool) {} + http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()) {} 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; }; HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { @@ -87,7 +84,6 @@ 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 49e4491..ece870c 100644 --- a/net/spdy/spdy_session_unittest.cc +++ b/net/spdy/spdy_session_unittest.cc @@ -28,15 +28,13 @@ class SessionDependencies { SessionDependencies() : host_resolver(new MockHostResolver), proxy_service(ProxyService::CreateNull()), - ssl_config_service(new SSLConfigServiceDefaults), - spdy_session_pool(new SpdySessionPool) { + ssl_config_service(new SSLConfigServiceDefaults) { } scoped_refptr<MockHostResolverBase> host_resolver; scoped_refptr<ProxyService> proxy_service; scoped_refptr<SSLConfigService> ssl_config_service; MockClientSocketFactory socket_factory; - scoped_refptr<SpdySessionPool> spdy_session_pool; }; HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { @@ -45,7 +43,6 @@ 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 b8c4b7f..a2cfa72 100644 --- a/net/spdy/spdy_stream_unittest.cc +++ b/net/spdy/spdy_stream_unittest.cc @@ -52,23 +52,20 @@ class SessionDependencies { : host_resolver(new MockHostResolver), proxy_service(CreateNullProxyService()), ssl_config_service(new SSLConfigServiceDefaults), - http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), - spdy_session_pool(new SpdySessionPool) {} + http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()) {} // 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()), - spdy_session_pool(new SpdySessionPool) {} + http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()) {} 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; }; HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { @@ -77,7 +74,6 @@ 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()); } |