diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-29 20:26:13 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-29 20:26:13 +0000 |
commit | 2431756ea7ceea7ac837522d948c3628cf83b647 (patch) | |
tree | 89e8921ce9f257f2dfeeb2491fb0ea246d4d1050 /net/socket/socket_test_util.h | |
parent | 252c50a4cdb5a9506938b231f4bd19afd5365757 (diff) | |
download | chromium_src-2431756ea7ceea7ac837522d948c3628cf83b647.zip chromium_src-2431756ea7ceea7ac837522d948c3628cf83b647.tar.gz chromium_src-2431756ea7ceea7ac837522d948c3628cf83b647.tar.bz2 |
Stop refcounting ClientSocketPool.
Establishes that HttpNetworkSession owns all the socket pools.
Move out all the socket pools into a ClientSocketPoolManager. This is because
of the dependency tree amongst socket pools, which dictates the order in which
they must be constructed and destructed. In order to better establish it, I
moved them out to their own class. HttpNetworkSession owns the
ClientSocketPoolManager which owns the pools. We pass the pools as raw
pointers everywhere.
Note that ClientSocketPoolManager owns more pools than are publicly accessible via its interface. That's because some of them are wrapped by publicly exposed pools.
Also, ClientSocketPoolHistograms used to be reference counted. That's because it can be shared by multiple ClientSocketPools. But it's effectively a global as well, so I make their lifetimes persist for the length of ClientSocketPoolManager too.
I also removed internal refcounting in ClientSocketPoolBase. I had refcounted
it before I knew about ScopedRunnableMethodFactory back when I first started.
I cleaned up the unit tests a lot. Back when I was a young padawan, I didn't
really know what I was doing, so I copy/pasted a metric asston of code. Turns
out most of it was stupid, so I fixed it. I also stopped the use of
implementation inheritance with ClientSocketPoolTest because it's discouraged
by the style guide and more importantly because it caused the
ClientSocketHandles within the TestSocketRequest vector to be destroyed _after_
the pools themselves were destroyed, which is bad since the handles will call
pool_->Release() which blows up.
BUG=56215,56215
TEST=Existing unit tests
Review URL: http://codereview.chromium.org/3389020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60983 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/socket_test_util.h')
-rw-r--r-- | net/socket/socket_test_util.h | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h index 7cc6f84..7f83a70 100644 --- a/net/socket/socket_test_util.h +++ b/net/socket/socket_test_util.h @@ -702,8 +702,8 @@ class TestSocketRequest : public CallbackRunner< Tuple1<int> > { TestCompletionCallback callback_; }; -class ClientSocketPoolTest : public testing::Test { - protected: +class ClientSocketPoolTest { + public: enum KeepAlive { KEEP_ALIVE, @@ -714,15 +714,15 @@ class ClientSocketPoolTest : public testing::Test { static const int kIndexOutOfBounds; static const int kRequestNotFound; - virtual void SetUp(); - virtual void TearDown(); + ClientSocketPoolTest(); + ~ClientSocketPoolTest(); template <typename PoolType, typename SocketParams> - int StartRequestUsingPool(const scoped_refptr<PoolType>& socket_pool, + int StartRequestUsingPool(PoolType* socket_pool, const std::string& group_name, RequestPriority priority, const scoped_refptr<SocketParams>& socket_params) { - DCHECK(socket_pool.get()); + DCHECK(socket_pool); TestSocketRequest* request = new TestSocketRequest(&request_order_, &completion_count_); requests_.push_back(request); @@ -738,7 +738,7 @@ class ClientSocketPoolTest : public testing::Test { // and returns order in which that request completed, in range 1..n, // or kIndexOutOfBounds if |index| is out of bounds, or kRequestNotFound // if that request did not complete (for example was canceled). - int GetOrderOfRequest(size_t index); + int GetOrderOfRequest(size_t index) const; // Resets first initialized socket handle from |requests_|. If found such // a handle, returns true. @@ -747,6 +747,12 @@ class ClientSocketPoolTest : public testing::Test { // Releases connections until there is nothing to release. void ReleaseAllConnections(KeepAlive keep_alive); + TestSocketRequest* request(int i) { return requests_[i]; } + size_t requests_size() const { return requests_.size(); } + ScopedVector<TestSocketRequest>* requests() { return &requests_; } + size_t completion_count() const { return completion_count_; } + + private: ScopedVector<TestSocketRequest> requests_; std::vector<TestSocketRequest*> request_order_; size_t completion_count_; @@ -776,9 +782,11 @@ class MockTCPClientSocketPool : public TCPClientSocketPool { MockTCPClientSocketPool( int max_sockets, int max_sockets_per_group, - const scoped_refptr<ClientSocketPoolHistograms>& histograms, + ClientSocketPoolHistograms* histograms, ClientSocketFactory* socket_factory); + virtual ~MockTCPClientSocketPool(); + int release_count() const { return release_count_; } int cancel_count() const { return cancel_count_; } @@ -795,9 +803,6 @@ class MockTCPClientSocketPool : public TCPClientSocketPool { virtual void ReleaseSocket(const std::string& group_name, ClientSocket* socket, int id); - protected: - virtual ~MockTCPClientSocketPool(); - private: ClientSocketFactory* client_socket_factory_; ScopedVector<MockConnectJob> job_list_; @@ -847,8 +852,10 @@ class MockSOCKSClientSocketPool : public SOCKSClientSocketPool { MockSOCKSClientSocketPool( int max_sockets, int max_sockets_per_group, - const scoped_refptr<ClientSocketPoolHistograms>& histograms, - const scoped_refptr<TCPClientSocketPool>& tcp_pool); + ClientSocketPoolHistograms* histograms, + TCPClientSocketPool* tcp_pool); + + virtual ~MockSOCKSClientSocketPool(); // SOCKSClientSocketPool methods. virtual int RequestSocket(const std::string& group_name, @@ -863,11 +870,8 @@ class MockSOCKSClientSocketPool : public SOCKSClientSocketPool { virtual void ReleaseSocket(const std::string& group_name, ClientSocket* socket, int id); - protected: - virtual ~MockSOCKSClientSocketPool(); - private: - const scoped_refptr<TCPClientSocketPool> tcp_pool_; + TCPClientSocketPool* const tcp_pool_; DISALLOW_COPY_AND_ASSIGN(MockSOCKSClientSocketPool); }; @@ -909,8 +913,11 @@ class MockSSLClientSocketPool : public SSLClientSocketPool { MockSSLClientSocketPool( int max_sockets, int max_sockets_per_group, - const scoped_refptr<ClientSocketPoolHistograms>& histograms, - ClientSocketFactory* socket_factory); + ClientSocketPoolHistograms* histograms, + ClientSocketFactory* socket_factory, + TCPClientSocketPool* tcp_pool); + + virtual ~MockSSLClientSocketPool(); int release_count() const { return release_count_; } int cancel_count() const { return cancel_count_; } @@ -928,9 +935,6 @@ class MockSSLClientSocketPool : public SSLClientSocketPool { virtual void ReleaseSocket(const std::string& group_name, ClientSocket* socket, int id); - protected: - virtual ~MockSSLClientSocketPool(); - private: ClientSocketFactory* client_socket_factory_; int release_count_; |