| Index: net/socket/client_socket_pool_base.cc
|
| diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc
|
| index 231254a5b7d5cb126920812afbeea606bdf7b2be..4c1600eeb52ebbf2a361008804680bf27d8927b7 100644
|
| --- a/net/socket/client_socket_pool_base.cc
|
| +++ b/net/socket/client_socket_pool_base.cc
|
| @@ -23,6 +23,10 @@ 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.
|
| +bool g_cleanup_timer_enabled = true;
|
| +
|
| // The timeout value, in seconds, used to clean up idle sockets that can't be
|
| // reused.
|
| //
|
| @@ -182,6 +186,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),
|
| @@ -237,6 +242,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);
|
|
|
| @@ -258,6 +267,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_;
|
| }
|
| @@ -696,9 +709,8 @@ void ClientSocketPoolBaseHelper::EnableConnectBackupJobs() {
|
| }
|
|
|
| void ClientSocketPoolBaseHelper::IncrementIdleCount() {
|
| - if (++idle_socket_count_ == 1)
|
| - timer_.Start(FROM_HERE, TimeDelta::FromSeconds(kCleanupInterval), this,
|
| - &ClientSocketPoolBaseHelper::OnCleanupTimerFired);
|
| + if (++idle_socket_count_ == 1 && use_cleanup_timer_)
|
| + StartIdleSocketTimer();
|
| }
|
|
|
| void ClientSocketPoolBaseHelper::DecrementIdleCount() {
|
| @@ -706,6 +718,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(FROM_HERE, TimeDelta::FromSeconds(kCleanupInterval), this,
|
| + &ClientSocketPoolBaseHelper::OnCleanupTimerFired);
|
| +}
|
| +
|
| void ClientSocketPoolBaseHelper::ReleaseSocket(const std::string& group_name,
|
| StreamSocket* socket,
|
| int id) {
|
| @@ -896,8 +925,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);
|
| }
|
| }
|
|
|
|
|