diff options
Diffstat (limited to 'net/socket/client_socket_pool_base.cc')
-rw-r--r-- | net/socket/client_socket_pool_base.cc | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc index b6f6190..46cfc45 100644 --- a/net/socket/client_socket_pool_base.cc +++ b/net/socket/client_socket_pool_base.cc @@ -20,6 +20,14 @@ using base::TimeDelta; namespace { +// Indicate whether we should enable idle socket cleanup timer. When timer is +// disabled, sockets are closed next time a socket request is made. +#ifdef ANDROID +bool g_cleanup_timer_enabled = false; +#else +bool g_cleanup_timer_enabled = true; +#endif + // The timeout value, in seconds, used to clean up idle sockets that can't be // reused. // @@ -164,6 +172,7 @@ ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( handed_out_socket_count_(0), max_sockets_(max_sockets), max_sockets_per_group_(max_sockets_per_group), + use_cleanup_timer_(g_cleanup_timer_enabled), unused_idle_socket_timeout_(unused_idle_socket_timeout), used_idle_socket_timeout_(used_idle_socket_timeout), connect_job_factory_(connect_job_factory), @@ -219,6 +228,10 @@ int ClientSocketPoolBaseHelper::RequestSocket( CHECK(request->callback()); CHECK(request->handle()); + // Cleanup any timed-out idle sockets if no timer is used. + if (!use_cleanup_timer_) + CleanupIdleSockets(false); + request->net_log().BeginEvent(NetLog::TYPE_SOCKET_POOL, NULL); Group* group = GetOrCreateGroup(group_name); @@ -240,6 +253,10 @@ void ClientSocketPoolBaseHelper::RequestSockets( DCHECK(!request.callback()); DCHECK(!request.handle()); + // Cleanup any timed out idle sockets if no timer is used. + if (!use_cleanup_timer_) + CleanupIdleSockets(false); + if (num_sockets > max_sockets_per_group_) { num_sockets = max_sockets_per_group_; } @@ -664,8 +681,7 @@ void ClientSocketPoolBaseHelper::EnableConnectBackupJobs() { void ClientSocketPoolBaseHelper::IncrementIdleCount() { if (++idle_socket_count_ == 1) - timer_.Start(TimeDelta::FromSeconds(kCleanupInterval), this, - &ClientSocketPoolBaseHelper::OnCleanupTimerFired); + StartIdleSocketTimer(); } void ClientSocketPoolBaseHelper::DecrementIdleCount() { @@ -673,6 +689,23 @@ void ClientSocketPoolBaseHelper::DecrementIdleCount() { timer_.Stop(); } +// static +bool ClientSocketPoolBaseHelper::cleanup_timer_enabled() { + return g_cleanup_timer_enabled; +} + +// static +bool ClientSocketPoolBaseHelper::set_cleanup_timer_enabled(bool enabled) { + bool old_value = g_cleanup_timer_enabled; + g_cleanup_timer_enabled = enabled; + return old_value; +} + +void ClientSocketPoolBaseHelper::StartIdleSocketTimer() { + timer_.Start(TimeDelta::FromSeconds(kCleanupInterval), this, + &ClientSocketPoolBaseHelper::OnCleanupTimerFired); +} + void ClientSocketPoolBaseHelper::ReleaseSocket(const std::string& group_name, ClientSocket* socket, int id) { @@ -863,8 +896,7 @@ void ClientSocketPoolBaseHelper::ProcessPendingRequest( RemoveGroup(group_name); request->net_log().EndEventWithNetErrorCode(NetLog::TYPE_SOCKET_POOL, rv); - InvokeUserCallbackLater( - request->handle(), request->callback(), rv); + InvokeUserCallbackLater(request->handle(), request->callback(), rv); } } |