| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 void LogConnectCompletion(int net_error); | 129 void LogConnectCompletion(int net_error); |
| 130 | 130 |
| 131 // Alerts the delegate that the ConnectJob has timed out. | 131 // Alerts the delegate that the ConnectJob has timed out. |
| 132 void OnTimeout(); | 132 void OnTimeout(); |
| 133 | 133 |
| 134 const std::string group_name_; | 134 const std::string group_name_; |
| 135 const base::TimeDelta timeout_duration_; | 135 const base::TimeDelta timeout_duration_; |
| 136 // TODO(akalin): Support reprioritization. | 136 // TODO(akalin): Support reprioritization. |
| 137 const RequestPriority priority_; | 137 const RequestPriority priority_; |
| 138 // Timer to abort jobs that take too long. | 138 // Timer to abort jobs that take too long. |
| 139 base::OneShotTimer<ConnectJob> timer_; | 139 base::OneShotTimer timer_; |
| 140 Delegate* delegate_; | 140 Delegate* delegate_; |
| 141 scoped_ptr<StreamSocket> socket_; | 141 scoped_ptr<StreamSocket> socket_; |
| 142 BoundNetLog net_log_; | 142 BoundNetLog net_log_; |
| 143 // A ConnectJob is idle until Connect() has been called. | 143 // A ConnectJob is idle until Connect() has been called. |
| 144 bool idle_; | 144 bool idle_; |
| 145 | 145 |
| 146 DISALLOW_COPY_AND_ASSIGN(ConnectJob); | 146 DISALLOW_COPY_AND_ASSIGN(ConnectJob); |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 namespace internal { | 149 namespace internal { |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 // preconnect and decremented when a preconnect is assigned, or when there | 487 // preconnect and decremented when a preconnect is assigned, or when there |
| 488 // are fewer than |unassigned_job_count_| ConnectJobs. Not incremented | 488 // are fewer than |unassigned_job_count_| ConnectJobs. Not incremented |
| 489 // when a request is cancelled. | 489 // when a request is cancelled. |
| 490 size_t unassigned_job_count_; | 490 size_t unassigned_job_count_; |
| 491 | 491 |
| 492 std::list<IdleSocket> idle_sockets_; | 492 std::list<IdleSocket> idle_sockets_; |
| 493 std::list<ConnectJob*> jobs_; | 493 std::list<ConnectJob*> jobs_; |
| 494 RequestQueue pending_requests_; | 494 RequestQueue pending_requests_; |
| 495 int active_socket_count_; // number of active sockets used by clients | 495 int active_socket_count_; // number of active sockets used by clients |
| 496 // A timer for when to start the backup job. | 496 // A timer for when to start the backup job. |
| 497 base::OneShotTimer<Group> backup_job_timer_; | 497 base::OneShotTimer backup_job_timer_; |
| 498 }; | 498 }; |
| 499 | 499 |
| 500 typedef std::map<std::string, Group*> GroupMap; | 500 typedef std::map<std::string, Group*> GroupMap; |
| 501 | 501 |
| 502 typedef std::set<ConnectJob*> ConnectJobSet; | 502 typedef std::set<ConnectJob*> ConnectJobSet; |
| 503 | 503 |
| 504 struct CallbackResultPair { | 504 struct CallbackResultPair { |
| 505 CallbackResultPair(); | 505 CallbackResultPair(); |
| 506 CallbackResultPair(const CompletionCallback& callback_in, int result_in); | 506 CallbackResultPair(const CompletionCallback& callback_in, int result_in); |
| 507 ~CallbackResultPair(); | 507 ~CallbackResultPair(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 | 608 |
| 609 GroupMap group_map_; | 609 GroupMap group_map_; |
| 610 | 610 |
| 611 // Map of the ClientSocketHandles for which we have a pending Task to invoke a | 611 // Map of the ClientSocketHandles for which we have a pending Task to invoke a |
| 612 // callback. This is necessary since, before we invoke said callback, it's | 612 // callback. This is necessary since, before we invoke said callback, it's |
| 613 // possible that the request is cancelled. | 613 // possible that the request is cancelled. |
| 614 PendingCallbackMap pending_callback_map_; | 614 PendingCallbackMap pending_callback_map_; |
| 615 | 615 |
| 616 // Timer used to periodically prune idle sockets that timed out or can't be | 616 // Timer used to periodically prune idle sockets that timed out or can't be |
| 617 // reused. | 617 // reused. |
| 618 base::RepeatingTimer<ClientSocketPoolBaseHelper> timer_; | 618 base::RepeatingTimer timer_; |
| 619 | 619 |
| 620 // The total number of idle sockets in the system. | 620 // The total number of idle sockets in the system. |
| 621 int idle_socket_count_; | 621 int idle_socket_count_; |
| 622 | 622 |
| 623 // Number of connecting sockets across all groups. | 623 // Number of connecting sockets across all groups. |
| 624 int connecting_socket_count_; | 624 int connecting_socket_count_; |
| 625 | 625 |
| 626 // Number of connected sockets we handed out across all groups. | 626 // Number of connected sockets we handed out across all groups. |
| 627 int handed_out_socket_count_; | 627 int handed_out_socket_count_; |
| 628 | 628 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 }; | 872 }; |
| 873 | 873 |
| 874 internal::ClientSocketPoolBaseHelper helper_; | 874 internal::ClientSocketPoolBaseHelper helper_; |
| 875 | 875 |
| 876 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); | 876 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); |
| 877 }; | 877 }; |
| 878 | 878 |
| 879 } // namespace net | 879 } // namespace net |
| 880 | 880 |
| 881 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 881 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
| OLD | NEW |