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/client_socket_pool_base.cc | |
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/client_socket_pool_base.cc')
-rw-r--r-- | net/socket/client_socket_pool_base.cc | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc index c40830d..be197f5 100644 --- a/net/socket/client_socket_pool_base.cc +++ b/net/socket/client_socket_pool_base.cc @@ -123,7 +123,9 @@ ClientSocketPoolBaseHelper::Request::Request( CompletionCallback* callback, RequestPriority priority, const BoundNetLog& net_log) - : handle_(handle), callback_(callback), priority_(priority), + : handle_(handle), + callback_(callback), + priority_(priority), net_log_(net_log) {} ClientSocketPoolBaseHelper::Request::~Request() {} @@ -143,7 +145,8 @@ ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( used_idle_socket_timeout_(used_idle_socket_timeout), connect_job_factory_(connect_job_factory), connect_backup_jobs_enabled_(false), - pool_generation_number_(0) { + pool_generation_number_(0), + method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { DCHECK_LE(0, max_sockets_per_group); DCHECK_LE(max_sockets_per_group, max_sockets); @@ -151,13 +154,11 @@ ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( } ClientSocketPoolBaseHelper::~ClientSocketPoolBaseHelper() { - CancelAllConnectJobs(); - - // Clean up any idle sockets. Assert that we have no remaining active - // sockets or pending requests. They should have all been cleaned up prior - // to the manager being destroyed. - CloseIdleSockets(); - CHECK(group_map_.empty()); + // Clean up any idle sockets and pending connect jobs. Assert that we have no + // remaining active sockets or pending requests. They should have all been + // cleaned up prior to |this| being destroyed. + Flush(); + DCHECK(group_map_.empty()); DCHECK(pending_callback_map_.empty()); DCHECK_EQ(0, connecting_socket_count_); @@ -623,12 +624,6 @@ void ClientSocketPoolBaseHelper::OnConnectJobComplete( BoundNetLog job_log = job->net_log(); - // ConnectJobs may hold references to pools which may hold references back to - // this pool, so RemoveConnectJob() may eventually lead to something calling - // Release() on |this| which deletes it in the middle of this function. Hold - // a self-reference to prevent deletion of |this|. - const scoped_refptr<ClientSocketPoolBaseHelper> self(this); - if (result == OK) { DCHECK(socket.get()); RemoveConnectJob(job, group); @@ -854,8 +849,7 @@ void ClientSocketPoolBaseHelper::InvokeUserCallbackLater( pending_callback_map_[handle] = CallbackResultPair(callback, rv); MessageLoop::current()->PostTask( FROM_HERE, - NewRunnableMethod( - this, + method_factory_.NewRunnableMethod( &ClientSocketPoolBaseHelper::InvokeUserCallback, handle)); } |