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 /net/socket | |
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
Diffstat (limited to 'net/socket')
-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 | 2 | ||||
-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 | 15 | ||||
-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 | 31 |
9 files changed, 19 insertions, 79 deletions
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[] = { |