| 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 <algorithm> |
| 8 |
| 7 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 8 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 11 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 12 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 13 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 14 #include "base/values.h" | 16 #include "base/values.h" |
| 15 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 16 #include "net/log/net_log.h" | 18 #include "net/log/net_log.h" |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 if (group_it == group_map_.end()) { | 567 if (group_it == group_map_.end()) { |
| 566 // TODO(mmenke): This is actually reached in the wild, for unknown reasons. | 568 // 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, | 569 // Would be great to understand why, and if it's a bug, fix it. If not, |
| 568 // should have a test for that case. | 570 // should have a test for that case. |
| 569 NOTREACHED(); | 571 NOTREACHED(); |
| 570 return LOAD_STATE_IDLE; | 572 return LOAD_STATE_IDLE; |
| 571 } | 573 } |
| 572 | 574 |
| 573 const Group& group = *group_it->second; | 575 const Group& group = *group_it->second; |
| 574 if (group.HasConnectJobForHandle(handle)) { | 576 if (group.HasConnectJobForHandle(handle)) { |
| 575 // Just return the state of the farthest along ConnectJob for the first | 577 // Just return the state of the oldest ConnectJob. |
| 576 // group.jobs().size() pending requests. | 578 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 } | 579 } |
| 583 | 580 |
| 584 if (group.CanUseAdditionalSocketSlot(max_sockets_per_group_)) | 581 if (group.CanUseAdditionalSocketSlot(max_sockets_per_group_)) |
| 585 return LOAD_STATE_WAITING_FOR_STALLED_SOCKET_POOL; | 582 return LOAD_STATE_WAITING_FOR_STALLED_SOCKET_POOL; |
| 586 return LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET; | 583 return LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET; |
| 587 } | 584 } |
| 588 | 585 |
| 589 base::DictionaryValue* ClientSocketPoolBaseHelper::GetInfoAsValue( | 586 base::DictionaryValue* ClientSocketPoolBaseHelper::GetInfoAsValue( |
| 590 const std::string& name, const std::string& type) const { | 587 const std::string& name, const std::string& type) const { |
| 591 base::DictionaryValue* dict = new base::DictionaryValue(); | 588 base::DictionaryValue* dict = new base::DictionaryValue(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 621 std::list<IdleSocket>::const_iterator idle_socket; | 618 std::list<IdleSocket>::const_iterator idle_socket; |
| 622 for (idle_socket = group->idle_sockets().begin(); | 619 for (idle_socket = group->idle_sockets().begin(); |
| 623 idle_socket != group->idle_sockets().end(); | 620 idle_socket != group->idle_sockets().end(); |
| 624 idle_socket++) { | 621 idle_socket++) { |
| 625 int source_id = idle_socket->socket->NetLog().source().id; | 622 int source_id = idle_socket->socket->NetLog().source().id; |
| 626 idle_socket_list->Append(new base::FundamentalValue(source_id)); | 623 idle_socket_list->Append(new base::FundamentalValue(source_id)); |
| 627 } | 624 } |
| 628 group_dict->Set("idle_sockets", idle_socket_list); | 625 group_dict->Set("idle_sockets", idle_socket_list); |
| 629 | 626 |
| 630 base::ListValue* connect_jobs_list = new base::ListValue(); | 627 base::ListValue* connect_jobs_list = new base::ListValue(); |
| 631 std::set<ConnectJob*>::const_iterator job = group->jobs().begin(); | 628 std::list<ConnectJob*>::const_iterator job = group->jobs().begin(); |
| 632 for (job = group->jobs().begin(); job != group->jobs().end(); job++) { | 629 for (job = group->jobs().begin(); job != group->jobs().end(); job++) { |
| 633 int source_id = (*job)->net_log().source().id; | 630 int source_id = (*job)->net_log().source().id; |
| 634 connect_jobs_list->Append(new base::FundamentalValue(source_id)); | 631 connect_jobs_list->Append(new base::FundamentalValue(source_id)); |
| 635 } | 632 } |
| 636 group_dict->Set("connect_jobs", connect_jobs_list); | 633 group_dict->Set("connect_jobs", connect_jobs_list); |
| 637 | 634 |
| 638 group_dict->SetBoolean("is_stalled", group->CanUseAdditionalSocketSlot( | 635 group_dict->SetBoolean("is_stalled", group->CanUseAdditionalSocketSlot( |
| 639 max_sockets_per_group_)); | 636 max_sockets_per_group_)); |
| 640 group_dict->SetBoolean("backup_job_timer_is_running", | 637 group_dict->SetBoolean("backup_job_timer_is_running", |
| 641 group->BackupJobTimerIsRunning()); | 638 group->BackupJobTimerIsRunning()); |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 --unassigned_job_count_; | 1182 --unassigned_job_count_; |
| 1186 return true; | 1183 return true; |
| 1187 } | 1184 } |
| 1188 | 1185 |
| 1189 void ClientSocketPoolBaseHelper::Group::AddJob(scoped_ptr<ConnectJob> job, | 1186 void ClientSocketPoolBaseHelper::Group::AddJob(scoped_ptr<ConnectJob> job, |
| 1190 bool is_preconnect) { | 1187 bool is_preconnect) { |
| 1191 SanityCheck(); | 1188 SanityCheck(); |
| 1192 | 1189 |
| 1193 if (is_preconnect) | 1190 if (is_preconnect) |
| 1194 ++unassigned_job_count_; | 1191 ++unassigned_job_count_; |
| 1195 jobs_.insert(job.release()); | 1192 jobs_.push_back(job.release()); |
| 1196 } | 1193 } |
| 1197 | 1194 |
| 1198 void ClientSocketPoolBaseHelper::Group::RemoveJob(ConnectJob* job) { | 1195 void ClientSocketPoolBaseHelper::Group::RemoveJob(ConnectJob* job) { |
| 1199 scoped_ptr<ConnectJob> owned_job(job); | 1196 scoped_ptr<ConnectJob> owned_job(job); |
| 1200 SanityCheck(); | 1197 SanityCheck(); |
| 1201 | 1198 |
| 1202 std::set<ConnectJob*>::iterator it = jobs_.find(job); | 1199 // Check that |job| is in the list. |
| 1203 if (it != jobs_.end()) { | 1200 DCHECK_EQ(*std::find(jobs_.begin(), jobs_.end(), job), job); |
| 1204 jobs_.erase(it); | 1201 jobs_.remove(job); |
| 1205 } else { | |
| 1206 NOTREACHED(); | |
| 1207 } | |
| 1208 size_t job_count = jobs_.size(); | 1202 size_t job_count = jobs_.size(); |
| 1209 if (job_count < unassigned_job_count_) | 1203 if (job_count < unassigned_job_count_) |
| 1210 unassigned_job_count_ = job_count; | 1204 unassigned_job_count_ = job_count; |
| 1211 | 1205 |
| 1212 // If we've got no more jobs for this group, then we no longer need a | 1206 // If we've got no more jobs for this group, then we no longer need a |
| 1213 // backup job either. | 1207 // backup job either. |
| 1214 if (jobs_.empty()) | 1208 if (jobs_.empty()) |
| 1215 backup_job_timer_.Stop(); | 1209 backup_job_timer_.Stop(); |
| 1216 } | 1210 } |
| 1217 | 1211 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 pending_requests_.Erase(pointer); | 1322 pending_requests_.Erase(pointer); |
| 1329 // If there are no more requests, kill the backup timer. | 1323 // If there are no more requests, kill the backup timer. |
| 1330 if (pending_requests_.empty()) | 1324 if (pending_requests_.empty()) |
| 1331 backup_job_timer_.Stop(); | 1325 backup_job_timer_.Stop(); |
| 1332 return request.Pass(); | 1326 return request.Pass(); |
| 1333 } | 1327 } |
| 1334 | 1328 |
| 1335 } // namespace internal | 1329 } // namespace internal |
| 1336 | 1330 |
| 1337 } // namespace net | 1331 } // namespace net |
| OLD | NEW |