| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 ConnectJob* job = connect_job.release(); | 139 ConnectJob* job = connect_job.release(); |
| 140 if (g_late_binding) { | 140 if (g_late_binding) { |
| 141 CHECK(!ContainsKey(connect_job_map_, handle)); | 141 CHECK(!ContainsKey(connect_job_map_, handle)); |
| 142 InsertRequestIntoQueue(r, &group.pending_requests); | 142 InsertRequestIntoQueue(r, &group.pending_requests); |
| 143 } else { | 143 } else { |
| 144 group.connecting_requests[handle] = r; | 144 group.connecting_requests[handle] = r; |
| 145 CHECK(!ContainsKey(connect_job_map_, handle)); | 145 CHECK(!ContainsKey(connect_job_map_, handle)); |
| 146 connect_job_map_[handle] = job; | 146 connect_job_map_[handle] = job; |
| 147 } | 147 } |
| 148 group.jobs.insert(job); | 148 group.jobs.insert(job); |
| 149 } else { | 149 } else if (group.IsEmpty()) { |
| 150 if (group.IsEmpty()) | 150 group_map_.erase(group_name); |
| 151 group_map_.erase(group_name); | |
| 152 } | 151 } |
| 153 | 152 |
| 154 return rv; | 153 return rv; |
| 155 } | 154 } |
| 156 | 155 |
| 157 void ClientSocketPoolBase::CancelRequest(const std::string& group_name, | 156 void ClientSocketPoolBase::CancelRequest(const std::string& group_name, |
| 158 const ClientSocketHandle* handle) { | 157 const ClientSocketHandle* handle) { |
| 159 CHECK(ContainsKey(group_map_, group_name)); | 158 CHECK(ContainsKey(group_map_, group_name)); |
| 160 | 159 |
| 161 Group& group = group_map_[group_name]; | 160 Group& group = group_map_[group_name]; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 delete j->socket; | 273 delete j->socket; |
| 275 j = group.idle_sockets.erase(j); | 274 j = group.idle_sockets.erase(j); |
| 276 DecrementIdleCount(); | 275 DecrementIdleCount(); |
| 277 } else { | 276 } else { |
| 278 ++j; | 277 ++j; |
| 279 } | 278 } |
| 280 } | 279 } |
| 281 | 280 |
| 282 // Delete group if no longer needed. | 281 // Delete group if no longer needed. |
| 283 if (group.IsEmpty()) { | 282 if (group.IsEmpty()) { |
| 284 CHECK(group.pending_requests.empty()); | |
| 285 group_map_.erase(i++); | 283 group_map_.erase(i++); |
| 286 } else { | 284 } else { |
| 287 ++i; | 285 ++i; |
| 288 } | 286 } |
| 289 } | 287 } |
| 290 } | 288 } |
| 291 | 289 |
| 292 void ClientSocketPoolBase::IncrementIdleCount() { | 290 void ClientSocketPoolBase::IncrementIdleCount() { |
| 293 if (++idle_socket_count_ == 1) | 291 if (++idle_socket_count_ == 1) |
| 294 timer_.Start(TimeDelta::FromSeconds(kCleanupInterval), this, | 292 timer_.Start(TimeDelta::FromSeconds(kCleanupInterval), this, |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 IncrementIdleCount(); | 512 IncrementIdleCount(); |
| 515 } | 513 } |
| 516 | 514 |
| 517 void ClientSocketPoolBase::CancelAllConnectJobs() { | 515 void ClientSocketPoolBase::CancelAllConnectJobs() { |
| 518 for (GroupMap::iterator i = group_map_.begin(); i != group_map_.end();) { | 516 for (GroupMap::iterator i = group_map_.begin(); i != group_map_.end();) { |
| 519 Group& group = i->second; | 517 Group& group = i->second; |
| 520 STLDeleteElements(&group.jobs); | 518 STLDeleteElements(&group.jobs); |
| 521 | 519 |
| 522 // Delete group if no longer needed. | 520 // Delete group if no longer needed. |
| 523 if (group.IsEmpty()) { | 521 if (group.IsEmpty()) { |
| 524 CHECK(group.pending_requests.empty()); | |
| 525 group_map_.erase(i++); | 522 group_map_.erase(i++); |
| 526 } else { | 523 } else { |
| 527 ++i; | 524 ++i; |
| 528 } | 525 } |
| 529 } | 526 } |
| 530 } | 527 } |
| 531 | 528 |
| 532 bool ClientSocketPoolBase::ReachedMaxSocketsLimit() const { | 529 bool ClientSocketPoolBase::ReachedMaxSocketsLimit() const { |
| 533 // Each connecting socket will eventually connect and be handed out. | 530 // Each connecting socket will eventually connect and be handed out. |
| 534 int total = handed_out_socket_count_ + connecting_socket_count_; | 531 int total = handed_out_socket_count_ + connecting_socket_count_; |
| 535 DCHECK_LE(total, max_sockets_); | 532 DCHECK_LE(total, max_sockets_); |
| 536 return total == max_sockets_; | 533 return total == max_sockets_; |
| 537 } | 534 } |
| 538 | 535 |
| 539 } // namespace net | 536 } // namespace net |
| OLD | NEW |