| 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 // A ClientSocketPoolBase is used to restrict the number of sockets open at | 5 // A ClientSocketPoolBase is used to restrict the number of sockets open at |
| 6 // a time. It also maintains a list of idle persistent sockets for reuse. | 6 // a time. It also maintains a list of idle persistent sockets for reuse. |
| 7 // Subclasses of ClientSocketPool should compose ClientSocketPoolBase to handle | 7 // Subclasses of ClientSocketPool should compose ClientSocketPoolBase to handle |
| 8 // the core logic of (1) restricting the number of active (connected or | 8 // the core logic of (1) restricting the number of active (connected or |
| 9 // connecting) sockets per "group" (generally speaking, the hostname), (2) | 9 // connecting) sockets per "group" (generally speaking, the hostname), (2) |
| 10 // maintaining a per-group list of idle, persistent sockets for reuse, and (3) | 10 // maintaining a per-group list of idle, persistent sockets for reuse, and (3) |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 | 376 |
| 377 bool HasAvailableSocketSlot(int max_sockets_per_group) const { | 377 bool HasAvailableSocketSlot(int max_sockets_per_group) const { |
| 378 return NumActiveSocketSlots() < max_sockets_per_group; | 378 return NumActiveSocketSlots() < max_sockets_per_group; |
| 379 } | 379 } |
| 380 | 380 |
| 381 int NumActiveSocketSlots() const { | 381 int NumActiveSocketSlots() const { |
| 382 return active_socket_count_ + static_cast<int>(jobs_.size()) + | 382 return active_socket_count_ + static_cast<int>(jobs_.size()) + |
| 383 static_cast<int>(idle_sockets_.size()); | 383 static_cast<int>(idle_sockets_.size()); |
| 384 } | 384 } |
| 385 | 385 |
| 386 bool IsStalledOnPoolMaxSockets(int max_sockets_per_group) const { | 386 // Returns true if the group could make use of an additional socket slot, if |
| 387 // it were given one. |
| 388 bool CanUseAdditionalSocketSlot(int max_sockets_per_group) const { |
| 387 return HasAvailableSocketSlot(max_sockets_per_group) && | 389 return HasAvailableSocketSlot(max_sockets_per_group) && |
| 388 pending_requests_.size() > jobs_.size(); | 390 pending_requests_.size() > jobs_.size(); |
| 389 } | 391 } |
| 390 | 392 |
| 391 // Returns the priority of the top of the pending request queue | 393 // Returns the priority of the top of the pending request queue |
| 392 // (which may be less than the maximum priority over the entire | 394 // (which may be less than the maximum priority over the entire |
| 393 // queue, due to how we prioritize requests with |ignore_limits| | 395 // queue, due to how we prioritize requests with |ignore_limits| |
| 394 // set over others). | 396 // set over others). |
| 395 RequestPriority TopPendingPriority() const { | 397 RequestPriority TopPendingPriority() const { |
| 396 // NOTE: FirstMax().value()->priority() is not the same as | 398 // NOTE: FirstMax().value()->priority() is not the same as |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 // Histograms for the pool | 871 // Histograms for the pool |
| 870 ClientSocketPoolHistograms* const histograms_; | 872 ClientSocketPoolHistograms* const histograms_; |
| 871 internal::ClientSocketPoolBaseHelper helper_; | 873 internal::ClientSocketPoolBaseHelper helper_; |
| 872 | 874 |
| 873 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); | 875 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); |
| 874 }; | 876 }; |
| 875 | 877 |
| 876 } // namespace net | 878 } // namespace net |
| 877 | 879 |
| 878 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 880 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
| OLD | NEW |