diff options
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 2 | ||||
-rw-r--r-- | net/http/http_proxy_client_socket_pool.cc | 2 | ||||
-rw-r--r-- | net/http/http_proxy_client_socket_pool.h | 2 | ||||
-rw-r--r-- | net/socket/client_socket_handle.cc | 10 | ||||
-rw-r--r-- | net/socket/client_socket_handle.h | 4 | ||||
-rw-r--r-- | net/socket/client_socket_pool.h | 2 | ||||
-rw-r--r-- | net/socket/client_socket_pool_base.cc | 168 | ||||
-rw-r--r-- | net/socket/client_socket_pool_base.h | 64 | ||||
-rw-r--r-- | net/socket/client_socket_pool_base_unittest.cc | 9 | ||||
-rw-r--r-- | net/socket/socket_test_util.cc | 9 | ||||
-rw-r--r-- | net/socket/socket_test_util.h | 8 | ||||
-rw-r--r-- | net/socket/socks_client_socket_pool.cc | 2 | ||||
-rw-r--r-- | net/socket/socks_client_socket_pool.h | 2 | ||||
-rw-r--r-- | net/socket/ssl_client_socket_pool.cc | 2 | ||||
-rw-r--r-- | net/socket/ssl_client_socket_pool.h | 2 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_pool.cc | 2 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_pool.h | 2 |
17 files changed, 164 insertions, 128 deletions
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index 48945db..c21634f 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -267,7 +267,7 @@ class CaptureGroupNameSocketPool : public ParentPool { return ERR_IO_PENDING; } virtual void CancelRequest(const std::string& group_name, - const ClientSocketHandle* handle) { } + ClientSocketHandle* handle) {} virtual void ReleaseSocket(const std::string& group_name, ClientSocket* socket) {} virtual void CloseIdleSockets() {} diff --git a/net/http/http_proxy_client_socket_pool.cc b/net/http/http_proxy_client_socket_pool.cc index 31c7822..a142576 100644 --- a/net/http/http_proxy_client_socket_pool.cc +++ b/net/http/http_proxy_client_socket_pool.cc @@ -199,7 +199,7 @@ int HttpProxyClientSocketPool::RequestSocket(const std::string& group_name, void HttpProxyClientSocketPool::CancelRequest( const std::string& group_name, - const ClientSocketHandle* handle) { + ClientSocketHandle* handle) { base_.CancelRequest(group_name, handle); } diff --git a/net/http/http_proxy_client_socket_pool.h b/net/http/http_proxy_client_socket_pool.h index a23318f..afe7d19 100644 --- a/net/http/http_proxy_client_socket_pool.h +++ b/net/http/http_proxy_client_socket_pool.h @@ -131,7 +131,7 @@ class HttpProxyClientSocketPool : public ClientSocketPool { const BoundNetLog& net_log); virtual void CancelRequest(const std::string& group_name, - const ClientSocketHandle* handle); + ClientSocketHandle* handle); virtual void ReleaseSocket(const std::string& group_name, ClientSocket* socket, diff --git a/net/socket/client_socket_handle.cc b/net/socket/client_socket_handle.cc index 73142bf..7093e14 100644 --- a/net/socket/client_socket_handle.cc +++ b/net/socket/client_socket_handle.cc @@ -14,7 +14,7 @@ namespace net { ClientSocketHandle::ClientSocketHandle() - : socket_(NULL), + : is_initialized_(false), is_reused_(false), ALLOW_THIS_IN_INITIALIZER_LIST( callback_(this, &ClientSocketHandle::OnIOComplete)), @@ -32,7 +32,7 @@ void ClientSocketHandle::Reset() { void ClientSocketHandle::ResetInternal(bool cancel) { if (group_name_.empty()) // Was Init called? return; - if (socket_.get()) { + if (is_initialized()) { // Because of http://crbug.com/37810 we may not have a pool, but have // just a raw socket. socket_->NetLog().EndEvent(NetLog::TYPE_SOCKET_IN_USE, NULL); @@ -41,10 +41,11 @@ void ClientSocketHandle::ResetInternal(bool cancel) { // it can be deleted or reused. pool_->ReleaseSocket(group_name_, release_socket(), pool_id_); } else if (cancel) { - // If we did not get initialized yet, so we've got a socket request pending. + // If we did not get initialized yet, we've got a socket request pending. // Cancel it. pool_->CancelRequest(group_name_, this); } + is_initialized_ = false; group_name_.clear(); is_reused_ = false; user_callback_ = NULL; @@ -82,8 +83,11 @@ void ClientSocketHandle::HandleInitCompletion(int result) { if (result != OK) { if (!socket_.get()) ResetInternal(false); // Nothing to cancel since the request failed. + else + is_initialized_ = true; return; } + is_initialized_ = true; CHECK_NE(-1, pool_id_) << "Pool should have set |pool_id_| to a valid value."; setup_time_ = base::TimeTicks::Now() - init_time_; diff --git a/net/socket/client_socket_handle.h b/net/socket/client_socket_handle.h index b0cb574..b8e6cc3 100644 --- a/net/socket/client_socket_handle.h +++ b/net/socket/client_socket_handle.h @@ -91,7 +91,7 @@ class ClientSocketHandle { LoadState GetLoadState() const; // Returns true when Init() has completed successfully. - bool is_initialized() const { return socket_ != NULL; } + bool is_initialized() const { return is_initialized_; } // Returns the time tick when Init() was called. base::TimeTicks init_time() const { return init_time_; } @@ -114,6 +114,7 @@ class ClientSocketHandle { // These may only be used if is_initialized() is true. const std::string& group_name() const { return group_name_; } + int id() const { return pool_id_; } ClientSocket* socket() { return socket_.get(); } ClientSocket* release_socket() { return socket_.release(); } const HttpResponseInfo& tunnel_auth_response_info() const { @@ -165,6 +166,7 @@ class ClientSocketHandle { // Resets the supplemental error state. void ResetErrorState(); + bool is_initialized_; scoped_refptr<ClientSocketPool> pool_; scoped_ptr<ClientSocket> socket_; std::string group_name_; diff --git a/net/socket/client_socket_pool.h b/net/socket/client_socket_pool.h index b22da31..646b5ed 100644 --- a/net/socket/client_socket_pool.h +++ b/net/socket/client_socket_pool.h @@ -71,7 +71,7 @@ class ClientSocketPool : public base::RefCounted<ClientSocketPool> { // not run. However, for performance, we will let one ConnectJob complete // and go idle. virtual void CancelRequest(const std::string& group_name, - const ClientSocketHandle* handle) = 0; + ClientSocketHandle* handle) = 0; // Called to release a socket once the socket is no longer needed. If the // socket still has an established connection, then it will be added to the diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc index 019452c..e4a611b 100644 --- a/net/socket/client_socket_pool_base.cc +++ b/net/socket/client_socket_pool_base.cc @@ -139,8 +139,7 @@ ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( connect_job_factory_(connect_job_factory), backup_jobs_enabled_(false), ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), - pool_generation_number_(0), - last_stalled_group_count_(0) { + pool_generation_number_(0) { DCHECK_LE(0, max_sockets_per_group); DCHECK_LE(max_sockets_per_group, max_sockets); @@ -155,6 +154,7 @@ ClientSocketPoolBaseHelper::~ClientSocketPoolBaseHelper() { // to the manager being destroyed. CloseIdleSockets(); CHECK(group_map_.empty()); + DCHECK(pending_callback_map_.empty()); DCHECK_EQ(0, connecting_socket_count_); NetworkChangeNotifier::RemoveObserver(this); @@ -191,6 +191,7 @@ int ClientSocketPoolBaseHelper::RequestSocket( int rv = RequestSocketInternal(group_name, request); if (rv != ERR_IO_PENDING) { request->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL); + CHECK(!request->handle()->is_initialized()); delete request; } else { InsertRequestIntoQueue(request, &group.pending_requests); @@ -262,16 +263,16 @@ int ClientSocketPoolBaseHelper::RequestSocketInternal( if (error_socket) { HandOutSocket(error_socket, false /* not reused */, handle, base::TimeDelta(), &group, request->net_log()); - } - if (group.IsEmpty()) + } else if (group.IsEmpty()) { group_map_.erase(group_name); + } } return rv; } -bool ClientSocketPoolBaseHelper::AssignIdleSocketToGroup(Group* group, - const Request* request) { +bool ClientSocketPoolBaseHelper::AssignIdleSocketToGroup( + Group* group, const Request* request) { // Iterate through the list of idle sockets until we find one or exhaust // the list. while (!group->idle_sockets.empty()) { @@ -355,10 +356,19 @@ void ClientSocketPoolBaseHelper::OnBackupSocketTimerFired( } void ClientSocketPoolBaseHelper::CancelRequest( - const std::string& group_name, const ClientSocketHandle* handle) { - // Running callbacks can cause the last outside reference to be released. - // Hold onto a reference. - scoped_refptr<ClientSocketPoolBaseHelper> ref_holder(this); + const std::string& group_name, ClientSocketHandle* handle) { + PendingCallbackMap::iterator callback_it = pending_callback_map_.find(handle); + if (callback_it != pending_callback_map_.end()) { + int result = callback_it->second.result; + pending_callback_map_.erase(callback_it); + ClientSocket* socket = handle->release_socket(); + if (socket) { + if (result != OK) + socket->Disconnect(); + ReleaseSocket(handle->group_name(), socket, handle->id()); + } + return; + } CHECK(ContainsKey(group_map_, group_name)); @@ -398,6 +408,9 @@ int ClientSocketPoolBaseHelper::IdleSocketCountInGroup( LoadState ClientSocketPoolBaseHelper::GetLoadState( const std::string& group_name, const ClientSocketHandle* handle) const { + if (ContainsKey(pending_callback_map_, handle)) + return LOAD_STATE_CONNECTING; + if (!ContainsKey(group_map_, group_name)) { NOTREACHED() << "ClientSocketPool does not contain group: " << group_name << " for handle: " << handle; @@ -486,10 +499,6 @@ void ClientSocketPoolBaseHelper::DecrementIdleCount() { void ClientSocketPoolBaseHelper::ReleaseSocket(const std::string& group_name, ClientSocket* socket, int id) { - // Running callbacks can cause the last outside reference to be released. - // Hold onto a reference. - scoped_refptr<ClientSocketPoolBaseHelper> ref_holder(this); - GroupMap::iterator i = group_map_.find(group_name); CHECK(i != group_map_.end()); @@ -506,11 +515,11 @@ void ClientSocketPoolBaseHelper::ReleaseSocket(const std::string& group_name, if (can_reuse) { // Add it to the idle list. AddIdleSocket(socket, true /* used socket */, &group); - OnAvailableSocketSlot(group_name, MayHaveStalledGroups()); + OnAvailableSocketSlot(group_name, &group); } else { delete socket; } - // Check to see if there are stalled groups that can resume now. + CheckForStalledSocketGroups(); } @@ -518,8 +527,7 @@ void ClientSocketPoolBaseHelper::CheckForStalledSocketGroups() { // If we have idle sockets, see if we can give one to the top-stalled group. std::string top_group_name; Group* top_group = NULL; - last_stalled_group_count_ = FindTopStalledGroup(&top_group, &top_group_name); - if (!last_stalled_group_count_) + if (!FindTopStalledGroup(&top_group, &top_group_name)) return; if (ReachedMaxSocketsLimit()) { @@ -534,35 +542,28 @@ void ClientSocketPoolBaseHelper::CheckForStalledSocketGroups() { // Note: we don't loop on waking stalled groups. If the stalled group is at // its limit, may be left with other stalled groups that could be - // waken. This isn't optimal, but there is no starvation, so to avoid + // woken. This isn't optimal, but there is no starvation, so to avoid // the looping we leave it at this. - OnAvailableSocketSlot(top_group_name, false); -} - -bool ClientSocketPoolBaseHelper::MayHaveStalledGroups() { - return last_stalled_group_count_ > 0 || ReachedMaxSocketsLimit(); + OnAvailableSocketSlot(top_group_name, top_group); } // Search for the highest priority pending request, amongst the groups that // are not at the |max_sockets_per_group_| limit. Note: for requests with // the same priority, the winner is based on group hash ordering (and not // insertion order). -int ClientSocketPoolBaseHelper::FindTopStalledGroup(Group** group, - std::string* group_name) { +bool ClientSocketPoolBaseHelper::FindTopStalledGroup(Group** group, + std::string* group_name) { Group* top_group = NULL; const std::string* top_group_name = NULL; - int stalled_group_count = 0; + bool has_stalled_group = false; for (GroupMap::iterator i = group_map_.begin(); i != group_map_.end(); ++i) { Group& group = i->second; const RequestQueue& queue = group.pending_requests; if (queue.empty()) continue; - bool has_unused_slot = - group.HasAvailableSocketSlot(max_sockets_per_group_) && - group.pending_requests.size() > group.jobs.size(); - if (has_unused_slot) { - stalled_group_count++; + if (group.IsStalled(max_sockets_per_group_)) { + has_stalled_group = true; bool has_higher_priority = !top_group || group.TopPendingPriority() < top_group->TopPendingPriority(); if (has_higher_priority) { @@ -571,19 +572,16 @@ int ClientSocketPoolBaseHelper::FindTopStalledGroup(Group** group, } } } + if (top_group) { *group = top_group; *group_name = *top_group_name; } - return stalled_group_count; + return has_stalled_group; } void ClientSocketPoolBaseHelper::OnConnectJobComplete( int result, ConnectJob* job) { - // Running callbacks can cause the last outside reference to be released. - // Hold onto a reference. - scoped_refptr<ClientSocketPoolBaseHelper> ref_holder(this); - DCHECK_NE(ERR_IO_PENDING, result); const std::string group_name = job->group_name(); GroupMap::iterator group_it = group_map_.find(group_name); @@ -605,10 +603,11 @@ void ClientSocketPoolBaseHelper::OnConnectJobComplete( socket.release(), false /* unused socket */, r->handle(), base::TimeDelta(), &group, r->net_log()); r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, NULL); - r->callback()->Run(result); + InvokeUserCallbackLater(r->handle(), r->callback(), result); } else { AddIdleSocket(socket.release(), false /* unused socket */, &group); - OnAvailableSocketSlot(group_name, MayHaveStalledGroups()); + OnAvailableSocketSlot(group_name, &group); + CheckForStalledSocketGroups(); } } else { // If we got a socket, it must contain error information so pass that @@ -627,12 +626,14 @@ void ClientSocketPoolBaseHelper::OnConnectJobComplete( } r->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, new NetLogIntegerParameter("net_error", result)); - r->callback()->Run(result); + InvokeUserCallbackLater(r->handle(), r->callback(), result); } else { RemoveConnectJob(job, &group); } - if (!handed_out_socket) - OnAvailableSocketSlot(group_name, MayHaveStalledGroups()); + if (!handed_out_socket) { + OnAvailableSocketSlot(group_name, &group); + CheckForStalledSocketGroups(); + } } } @@ -665,47 +666,29 @@ void ClientSocketPoolBaseHelper::RemoveConnectJob(const ConnectJob* job, } void ClientSocketPoolBaseHelper::OnAvailableSocketSlot( - const std::string& group_name, bool was_at_socket_limit) { - // Go back to the message loop before processing the request wakeup - // so that we don't get recursive and lengthy stacks. - MessageLoop::current()->PostTask(FROM_HERE, - NewRunnableMethod( - this, - &ClientSocketPoolBaseHelper::ProcessPendingRequest, - group_name, - was_at_socket_limit)); + const std::string& group_name, Group* group) { + if (!group->pending_requests.empty()) + ProcessPendingRequest(group_name, group); + + if (group->IsEmpty()) + group_map_.erase(group_name); } void ClientSocketPoolBaseHelper::ProcessPendingRequest( - const std::string& group_name, bool was_at_socket_limit) { - GroupMap::iterator it = group_map_.find(group_name); - if (it != group_map_.end()) { - Group& group = it->second; - if (!group.pending_requests.empty()) { - int rv = RequestSocketInternal(group_name, - *group.pending_requests.begin()); - if (rv != ERR_IO_PENDING) { - scoped_ptr<const Request> request(RemoveRequestFromQueue( - group.pending_requests.begin(), &group.pending_requests)); - - scoped_refptr<NetLog::EventParameters> params; - if (rv != OK) - params = new NetLogIntegerParameter("net_error", rv); - request->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, params); - request->callback()->Run(rv); - } - - // |group| may no longer be valid after this point. Be careful not to - // access it again. - if (group.IsEmpty()) { - // Delete |group| if no longer needed. |group| will no longer be valid. - group_map_.erase(group_name); - } - } + const std::string& group_name, Group* group) { + int rv = RequestSocketInternal(group_name, + *group->pending_requests.begin()); + if (rv != ERR_IO_PENDING) { + scoped_ptr<const Request> request(RemoveRequestFromQueue( + group->pending_requests.begin(), &group->pending_requests)); + + scoped_refptr<NetLog::EventParameters> params; + if (rv != OK) + params = new NetLogIntegerParameter("net_error", rv); + request->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL, params); + InvokeUserCallbackLater( + request->handle(), request->callback(), rv); } - - if (was_at_socket_limit) - CheckForStalledSocketGroups(); } void ClientSocketPoolBaseHelper::HandOutSocket( @@ -800,6 +783,33 @@ void ClientSocketPoolBaseHelper::CloseOneIdleSocket() { LOG(DFATAL) << "No idle socket found to close!."; } +void ClientSocketPoolBaseHelper::InvokeUserCallbackLater( + ClientSocketHandle* handle, CompletionCallback* callback, int rv) { + CHECK(!ContainsKey(pending_callback_map_, handle)); + pending_callback_map_[handle] = CallbackResultPair(callback, rv); + MessageLoop::current()->PostTask( + FROM_HERE, + NewRunnableMethod( + this, + &ClientSocketPoolBaseHelper::InvokeUserCallback, + handle)); +} + +void ClientSocketPoolBaseHelper::InvokeUserCallback( + ClientSocketHandle* handle) { + PendingCallbackMap::iterator it = pending_callback_map_.find(handle); + + // Exit if the request has already been cancelled. + if (it == pending_callback_map_.end()) + return; + + CHECK(!handle->is_initialized()); + CompletionCallback* callback = it->second.callback; + int result = it->second.result; + pending_callback_map_.erase(it); + callback->Run(result); +} + } // namespace internal } // namespace net diff --git a/net/socket/client_socket_pool_base.h b/net/socket/client_socket_pool_base.h index 77698ce..ef4b115 100644 --- a/net/socket/client_socket_pool_base.h +++ b/net/socket/client_socket_pool_base.h @@ -188,7 +188,7 @@ class ClientSocketPoolBaseHelper // See ClientSocketPool::CancelRequest for documentation on this function. void CancelRequest(const std::string& group_name, - const ClientSocketHandle* handle); + ClientSocketHandle* handle); // See ClientSocketPool::ReleaseSocket for documentation on this function. void ReleaseSocket(const std::string& group_name, @@ -243,8 +243,6 @@ class ClientSocketPoolBaseHelper private: friend class base::RefCounted<ClientSocketPoolBaseHelper>; - ~ClientSocketPoolBaseHelper(); - // Entry for a persistent socket which became idle at time |start_time|. struct IdleSocket { IdleSocket() : socket(NULL), used(false) {} @@ -290,6 +288,11 @@ class ClientSocketPoolBaseHelper max_sockets_per_group; } + bool IsStalled(int max_sockets_per_group) const { + return HasAvailableSocketSlot(max_sockets_per_group) && + pending_requests.size() > jobs.size(); + } + RequestPriority TopPendingPriority() const { return pending_requests.front()->priority(); } @@ -318,6 +321,20 @@ class ClientSocketPoolBaseHelper typedef std::set<const ConnectJob*> ConnectJobSet; + struct CallbackResultPair { + CallbackResultPair() : callback(NULL), result(OK) {} + CallbackResultPair(CompletionCallback* callback_in, int result_in) + : callback(callback_in), result(result_in) {} + + CompletionCallback* callback; + int result; + }; + + typedef std::map<const ClientSocketHandle*, CallbackResultPair> + PendingCallbackMap; + + ~ClientSocketPoolBaseHelper(); + static void InsertRequestIntoQueue(const Request* r, RequestQueue* pending_requests); static const Request* RemoveRequestFromQueue(RequestQueue::iterator it, @@ -328,10 +345,10 @@ class ClientSocketPoolBaseHelper void DecrementIdleCount(); // Scans the group map for groups which have an available socket slot and - // at least one pending request. Returns number of groups found, and if found - // at least one, fills |group| and |group_name| with data of the stalled group + // at least one pending request. Returns true if any groups are stalled, and + // if so, fills |group| and |group_name| with data of the stalled group // having highest priority. - int FindTopStalledGroup(Group** group, std::string* group_name); + bool FindTopStalledGroup(Group** group, std::string* group_name); // Called when timer_ fires. This method scans the idle sockets removing // sockets that timed out or can't be reused. @@ -342,17 +359,11 @@ class ClientSocketPoolBaseHelper // Removes |job| from |connect_job_set_|. Also updates |group| if non-NULL. void RemoveConnectJob(const ConnectJob* job, Group* group); - // Might delete the Group from |group_map_|. - // If |was_at_socket_limit|, will also check for idle sockets to assign - // to any stalled groups. - void OnAvailableSocketSlot(const std::string& group_name, - bool was_at_socket_limit); + // Tries to see if we can handle any more requests for |group|. + void OnAvailableSocketSlot(const std::string& group_name, Group* group); // Process a pending socket request for a group. - // If |was_at_socket_limit|, will also check for idle sockets to assign - // to any stalled groups. - void ProcessPendingRequest(const std::string& group_name, - bool was_at_socket_limit); + void ProcessPendingRequest(const std::string& group_name, Group* group); // Assigns |socket| to |handle| and updates |group|'s counters appropriately. void HandOutSocket(ClientSocket* socket, @@ -404,11 +415,25 @@ class ClientSocketPoolBaseHelper // for possible wakeup. void CheckForStalledSocketGroups(); - // Returns true if we might have a stalled group. - bool MayHaveStalledGroups(); + // Posts a task to call InvokeUserCallback() on the next iteration through the + // current message loop. Inserts |callback| into |pending_callback_map_|, + // keyed by |handle|. + void InvokeUserCallbackLater( + ClientSocketHandle* handle, CompletionCallback* callback, int rv); + + // Invokes the user callback for |handle|. By the time this task has run, + // it's possible that the request has been cancelled, so |handle| may not + // exist in |pending_callback_map_|. We look up the callback and result code + // in |pending_callback_map_|. + void InvokeUserCallback(ClientSocketHandle* handle); GroupMap group_map_; + // Map of the ClientSocketHandles for which we have a pending Task to invoke a + // callback. This is necessary since, before we invoke said callback, it's + // possible that the request is cancelled. + PendingCallbackMap pending_callback_map_; + // Timer used to periodically prune idle sockets that timed out or can't be // reused. base::RepeatingTimer<ClientSocketPoolBaseHelper> timer_; @@ -444,9 +469,6 @@ class ClientSocketPoolBaseHelper // pool. This is so that when sockets get released back to the pool, we can // make sure that they are discarded rather than reused. int pool_generation_number_; - - // The count of stalled groups the last time we checked. - int last_stalled_group_count_; }; } // namespace internal @@ -527,7 +549,7 @@ class ClientSocketPoolBase { } void CancelRequest(const std::string& group_name, - const ClientSocketHandle* handle) { + ClientSocketHandle* handle) { return helper_->CancelRequest(group_name, handle); } diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc index 53063ba..9686794 100644 --- a/net/socket/client_socket_pool_base_unittest.cc +++ b/net/socket/client_socket_pool_base_unittest.cc @@ -370,7 +370,7 @@ class TestClientSocketPool : public ClientSocketPool { virtual void CancelRequest( const std::string& group_name, - const ClientSocketHandle* handle) { + ClientSocketHandle* handle) { base_.CancelRequest(group_name, handle); } @@ -521,8 +521,10 @@ class ClientSocketPoolBaseTest : public ClientSocketPoolTest { // to delete |requests_| because the pool is reference counted and requests // keep reference to it. // TODO(willchan): Remove this part when late binding becomes the default. + TestClientSocketPool* pool = pool_.get(); pool_ = NULL; requests_.reset(); + pool = NULL; ClientSocketPoolTest::TearDown(); } @@ -934,11 +936,6 @@ TEST_F(ClientSocketPoolBaseTest, CancelPendingSocketAtSocketLimit) { // Cancel the stalled request. handles[0].Reset(); - // Wait for the pending job to be guaranteed to complete. - PlatformThread::Sleep(TestConnectJob::kPendingConnectDelay * 2); - - MessageLoop::current()->RunAllPending(); - // Now we should have a connect job. EXPECT_EQ(1, pool_->NumConnectJobsInGroup("foo")); diff --git a/net/socket/socket_test_util.cc b/net/socket/socket_test_util.cc index bb40354..0d75516 100644 --- a/net/socket/socket_test_util.cc +++ b/net/socket/socket_test_util.cc @@ -792,10 +792,11 @@ bool MockTCPClientSocketPool::MockConnectJob::CancelHandle( void MockTCPClientSocketPool::MockConnectJob::OnConnect(int rv) { if (!socket_.get()) return; - if (rv == OK) + if (rv == OK) { handle_->set_socket(socket_.release()); - else + } else { socket_.reset(); + } handle_ = NULL; @@ -833,7 +834,7 @@ int MockTCPClientSocketPool::RequestSocket(const std::string& group_name, } void MockTCPClientSocketPool::CancelRequest(const std::string& group_name, - const ClientSocketHandle* handle) { + ClientSocketHandle* handle) { std::vector<MockConnectJob*>::iterator i; for (i = job_list_.begin(); i != job_list_.end(); ++i) { if ((*i)->CancelHandle(handle)) { @@ -874,7 +875,7 @@ int MockSOCKSClientSocketPool::RequestSocket(const std::string& group_name, void MockSOCKSClientSocketPool::CancelRequest( const std::string& group_name, - const ClientSocketHandle* handle) { + ClientSocketHandle* handle) { return tcp_pool_->CancelRequest(group_name, handle); } diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h index b9c0f0c..bb52c0c 100644 --- a/net/socket/socket_test_util.h +++ b/net/socket/socket_test_util.h @@ -635,8 +635,8 @@ class MockTCPClientSocketPool : public TCPClientSocketPool { const scoped_refptr<ClientSocketPoolHistograms>& histograms, ClientSocketFactory* socket_factory); - int release_count() { return release_count_; }; - int cancel_count() { return cancel_count_; }; + int release_count() const { return release_count_; }; + int cancel_count() const { return cancel_count_; }; // TCPClientSocketPool methods. virtual int RequestSocket(const std::string& group_name, @@ -647,7 +647,7 @@ class MockTCPClientSocketPool : public TCPClientSocketPool { const BoundNetLog& net_log); virtual void CancelRequest(const std::string& group_name, - const ClientSocketHandle* handle); + ClientSocketHandle* handle); virtual void ReleaseSocket(const std::string& group_name, ClientSocket* socket, int id); @@ -680,7 +680,7 @@ class MockSOCKSClientSocketPool : public SOCKSClientSocketPool { const BoundNetLog& net_log); virtual void CancelRequest(const std::string& group_name, - const ClientSocketHandle* handle); + ClientSocketHandle* handle); virtual void ReleaseSocket(const std::string& group_name, ClientSocket* socket, int id); diff --git a/net/socket/socks_client_socket_pool.cc b/net/socket/socks_client_socket_pool.cc index f04af19..d1c75b6 100644 --- a/net/socket/socks_client_socket_pool.cc +++ b/net/socket/socks_client_socket_pool.cc @@ -205,7 +205,7 @@ int SOCKSClientSocketPool::RequestSocket(const std::string& group_name, } void SOCKSClientSocketPool::CancelRequest(const std::string& group_name, - const ClientSocketHandle* handle) { + ClientSocketHandle* handle) { base_.CancelRequest(group_name, handle); } diff --git a/net/socket/socks_client_socket_pool.h b/net/socket/socks_client_socket_pool.h index 795c13c..4387aa7 100644 --- a/net/socket/socks_client_socket_pool.h +++ b/net/socket/socks_client_socket_pool.h @@ -121,7 +121,7 @@ class SOCKSClientSocketPool : public ClientSocketPool { const BoundNetLog& net_log); virtual void CancelRequest(const std::string& group_name, - const ClientSocketHandle* handle); + ClientSocketHandle* handle); virtual void ReleaseSocket(const std::string& group_name, ClientSocket* socket, diff --git a/net/socket/ssl_client_socket_pool.cc b/net/socket/ssl_client_socket_pool.cc index fedb3ca..cfe3df4 100644 --- a/net/socket/ssl_client_socket_pool.cc +++ b/net/socket/ssl_client_socket_pool.cc @@ -394,7 +394,7 @@ int SSLClientSocketPool::RequestSocket(const std::string& group_name, } void SSLClientSocketPool::CancelRequest(const std::string& group_name, - const ClientSocketHandle* handle) { + ClientSocketHandle* handle) { base_.CancelRequest(group_name, handle); } diff --git a/net/socket/ssl_client_socket_pool.h b/net/socket/ssl_client_socket_pool.h index cba012c..48bba9c 100644 --- a/net/socket/ssl_client_socket_pool.h +++ b/net/socket/ssl_client_socket_pool.h @@ -171,7 +171,7 @@ class SSLClientSocketPool : public ClientSocketPool { const BoundNetLog& net_log); virtual void CancelRequest(const std::string& group_name, - const ClientSocketHandle* handle); + ClientSocketHandle* handle); virtual void ReleaseSocket(const std::string& group_name, ClientSocket* socket, diff --git a/net/socket/tcp_client_socket_pool.cc b/net/socket/tcp_client_socket_pool.cc index 7d7c110..2caa3fb 100644 --- a/net/socket/tcp_client_socket_pool.cc +++ b/net/socket/tcp_client_socket_pool.cc @@ -234,7 +234,7 @@ int TCPClientSocketPool::RequestSocket( void TCPClientSocketPool::CancelRequest( const std::string& group_name, - const ClientSocketHandle* handle) { + ClientSocketHandle* handle) { base_.CancelRequest(group_name, handle); } diff --git a/net/socket/tcp_client_socket_pool.h b/net/socket/tcp_client_socket_pool.h index 99513fd..1ee50d2 100644 --- a/net/socket/tcp_client_socket_pool.h +++ b/net/socket/tcp_client_socket_pool.h @@ -129,7 +129,7 @@ class TCPClientSocketPool : public ClientSocketPool { const BoundNetLog& net_log); virtual void CancelRequest(const std::string& group_name, - const ClientSocketHandle* handle); + ClientSocketHandle* handle); virtual void ReleaseSocket(const std::string& group_name, ClientSocket* socket, |