| 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 9e1abf482a5b6180abfa57031fe2cf80c5376a3c..483b839386925d79420e03f5334707461cfda7e5 100644
|
| --- a/net/socket/client_socket_pool_base.cc
|
| +++ b/net/socket/client_socket_pool_base.cc
|
| @@ -127,13 +127,12 @@ void ConnectJob::OnTimeout() {
|
|
|
| namespace internal {
|
|
|
| -ClientSocketPoolBaseHelper::Request::Request(
|
| - ClientSocketHandle* handle,
|
| - const CompletionCallback& callback,
|
| - RequestPriority priority,
|
| - bool ignore_limits,
|
| - Flags flags,
|
| - const BoundNetLog& net_log)
|
| +ClientSocketPoolBaseHelper::Request::Request(ClientSocketHandle* handle,
|
| + const CompletionCallback& callback,
|
| + RequestPriority priority,
|
| + bool ignore_limits,
|
| + Flags flags,
|
| + const BoundNetLog& net_log)
|
| : handle_(handle),
|
| callback_(callback),
|
| priority_(priority),
|
| @@ -144,7 +143,8 @@ ClientSocketPoolBaseHelper::Request::Request(
|
| DCHECK_EQ(priority_, MAXIMUM_PRIORITY);
|
| }
|
|
|
| -ClientSocketPoolBaseHelper::Request::~Request() {}
|
| +ClientSocketPoolBaseHelper::Request::~Request() {
|
| +}
|
|
|
| ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper(
|
| HigherLayeredPool* pool,
|
| @@ -197,12 +197,13 @@ ClientSocketPoolBaseHelper::CallbackResultPair::CallbackResultPair()
|
| }
|
|
|
| ClientSocketPoolBaseHelper::CallbackResultPair::CallbackResultPair(
|
| - const CompletionCallback& callback_in, int result_in)
|
| - : callback(callback_in),
|
| - result(result_in) {
|
| + const CompletionCallback& callback_in,
|
| + int result_in)
|
| + : callback(callback_in), result(result_in) {
|
| }
|
|
|
| -ClientSocketPoolBaseHelper::CallbackResultPair::~CallbackResultPair() {}
|
| +ClientSocketPoolBaseHelper::CallbackResultPair::~CallbackResultPair() {
|
| +}
|
|
|
| bool ClientSocketPoolBaseHelper::IsStalled() const {
|
| // If a lower layer pool is stalled, consider |this| stalled as well.
|
| @@ -224,8 +225,8 @@ bool ClientSocketPoolBaseHelper::IsStalled() const {
|
| // |max_sockets_per_group_|. (If the number of sockets is equal to
|
| // |max_sockets_per_group_|, then the request is stalled on the group limit,
|
| // which does not count.)
|
| - for (GroupMap::const_iterator it = group_map_.begin();
|
| - it != group_map_.end(); ++it) {
|
| + for (GroupMap::const_iterator it = group_map_.begin(); it != group_map_.end();
|
| + ++it) {
|
| if (it->second->IsStalledOnPoolMaxSockets(max_sockets_per_group_))
|
| return true;
|
| }
|
| @@ -289,10 +290,9 @@ int ClientSocketPoolBaseHelper::RequestSocket(
|
| return rv;
|
| }
|
|
|
| -void ClientSocketPoolBaseHelper::RequestSockets(
|
| - const std::string& group_name,
|
| - const Request& request,
|
| - int num_sockets) {
|
| +void ClientSocketPoolBaseHelper::RequestSockets(const std::string& group_name,
|
| + const Request& request,
|
| + int num_sockets) {
|
| DCHECK(request.callback().is_null());
|
| DCHECK(!request.handle());
|
|
|
| @@ -315,8 +315,8 @@ void ClientSocketPoolBaseHelper::RequestSockets(
|
|
|
| int rv = OK;
|
| for (int num_iterations_left = num_sockets;
|
| - group->NumActiveSocketSlots() < num_sockets &&
|
| - num_iterations_left > 0 ; num_iterations_left--) {
|
| + group->NumActiveSocketSlots() < num_sockets && num_iterations_left > 0;
|
| + num_iterations_left--) {
|
| rv = RequestSocketInternal(group_name, request);
|
| if (rv < 0 && rv != ERR_IO_PENDING) {
|
| // We're encountering a synchronous error. Give up.
|
| @@ -400,9 +400,13 @@ int ClientSocketPoolBaseHelper::RequestSocketInternal(
|
| if (rv == OK) {
|
| LogBoundConnectJobToRequest(connect_job->net_log().source(), request);
|
| if (!preconnecting) {
|
| - HandOutSocket(connect_job->PassSocket(), ClientSocketHandle::UNUSED,
|
| - connect_job->connect_timing(), handle, base::TimeDelta(),
|
| - group, request.net_log());
|
| + HandOutSocket(connect_job->PassSocket(),
|
| + ClientSocketHandle::UNUSED,
|
| + connect_job->connect_timing(),
|
| + handle,
|
| + base::TimeDelta(),
|
| + group,
|
| + request.net_log());
|
| } else {
|
| AddIdleSocket(connect_job->PassSocket(), group);
|
| }
|
| @@ -426,9 +430,13 @@ int ClientSocketPoolBaseHelper::RequestSocketInternal(
|
| error_socket = connect_job->PassSocket();
|
| }
|
| if (error_socket) {
|
| - HandOutSocket(error_socket.Pass(), ClientSocketHandle::UNUSED,
|
| - connect_job->connect_timing(), handle, base::TimeDelta(),
|
| - group, request.net_log());
|
| + HandOutSocket(error_socket.Pass(),
|
| + ClientSocketHandle::UNUSED,
|
| + connect_job->connect_timing(),
|
| + handle,
|
| + base::TimeDelta(),
|
| + group,
|
| + request.net_log());
|
| } else if (group->IsEmpty()) {
|
| RemoveGroup(group_name);
|
| }
|
| @@ -438,7 +446,8 @@ int ClientSocketPoolBaseHelper::RequestSocketInternal(
|
| }
|
|
|
| bool ClientSocketPoolBaseHelper::AssignIdleSocketToRequest(
|
| - const Request& request, Group* group) {
|
| + const Request& request,
|
| + Group* group) {
|
| std::list<IdleSocket>* idle_sockets = group->mutable_idle_sockets();
|
| std::list<IdleSocket>::iterator idle_socket_it = idle_sockets->end();
|
|
|
| @@ -479,17 +488,15 @@ bool ClientSocketPoolBaseHelper::AssignIdleSocketToRequest(
|
| // treating as UNUSED rather than UNUSED_IDLE. This will avoid
|
| // HttpNetworkTransaction retrying on some errors.
|
| ClientSocketHandle::SocketReuseType reuse_type =
|
| - idle_socket.socket->WasEverUsed() ?
|
| - ClientSocketHandle::REUSED_IDLE :
|
| - ClientSocketHandle::UNUSED_IDLE;
|
| - HandOutSocket(
|
| - scoped_ptr<StreamSocket>(idle_socket.socket),
|
| - reuse_type,
|
| - LoadTimingInfo::ConnectTiming(),
|
| - request.handle(),
|
| - idle_time,
|
| - group,
|
| - request.net_log());
|
| + idle_socket.socket->WasEverUsed() ? ClientSocketHandle::REUSED_IDLE
|
| + : ClientSocketHandle::UNUSED_IDLE;
|
| + HandOutSocket(scoped_ptr<StreamSocket>(idle_socket.socket),
|
| + reuse_type,
|
| + LoadTimingInfo::ConnectTiming(),
|
| + request.handle(),
|
| + idle_time,
|
| + group,
|
| + request.net_log());
|
| return true;
|
| }
|
|
|
| @@ -498,13 +505,14 @@ bool ClientSocketPoolBaseHelper::AssignIdleSocketToRequest(
|
|
|
| // static
|
| void ClientSocketPoolBaseHelper::LogBoundConnectJobToRequest(
|
| - const NetLog::Source& connect_job_source, const Request& request) {
|
| + const NetLog::Source& connect_job_source,
|
| + const Request& request) {
|
| request.net_log().AddEvent(NetLog::TYPE_SOCKET_POOL_BOUND_TO_CONNECT_JOB,
|
| connect_job_source.ToEventParametersCallback());
|
| }
|
|
|
| -void ClientSocketPoolBaseHelper::CancelRequest(
|
| - const std::string& group_name, ClientSocketHandle* handle) {
|
| +void ClientSocketPoolBaseHelper::CancelRequest(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;
|
| @@ -576,7 +584,8 @@ LoadState ClientSocketPoolBaseHelper::GetLoadState(
|
| // group.jobs().size() pending requests.
|
| LoadState max_state = LOAD_STATE_IDLE;
|
| for (ConnectJobSet::const_iterator job_it = group.jobs().begin();
|
| - job_it != group.jobs().end(); ++job_it) {
|
| + job_it != group.jobs().end();
|
| + ++job_it) {
|
| max_state = std::max(max_state, (*job_it)->GetLoadState());
|
| }
|
| return max_state;
|
| @@ -588,7 +597,8 @@ LoadState ClientSocketPoolBaseHelper::GetLoadState(
|
| }
|
|
|
| base::DictionaryValue* ClientSocketPoolBaseHelper::GetInfoAsValue(
|
| - const std::string& name, const std::string& type) const {
|
| + const std::string& name,
|
| + const std::string& type) const {
|
| base::DictionaryValue* dict = new base::DictionaryValue();
|
| dict->SetString("name", name);
|
| dict->SetString("type", type);
|
| @@ -603,8 +613,8 @@ base::DictionaryValue* ClientSocketPoolBaseHelper::GetInfoAsValue(
|
| return dict;
|
|
|
| base::DictionaryValue* all_groups_dict = new base::DictionaryValue();
|
| - for (GroupMap::const_iterator it = group_map_.begin();
|
| - it != group_map_.end(); it++) {
|
| + for (GroupMap::const_iterator it = group_map_.begin(); it != group_map_.end();
|
| + it++) {
|
| const Group* group = it->second;
|
| base::DictionaryValue* group_dict = new base::DictionaryValue();
|
|
|
| @@ -636,9 +646,8 @@ base::DictionaryValue* ClientSocketPoolBaseHelper::GetInfoAsValue(
|
| }
|
| group_dict->Set("connect_jobs", connect_jobs_list);
|
|
|
| - group_dict->SetBoolean("is_stalled",
|
| - group->IsStalledOnPoolMaxSockets(
|
| - max_sockets_per_group_));
|
| + group_dict->SetBoolean(
|
| + "is_stalled", group->IsStalledOnPoolMaxSockets(max_sockets_per_group_));
|
| group_dict->SetBoolean("backup_job_timer_is_running",
|
| group->BackupJobTimerIsRunning());
|
|
|
| @@ -677,9 +686,9 @@ void ClientSocketPoolBaseHelper::CleanupIdleSockets(bool force) {
|
|
|
| std::list<IdleSocket>::iterator j = group->mutable_idle_sockets()->begin();
|
| while (j != group->idle_sockets().end()) {
|
| - base::TimeDelta timeout =
|
| - j->socket->WasEverUsed() ?
|
| - used_idle_socket_timeout_ : unused_idle_socket_timeout_;
|
| + base::TimeDelta timeout = j->socket->WasEverUsed()
|
| + ? used_idle_socket_timeout_
|
| + : unused_idle_socket_timeout_;
|
| if (force || j->ShouldCleanup(now, timeout)) {
|
| delete j->socket;
|
| j = group->mutable_idle_sockets()->erase(j);
|
| @@ -759,7 +768,9 @@ bool ClientSocketPoolBaseHelper::set_cleanup_timer_enabled(bool enabled) {
|
| }
|
|
|
| void ClientSocketPoolBaseHelper::StartIdleSocketTimer() {
|
| - timer_.Start(FROM_HERE, TimeDelta::FromSeconds(kCleanupInterval), this,
|
| + timer_.Start(FROM_HERE,
|
| + TimeDelta::FromSeconds(kCleanupInterval),
|
| + this,
|
| &ClientSocketPoolBaseHelper::OnCleanupTimerFired);
|
| }
|
|
|
| @@ -777,8 +788,8 @@ void ClientSocketPoolBaseHelper::ReleaseSocket(const std::string& group_name,
|
| CHECK_GT(group->active_socket_count(), 0);
|
| group->DecrementActiveSocketCount();
|
|
|
| - const bool can_reuse = socket->IsConnectedAndIdle() &&
|
| - id == pool_generation_number_;
|
| + const bool can_reuse =
|
| + socket->IsConnectedAndIdle() && id == pool_generation_number_;
|
| if (can_reuse) {
|
| // Add it to the idle list.
|
| AddIdleSocket(socket.Pass(), group);
|
| @@ -799,10 +810,10 @@ void ClientSocketPoolBaseHelper::CheckForStalledSocketGroups() {
|
| for (std::set<LowerLayeredPool*>::iterator it = lower_pools_.begin();
|
| it != lower_pools_.end();
|
| ++it) {
|
| - if ((*it)->IsStalled()) {
|
| - CloseOneIdleSocket();
|
| - break;
|
| - }
|
| + if ((*it)->IsStalled()) {
|
| + CloseOneIdleSocket();
|
| + break;
|
| + }
|
| }
|
| return;
|
| }
|
| @@ -835,8 +846,8 @@ bool ClientSocketPoolBaseHelper::FindTopStalledGroup(
|
| Group* top_group = NULL;
|
| const std::string* top_group_name = NULL;
|
| bool has_stalled_group = false;
|
| - for (GroupMap::const_iterator i = group_map_.begin();
|
| - i != group_map_.end(); ++i) {
|
| + for (GroupMap::const_iterator i = group_map_.begin(); i != group_map_.end();
|
| + ++i) {
|
| Group* curr_group = i->second;
|
| if (!curr_group->has_pending_requests())
|
| continue;
|
| @@ -844,7 +855,8 @@ bool ClientSocketPoolBaseHelper::FindTopStalledGroup(
|
| if (!group)
|
| return true;
|
| has_stalled_group = true;
|
| - bool has_higher_priority = !top_group ||
|
| + bool has_higher_priority =
|
| + !top_group ||
|
| curr_group->TopPendingPriority() > top_group->TopPendingPriority();
|
| if (has_higher_priority) {
|
| top_group = curr_group;
|
| @@ -863,8 +875,8 @@ bool ClientSocketPoolBaseHelper::FindTopStalledGroup(
|
| return has_stalled_group;
|
| }
|
|
|
| -void ClientSocketPoolBaseHelper::OnConnectJobComplete(
|
| - int result, ConnectJob* job) {
|
| +void ClientSocketPoolBaseHelper::OnConnectJobComplete(int result,
|
| + ConnectJob* job) {
|
| DCHECK_NE(ERR_IO_PENDING, result);
|
| const std::string group_name = job->group_name();
|
| GroupMap::iterator group_it = group_map_.find(group_name);
|
| @@ -887,9 +899,13 @@ void ClientSocketPoolBaseHelper::OnConnectJobComplete(
|
| scoped_ptr<const Request> request = group->PopNextPendingRequest();
|
| if (request) {
|
| LogBoundConnectJobToRequest(job_log.source(), *request);
|
| - HandOutSocket(
|
| - socket.Pass(), ClientSocketHandle::UNUSED, connect_timing,
|
| - request->handle(), base::TimeDelta(), group, request->net_log());
|
| + HandOutSocket(socket.Pass(),
|
| + ClientSocketHandle::UNUSED,
|
| + connect_timing,
|
| + request->handle(),
|
| + base::TimeDelta(),
|
| + group,
|
| + request->net_log());
|
| request->net_log().EndEvent(NetLog::TYPE_SOCKET_POOL);
|
| InvokeUserCallbackLater(request->handle(), request->callback(), result);
|
| } else {
|
| @@ -908,12 +924,16 @@ void ClientSocketPoolBaseHelper::OnConnectJobComplete(
|
| RemoveConnectJob(job, group);
|
| if (socket.get()) {
|
| handed_out_socket = true;
|
| - HandOutSocket(socket.Pass(), ClientSocketHandle::UNUSED,
|
| - connect_timing, request->handle(), base::TimeDelta(),
|
| - group, request->net_log());
|
| + HandOutSocket(socket.Pass(),
|
| + ClientSocketHandle::UNUSED,
|
| + connect_timing,
|
| + request->handle(),
|
| + base::TimeDelta(),
|
| + group,
|
| + request->net_log());
|
| }
|
| - request->net_log().EndEventWithNetErrorCode(
|
| - NetLog::TYPE_SOCKET_POOL, result);
|
| + request->net_log().EndEventWithNetErrorCode(NetLog::TYPE_SOCKET_POOL,
|
| + result);
|
| InvokeUserCallbackLater(request->handle(), request->callback(), result);
|
| } else {
|
| RemoveConnectJob(job, group);
|
| @@ -946,7 +966,8 @@ void ClientSocketPoolBaseHelper::RemoveConnectJob(ConnectJob* job,
|
| }
|
|
|
| void ClientSocketPoolBaseHelper::OnAvailableSocketSlot(
|
| - const std::string& group_name, Group* group) {
|
| + const std::string& group_name,
|
| + Group* group) {
|
| DCHECK(ContainsKey(group_map_, group_name));
|
| if (group->IsEmpty()) {
|
| RemoveGroup(group_name);
|
| @@ -956,7 +977,8 @@ void ClientSocketPoolBaseHelper::OnAvailableSocketSlot(
|
| }
|
|
|
| void ClientSocketPoolBaseHelper::ProcessPendingRequest(
|
| - const std::string& group_name, Group* group) {
|
| + const std::string& group_name,
|
| + Group* group) {
|
| const Request* next_request = group->GetNextPendingRequest();
|
| DCHECK(next_request);
|
| int rv = RequestSocketInternal(group_name, *next_request);
|
| @@ -989,8 +1011,8 @@ void ClientSocketPoolBaseHelper::HandOutSocket(
|
| if (handle->is_reused()) {
|
| net_log.AddEvent(
|
| NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET,
|
| - NetLog::IntegerCallback(
|
| - "idle_ms", static_cast<int>(idle_time.InMilliseconds())));
|
| + NetLog::IntegerCallback("idle_ms",
|
| + static_cast<int>(idle_time.InMilliseconds())));
|
| }
|
|
|
| net_log.AddEvent(
|
| @@ -1001,9 +1023,8 @@ void ClientSocketPoolBaseHelper::HandOutSocket(
|
| group->IncrementActiveSocketCount();
|
| }
|
|
|
| -void ClientSocketPoolBaseHelper::AddIdleSocket(
|
| - scoped_ptr<StreamSocket> socket,
|
| - Group* group) {
|
| +void ClientSocketPoolBaseHelper::AddIdleSocket(scoped_ptr<StreamSocket> socket,
|
| + Group* group) {
|
| DCHECK(socket);
|
| IdleSocket idle_socket;
|
| idle_socket.socket = socket.release();
|
| @@ -1057,8 +1078,8 @@ void ClientSocketPoolBaseHelper::CancelAllRequestsWithError(int error) {
|
|
|
| bool ClientSocketPoolBaseHelper::ReachedMaxSocketsLimit() const {
|
| // Each connecting socket will eventually connect and be handed out.
|
| - int total = handed_out_socket_count_ + connecting_socket_count_ +
|
| - idle_socket_count();
|
| + int total =
|
| + handed_out_socket_count_ + connecting_socket_count_ + idle_socket_count();
|
| // There can be more sockets than the limit since some requests can ignore
|
| // the limit
|
| if (total < max_sockets_)
|
| @@ -1101,7 +1122,8 @@ bool ClientSocketPoolBaseHelper::CloseOneIdleConnectionInHigherLayeredPool() {
|
| // higher layer is holding one of this sockets active, but it's actually idle.
|
| // Query the higher layers.
|
| for (std::set<HigherLayeredPool*>::const_iterator it = higher_pools_.begin();
|
| - it != higher_pools_.end(); ++it) {
|
| + it != higher_pools_.end();
|
| + ++it) {
|
| if ((*it)->CloseOneIdleConnection())
|
| return true;
|
| }
|
| @@ -1109,13 +1131,16 @@ bool ClientSocketPoolBaseHelper::CloseOneIdleConnectionInHigherLayeredPool() {
|
| }
|
|
|
| void ClientSocketPoolBaseHelper::InvokeUserCallbackLater(
|
| - ClientSocketHandle* handle, const CompletionCallback& callback, int rv) {
|
| + ClientSocketHandle* handle,
|
| + const CompletionCallback& callback,
|
| + int rv) {
|
| CHECK(!ContainsKey(pending_callback_map_, handle));
|
| pending_callback_map_[handle] = CallbackResultPair(callback, rv);
|
| base::MessageLoop::current()->PostTask(
|
| FROM_HERE,
|
| base::Bind(&ClientSocketPoolBaseHelper::InvokeUserCallback,
|
| - weak_factory_.GetWeakPtr(), handle));
|
| + weak_factory_.GetWeakPtr(),
|
| + handle));
|
| }
|
|
|
| void ClientSocketPoolBaseHelper::InvokeUserCallback(
|
| @@ -1145,7 +1170,8 @@ void ClientSocketPoolBaseHelper::TryToCloseSocketsInLayeredPools() {
|
| ClientSocketPoolBaseHelper::Group::Group()
|
| : unassigned_job_count_(0),
|
| pending_requests_(NUM_PRIORITIES),
|
| - active_socket_count_(0) {}
|
| + active_socket_count_(0) {
|
| +}
|
|
|
| ClientSocketPoolBaseHelper::Group::~Group() {
|
| DCHECK_EQ(0u, unassigned_job_count_);
|
| @@ -1160,10 +1186,12 @@ void ClientSocketPoolBaseHelper::Group::StartBackupJobTimer(
|
|
|
| // Unretained here is okay because |backup_job_timer_| is
|
| // automatically cancelled when it's destroyed.
|
| - backup_job_timer_.Start(
|
| - FROM_HERE, pool->ConnectRetryInterval(),
|
| - base::Bind(&Group::OnBackupJobTimerFired, base::Unretained(this),
|
| - group_name, pool));
|
| + backup_job_timer_.Start(FROM_HERE,
|
| + pool->ConnectRetryInterval(),
|
| + base::Bind(&Group::OnBackupJobTimerFired,
|
| + base::Unretained(this),
|
| + group_name,
|
| + pool));
|
| }
|
|
|
| bool ClientSocketPoolBaseHelper::Group::BackupJobTimerIsRunning() const {
|
| @@ -1230,9 +1258,8 @@ void ClientSocketPoolBaseHelper::Group::OnBackupJobTimerFired(
|
| if (pending_requests_.empty())
|
| return;
|
|
|
| - scoped_ptr<ConnectJob> backup_job =
|
| - pool->connect_job_factory_->NewConnectJob(
|
| - group_name, *pending_requests_.FirstMax().value(), pool);
|
| + scoped_ptr<ConnectJob> backup_job = pool->connect_job_factory_->NewConnectJob(
|
| + group_name, *pending_requests_.FirstMax().value(), pool);
|
| backup_job->net_log().AddEvent(NetLog::TYPE_BACKUP_CONNECT_JOB_CREATED);
|
| SIMPLE_STATS_COUNTER("socket.backup_created");
|
| int rv = backup_job->Connect();
|
| @@ -1260,8 +1287,8 @@ void ClientSocketPoolBaseHelper::Group::RemoveAllJobs() {
|
|
|
| const ClientSocketPoolBaseHelper::Request*
|
| ClientSocketPoolBaseHelper::Group::GetNextPendingRequest() const {
|
| - return
|
| - pending_requests_.empty() ? NULL : pending_requests_.FirstMax().value();
|
| + return pending_requests_.empty() ? NULL
|
| + : pending_requests_.FirstMax().value();
|
| }
|
|
|
| bool ClientSocketPoolBaseHelper::Group::HasConnectJobForHandle(
|
|
|