Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "net/socket/client_socket_pool_base.h" | 5 #include "net/socket/client_socket_pool_base.h" | 
| 6 | 6 | 
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" | 
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" | 
| 9 #include "base/logging.h" | 9 #include "base/logging.h" | 
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" | 
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 if (group_it == group_map_.end()) { | 565 if (group_it == group_map_.end()) { | 
| 566 // TODO(mmenke): This is actually reached in the wild, for unknown reasons. | 566 // TODO(mmenke): This is actually reached in the wild, for unknown reasons. | 
| 567 // Would be great to understand why, and if it's a bug, fix it. If not, | 567 // Would be great to understand why, and if it's a bug, fix it. If not, | 
| 568 // should have a test for that case. | 568 // should have a test for that case. | 
| 569 NOTREACHED(); | 569 NOTREACHED(); | 
| 570 return LOAD_STATE_IDLE; | 570 return LOAD_STATE_IDLE; | 
| 571 } | 571 } | 
| 572 | 572 | 
| 573 const Group& group = *group_it->second; | 573 const Group& group = *group_it->second; | 
| 574 if (group.HasConnectJobForHandle(handle)) { | 574 if (group.HasConnectJobForHandle(handle)) { | 
| 575 // Just return the state of the farthest along ConnectJob for the first | 575 // Just return the state of the oldest ConnectJob. | 
| 576 // group.jobs().size() pending requests. | 576 return (*group.jobs().begin())->GetLoadState(); | 
| 577 LoadState max_state = LOAD_STATE_IDLE; | |
| 578 for (const auto& job : group.jobs()) { | |
| 579 max_state = std::max(max_state, job->GetLoadState()); | |
| 580 } | |
| 581 return max_state; | |
| 582 } | 577 } | 
| 583 | 578 | 
| 584 if (group.CanUseAdditionalSocketSlot(max_sockets_per_group_)) | 579 if (group.CanUseAdditionalSocketSlot(max_sockets_per_group_)) | 
| 585 return LOAD_STATE_WAITING_FOR_STALLED_SOCKET_POOL; | 580 return LOAD_STATE_WAITING_FOR_STALLED_SOCKET_POOL; | 
| 586 return LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET; | 581 return LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET; | 
| 587 } | 582 } | 
| 588 | 583 | 
| 589 base::DictionaryValue* ClientSocketPoolBaseHelper::GetInfoAsValue( | 584 base::DictionaryValue* ClientSocketPoolBaseHelper::GetInfoAsValue( | 
| 590 const std::string& name, const std::string& type) const { | 585 const std::string& name, const std::string& type) const { | 
| 591 base::DictionaryValue* dict = new base::DictionaryValue(); | 586 base::DictionaryValue* dict = new base::DictionaryValue(); | 
| (...skipping 29 matching lines...) Expand all Loading... | |
| 621 std::list<IdleSocket>::const_iterator idle_socket; | 616 std::list<IdleSocket>::const_iterator idle_socket; | 
| 622 for (idle_socket = group->idle_sockets().begin(); | 617 for (idle_socket = group->idle_sockets().begin(); | 
| 623 idle_socket != group->idle_sockets().end(); | 618 idle_socket != group->idle_sockets().end(); | 
| 624 idle_socket++) { | 619 idle_socket++) { | 
| 625 int source_id = idle_socket->socket->NetLog().source().id; | 620 int source_id = idle_socket->socket->NetLog().source().id; | 
| 626 idle_socket_list->Append(new base::FundamentalValue(source_id)); | 621 idle_socket_list->Append(new base::FundamentalValue(source_id)); | 
| 627 } | 622 } | 
| 628 group_dict->Set("idle_sockets", idle_socket_list); | 623 group_dict->Set("idle_sockets", idle_socket_list); | 
| 629 | 624 | 
| 630 base::ListValue* connect_jobs_list = new base::ListValue(); | 625 base::ListValue* connect_jobs_list = new base::ListValue(); | 
| 631 std::set<ConnectJob*>::const_iterator job = group->jobs().begin(); | 626 std::list<ConnectJob*>::const_iterator job = group->jobs().begin(); | 
| 632 for (job = group->jobs().begin(); job != group->jobs().end(); job++) { | 627 for (job = group->jobs().begin(); job != group->jobs().end(); job++) { | 
| 633 int source_id = (*job)->net_log().source().id; | 628 int source_id = (*job)->net_log().source().id; | 
| 634 connect_jobs_list->Append(new base::FundamentalValue(source_id)); | 629 connect_jobs_list->Append(new base::FundamentalValue(source_id)); | 
| 635 } | 630 } | 
| 636 group_dict->Set("connect_jobs", connect_jobs_list); | 631 group_dict->Set("connect_jobs", connect_jobs_list); | 
| 637 | 632 | 
| 638 group_dict->SetBoolean("is_stalled", group->CanUseAdditionalSocketSlot( | 633 group_dict->SetBoolean("is_stalled", group->CanUseAdditionalSocketSlot( | 
| 639 max_sockets_per_group_)); | 634 max_sockets_per_group_)); | 
| 640 group_dict->SetBoolean("backup_job_timer_is_running", | 635 group_dict->SetBoolean("backup_job_timer_is_running", | 
| 641 group->BackupJobTimerIsRunning()); | 636 group->BackupJobTimerIsRunning()); | 
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1185 --unassigned_job_count_; | 1180 --unassigned_job_count_; | 
| 1186 return true; | 1181 return true; | 
| 1187 } | 1182 } | 
| 1188 | 1183 | 
| 1189 void ClientSocketPoolBaseHelper::Group::AddJob(scoped_ptr<ConnectJob> job, | 1184 void ClientSocketPoolBaseHelper::Group::AddJob(scoped_ptr<ConnectJob> job, | 
| 1190 bool is_preconnect) { | 1185 bool is_preconnect) { | 
| 1191 SanityCheck(); | 1186 SanityCheck(); | 
| 1192 | 1187 | 
| 1193 if (is_preconnect) | 1188 if (is_preconnect) | 
| 1194 ++unassigned_job_count_; | 1189 ++unassigned_job_count_; | 
| 1195 jobs_.insert(job.release()); | 1190 jobs_.push_back(job.release()); | 
| 1196 } | 1191 } | 
| 1197 | 1192 | 
| 1198 void ClientSocketPoolBaseHelper::Group::RemoveJob(ConnectJob* job) { | 1193 void ClientSocketPoolBaseHelper::Group::RemoveJob(ConnectJob* job) { | 
| 1199 scoped_ptr<ConnectJob> owned_job(job); | 1194 scoped_ptr<ConnectJob> owned_job(job); | 
| 1200 SanityCheck(); | 1195 SanityCheck(); | 
| 1201 | 1196 | 
| 1202 std::set<ConnectJob*>::iterator it = jobs_.find(job); | 1197 jobs_.remove(job); | 
| 
 
mmenke
2015/04/20 14:49:16
Suggest:
// |job| should appear once and only onc
 
haavardm
2015/04/21 13:28:36
Done. Lists doesn't have the find operation though
 
 | |
| 1203 if (it != jobs_.end()) { | |
| 1204 jobs_.erase(it); | |
| 1205 } else { | |
| 1206 NOTREACHED(); | |
| 1207 } | |
| 1208 size_t job_count = jobs_.size(); | 1198 size_t job_count = jobs_.size(); | 
| 1209 if (job_count < unassigned_job_count_) | 1199 if (job_count < unassigned_job_count_) | 
| 1210 unassigned_job_count_ = job_count; | 1200 unassigned_job_count_ = job_count; | 
| 1211 | 1201 | 
| 1212 // If we've got no more jobs for this group, then we no longer need a | 1202 // If we've got no more jobs for this group, then we no longer need a | 
| 1213 // backup job either. | 1203 // backup job either. | 
| 1214 if (jobs_.empty()) | 1204 if (jobs_.empty()) | 
| 1215 backup_job_timer_.Stop(); | 1205 backup_job_timer_.Stop(); | 
| 1216 } | 1206 } | 
| 1217 | 1207 | 
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1328 pending_requests_.Erase(pointer); | 1318 pending_requests_.Erase(pointer); | 
| 1329 // If there are no more requests, kill the backup timer. | 1319 // If there are no more requests, kill the backup timer. | 
| 1330 if (pending_requests_.empty()) | 1320 if (pending_requests_.empty()) | 
| 1331 backup_job_timer_.Stop(); | 1321 backup_job_timer_.Stop(); | 
| 1332 return request.Pass(); | 1322 return request.Pass(); | 
| 1333 } | 1323 } | 
| 1334 | 1324 | 
| 1335 } // namespace internal | 1325 } // namespace internal | 
| 1336 | 1326 | 
| 1337 } // namespace net | 1327 } // namespace net | 
| OLD | NEW |