summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-19 22:45:53 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-19 22:45:53 +0000
commit61a86c4d5644817d291e7f22ffd0b0b5cef56295 (patch)
treedfd15e590bbbf44af479f702875d24aa19d1f491
parent74d7e1d0cb8040ba0bfe15619ccb240e5c7d5c19 (diff)
downloadchromium_src-61a86c4d5644817d291e7f22ffd0b0b5cef56295.zip
chromium_src-61a86c4d5644817d291e7f22ffd0b0b5cef56295.tar.gz
chromium_src-61a86c4d5644817d291e7f22ffd0b0b5cef56295.tar.bz2
Fix crash on IP address change.
Revert r43908: "Flush socket pools and SPDY session pool properly on explicit requests and network changes." This change was reverted on the 375 branch, but not on trunk. BUG=41190 Review URL: http://codereview.chromium.org/1604045 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44973 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/base/host_resolver.h3
-rw-r--r--net/base/host_resolver_impl.cc9
-rw-r--r--net/base/host_resolver_impl.h7
-rw-r--r--net/base/host_resolver_impl_unittest.cc32
-rw-r--r--net/base/mapped_host_resolver.h1
-rw-r--r--net/base/mock_host_resolver.cc4
-rw-r--r--net/base/mock_host_resolver.h3
-rw-r--r--net/http/http_cache.cc8
-rw-r--r--net/http/http_network_layer.cc8
-rw-r--r--net/http/http_network_layer.h2
-rw-r--r--net/http/http_network_session.cc65
-rw-r--r--net/http/http_network_session.h21
-rw-r--r--net/http/http_network_session_unittest.cc82
-rw-r--r--net/http/http_network_transaction_unittest.cc11
-rw-r--r--net/net.gyp1
-rw-r--r--net/socket/client_socket_pool_base.cc14
-rw-r--r--net/socket/client_socket_pool_base.h18
-rw-r--r--net/socket/client_socket_pool_base_unittest.cc2
-rw-r--r--net/socket/socks_client_socket_pool.cc6
-rw-r--r--net/socket/socks_client_socket_pool.h3
-rw-r--r--net/socket/socks_client_socket_pool_unittest.cc15
-rw-r--r--net/socket/tcp_client_socket_pool.cc6
-rw-r--r--net/socket/tcp_client_socket_pool.h3
-rw-r--r--net/socket/tcp_client_socket_pool_unittest.cc31
-rw-r--r--net/spdy/spdy_network_transaction_unittest.cc8
-rw-r--r--net/spdy/spdy_session_unittest.cc5
-rw-r--r--net/spdy/spdy_stream_unittest.cc8
27 files changed, 191 insertions, 185 deletions
diff --git a/net/base/host_resolver.h b/net/base/host_resolver.h
index 9fd8dbe4..e4bf847 100644
--- a/net/base/host_resolver.h
+++ b/net/base/host_resolver.h
@@ -167,9 +167,6 @@ 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 1f43c60..df5bc79 100644
--- a/net/base/host_resolver_impl.cc
+++ b/net/base/host_resolver_impl.cc
@@ -683,6 +683,8 @@ HostResolverImpl::HostResolverImpl(
#if defined(OS_WIN)
EnsureWinsockInit();
#endif
+ if (network_change_notifier_)
+ network_change_notifier_->AddObserver(this);
}
HostResolverImpl::~HostResolverImpl() {
@@ -697,6 +699,9 @@ 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 +846,7 @@ void HostResolverImpl::SetDefaultAddressFamily(AddressFamily address_family) {
void HostResolverImpl::ProbeIPv6Support() {
DCHECK(!ipv6_probe_monitoring_);
ipv6_probe_monitoring_ = true;
- Flush(); // Give initial setup call.
+ OnIPAddressChanged(); // Give initial setup call.
}
void HostResolverImpl::Shutdown() {
@@ -1074,7 +1079,7 @@ void HostResolverImpl::OnCancelRequest(const BoundNetLog& net_log,
net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL);
}
-void HostResolverImpl::Flush() {
+void HostResolverImpl::OnIPAddressChanged() {
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 4814921..1a182b3 100644
--- a/net/base/host_resolver_impl.h
+++ b/net/base/host_resolver_impl.h
@@ -47,7 +47,8 @@ namespace net {
//
// Requests are ordered in the queue based on their priority.
-class HostResolverImpl : public HostResolver {
+class HostResolverImpl : public HostResolver,
+ public NetworkChangeNotifier::Observer {
public:
// The index into |job_pools_| for the various job pools. Pools with a higher
// index have lower priority.
@@ -87,7 +88,6 @@ 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,6 +180,9 @@ 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 e9a721c..a17fb6a 100644
--- a/net/base/host_resolver_impl_unittest.cc
+++ b/net/base/host_resolver_impl_unittest.cc
@@ -1043,6 +1043,38 @@ 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 890f3072..7339f06 100644
--- a/net/base/mapped_host_resolver.h
+++ b/net/base/mapped_host_resolver.h
@@ -32,7 +32,6 @@ 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 9e57fd1..d99b24e 100644
--- a/net/base/mock_host_resolver.cc
+++ b/net/base/mock_host_resolver.cc
@@ -66,10 +66,6 @@ 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 ff9f9fc..5a1df7f 100644
--- a/net/base/mock_host_resolver.h
+++ b/net/base/mock_host_resolver.h
@@ -47,12 +47,9 @@ 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 f1ddaf9..3a816f7 100644
--- a/net/http/http_cache.cc
+++ b/net/http/http_cache.cc
@@ -371,8 +371,12 @@ void HttpCache::CloseCurrentConnections() {
net::HttpNetworkLayer* network =
static_cast<net::HttpNetworkLayer*>(network_layer_.get());
HttpNetworkSession* session = network->GetSession();
- if (session)
- session->Flush();
+ if (session) {
+ session->tcp_socket_pool()->CloseIdleSockets();
+ if (session->spdy_session_pool())
+ session->spdy_session_pool()->CloseAllSessions();
+ session->ReplaceTCPSocketPool();
+ }
}
//-----------------------------------------------------------------------------
diff --git a/net/http/http_network_layer.cc b/net/http/http_network_layer.cc
index 4915cd1..4e53abe 100644
--- a/net/http/http_network_layer.cc
+++ b/net/http/http_network_layer.cc
@@ -12,6 +12,7 @@
#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 {
@@ -56,6 +57,7 @@ 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_);
@@ -67,6 +69,7 @@ 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());
@@ -94,15 +97,16 @@ void HttpNetworkLayer::Suspend(bool suspend) {
suspended_ = suspend;
if (suspend && session_)
- session_->Flush();
+ session_->tcp_socket_pool()->CloseIdleSockets();
}
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_layer.h b/net/http/http_network_layer.h
index 63df00b..2d4130d 100644
--- a/net/http/http_network_layer.h
+++ b/net/http/http_network_layer.h
@@ -20,6 +20,7 @@ class HttpNetworkSession;
class NetworkChangeNotifier;
class ProxyInfo;
class ProxyService;
+class SpdySessionPool;
class SSLConfigService;
class HttpNetworkLayer : public HttpTransactionFactory {
@@ -81,6 +82,7 @@ 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 ea8d1d7..146223b6 100644
--- a/net/http/http_network_session.cc
+++ b/net/http/http_network_session.cc
@@ -29,68 +29,49 @@ 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_(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);
}
// static
void HttpNetworkSession::set_max_sockets_per_group(int socket_count) {
- DCHECK_LT(0, socket_count);
+ DCHECK(0 < socket_count);
// The following is a sanity check... but we should NEVER be near this value.
- DCHECK_GT(100, socket_count);
+ DCHECK(100 > socket_count);
max_sockets_per_group_ = socket_count;
}
-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_));
+// 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_);
}
} // namespace net
diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h
index 23ba526..8f85ce7 100644
--- a/net/http/http_network_session.h
+++ b/net/http/http_network_session.h
@@ -8,7 +8,6 @@
#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"
@@ -26,9 +25,7 @@ class SpdySessionPool;
class NetworkChangeNotifier;
// 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,
@@ -36,6 +33,7 @@ class 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_; }
@@ -77,11 +75,9 @@ class HttpNetworkSession
return http_auth_handler_factory_;
}
- // Flushes cached data in the HttpNetworkSession.
- void Flush();
-
- // NetworkChangeNotifier::Observer methods:
- virtual void OnIPAddressChanged();
+ // 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);
@@ -97,9 +93,6 @@ class HttpNetworkSession
~HttpNetworkSession();
- scoped_refptr<TCPClientSocketPool> CreateNewTCPSocketPool();
- scoped_refptr<SOCKSClientSocketPool> CreateNewSOCKSSocketPool();
-
// Total limit of sockets. Not a constant to allow experiments.
static int max_sockets_;
@@ -115,10 +108,10 @@ class HttpNetworkSession
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_;
scoped_refptr<SOCKSClientSocketPool> 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 329f394c..0000000
--- a/net/http/http_network_session_unittest.cc
+++ /dev/null
@@ -1,82 +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());
-
- 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 df1604e..41408bd 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -43,20 +43,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) {
@@ -71,6 +74,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());
}
@@ -184,7 +188,8 @@ class CaptureGroupNameSocketPool : public EmulatedClientSocketPool {
CaptureGroupNameSocketPool(HttpNetworkSession* session,
SocketSourceType* socket_source)
: EmulatedClientSocketPool(0, 0, "CaptureGroupNameTestPool",
- session->host_resolver(), socket_source) {}
+ session->host_resolver(), socket_source,
+ NULL) {}
const std::string last_group_name_received() const {
return last_group_name_;
}
diff --git a/net/net.gyp b/net/net.gyp
index 1a41553..f0a632b 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -680,7 +680,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 eb1cd51..4b6cff0 100644
--- a/net/socket/client_socket_pool_base.cc
+++ b/net/socket/client_socket_pool_base.cc
@@ -110,7 +110,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),
@@ -120,10 +121,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() {
@@ -135,6 +140,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
@@ -583,6 +591,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 75572cf..d1abd58 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"
@@ -121,7 +122,8 @@ namespace internal {
// ClientSocketPoolBase instead.
class ClientSocketPoolBaseHelper
: public base::RefCounted<ClientSocketPoolBaseHelper>,
- public ConnectJob::Delegate {
+ public ConnectJob::Delegate,
+ public NetworkChangeNotifier::Observer {
public:
class Request {
public:
@@ -168,7 +170,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.
// Note that |request| must be heap allocated. If ERR_IO_PENDING is returned,
@@ -208,6 +211,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_; }
@@ -428,6 +434,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_;
@@ -494,12 +502,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 2b25785..a706df8 100644
--- a/net/socket/client_socket_pool_base_unittest.cc
+++ b/net/socket/client_socket_pool_base_unittest.cc
@@ -282,7 +282,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 36d12ba..246cc20 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 f74074a..2c30600 100644
--- a/net/socket/socks_client_socket_pool.h
+++ b/net/socket/socks_client_socket_pool.h
@@ -108,7 +108,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 cef7ff6..4291f3c 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"
@@ -83,9 +84,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,12 +171,11 @@ 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_client_socket_factory_, &tcp_notifier_)),
ignored_socket_params_(ignored_tcp_socket_params_, true, "host", 80,
MEDIUM, GURL()),
- pool_(new SOCKSClientSocketPool(
- kMaxSockets, kMaxSocketsPerGroup,
- "SOCKSUnitTest", NULL, tcp_socket_pool_.get())) {
+ pool_(new SOCKSClientSocketPool(kMaxSockets, kMaxSocketsPerGroup,
+ "SOCKSUnitTest", NULL, tcp_socket_pool_.get(), &socks_notifier_)) {
}
int StartRequest(const std::string& group_name, RequestPriority priority) {
@@ -184,9 +185,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 db8a88a..a833e01 100644
--- a/net/socket/tcp_client_socket_pool.cc
+++ b/net/socket/tcp_client_socket_pool.cc
@@ -176,11 +176,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 463e765..76950c3 100644
--- a/net/socket/tcp_client_socket_pool.h
+++ b/net/socket/tcp_client_socket_pool.h
@@ -103,7 +103,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 a41fb88..e7c8a9f 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"
@@ -246,7 +247,8 @@ class TCPClientSocketPoolTest : public ClientSocketPoolTest {
kMaxSocketsPerGroup,
"TCPUnitTest",
host_resolver_,
- &client_socket_factory_)) {
+ &client_socket_factory_,
+ &notifier_)) {
}
int StartRequest(const std::string& group_name, RequestPriority priority) {
@@ -257,6 +259,7 @@ class TCPClientSocketPoolTest : public ClientSocketPoolTest {
TCPSocketParams ignored_socket_params_;
scoped_refptr<MockHostResolver> host_resolver_;
MockClientSocketFactory client_socket_factory_;
+ MockNetworkChangeNotifier notifier_;
scoped_refptr<TCPClientSocketPool> pool_;
};
@@ -625,6 +628,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_, 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 d7d0cdf..cc08a9e 100644
--- a/net/spdy/spdy_network_transaction_unittest.cc
+++ b/net/spdy/spdy_network_transaction_unittest.cc
@@ -54,7 +54,8 @@ 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) {
// 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
@@ -69,13 +70,15 @@ class SessionDependencies {
: 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;
};
HttpNetworkSession* CreateSession(SessionDependencies* session_deps) {
@@ -84,6 +87,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 471a52f..2dd0820 100644
--- a/net/spdy/spdy_session_unittest.cc
+++ b/net/spdy/spdy_session_unittest.cc
@@ -28,13 +28,15 @@ class SessionDependencies {
SessionDependencies()
: host_resolver(new MockHostResolver),
proxy_service(ProxyService::CreateNull()),
- ssl_config_service(new SSLConfigServiceDefaults) {
+ ssl_config_service(new SSLConfigServiceDefaults),
+ 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_refptr<SpdySessionPool> spdy_session_pool;
};
HttpNetworkSession* CreateSession(SessionDependencies* session_deps) {
@@ -43,6 +45,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 a2cfa72..b8c4b7f 100644
--- a/net/spdy/spdy_stream_unittest.cc
+++ b/net/spdy/spdy_stream_unittest.cc
@@ -52,20 +52,23 @@ class SessionDependencies {
: host_resolver(new MockHostResolver),
proxy_service(CreateNullProxyService()),
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;
};
HttpNetworkSession* CreateSession(SessionDependencies* session_deps) {
@@ -74,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());
}