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 // 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 private: | 161 private: |
162 DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory); | 162 DISALLOW_COPY_AND_ASSIGN(ConnectJobFactory); |
163 }; | 163 }; |
164 | 164 |
165 ClientSocketPoolBaseHelper(int max_sockets, | 165 ClientSocketPoolBaseHelper(int max_sockets, |
166 int max_sockets_per_group, | 166 int max_sockets_per_group, |
167 base::TimeDelta unused_idle_socket_timeout, | 167 base::TimeDelta unused_idle_socket_timeout, |
168 base::TimeDelta used_idle_socket_timeout, | 168 base::TimeDelta used_idle_socket_timeout, |
169 ConnectJobFactory* connect_job_factory); | 169 ConnectJobFactory* connect_job_factory); |
170 | 170 |
171 ~ClientSocketPoolBaseHelper(); | |
172 | |
173 // See ClientSocketPool::RequestSocket for documentation on this function. | 171 // See ClientSocketPool::RequestSocket for documentation on this function. |
174 // Note that |request| must be heap allocated. If ERR_IO_PENDING is returned, | 172 // Note that |request| must be heap allocated. If ERR_IO_PENDING is returned, |
175 // then ClientSocketPoolBaseHelper takes ownership of |request|. | 173 // then ClientSocketPoolBaseHelper takes ownership of |request|. |
176 int RequestSocket(const std::string& group_name, const Request* request); | 174 int RequestSocket(const std::string& group_name, const Request* request); |
177 | 175 |
178 // See ClientSocketPool::CancelRequest for documentation on this function. | 176 // See ClientSocketPool::CancelRequest for documentation on this function. |
179 void CancelRequest(const std::string& group_name, | 177 void CancelRequest(const std::string& group_name, |
180 const ClientSocketHandle* handle); | 178 const ClientSocketHandle* handle); |
181 | 179 |
182 // See ClientSocketPool::ReleaseSocket for documentation on this function. | 180 // See ClientSocketPool::ReleaseSocket for documentation on this function. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 213 |
216 int NumConnectJobsInGroup(const std::string& group_name) const { | 214 int NumConnectJobsInGroup(const std::string& group_name) const { |
217 return group_map_.find(group_name)->second.jobs.size(); | 215 return group_map_.find(group_name)->second.jobs.size(); |
218 } | 216 } |
219 | 217 |
220 // Closes all idle sockets if |force| is true. Else, only closes idle | 218 // Closes all idle sockets if |force| is true. Else, only closes idle |
221 // sockets that timed out or can't be reused. Made public for testing. | 219 // sockets that timed out or can't be reused. Made public for testing. |
222 void CleanupIdleSockets(bool force); | 220 void CleanupIdleSockets(bool force); |
223 | 221 |
224 private: | 222 private: |
| 223 friend class base::RefCounted<ClientSocketPoolBaseHelper>; |
| 224 |
| 225 ~ClientSocketPoolBaseHelper(); |
| 226 |
225 // Entry for a persistent socket which became idle at time |start_time|. | 227 // Entry for a persistent socket which became idle at time |start_time|. |
226 struct IdleSocket { | 228 struct IdleSocket { |
227 IdleSocket() : socket(NULL), used(false) {} | 229 IdleSocket() : socket(NULL), used(false) {} |
228 ClientSocket* socket; | 230 ClientSocket* socket; |
229 base::TimeTicks start_time; | 231 base::TimeTicks start_time; |
230 bool used; // Indicates whether or not the socket has been used yet. | 232 bool used; // Indicates whether or not the socket has been used yet. |
231 | 233 |
232 // An idle socket should be removed if it can't be reused, or has been idle | 234 // An idle socket should be removed if it can't be reused, or has been idle |
233 // for too long. |now| is the current time value (TimeTicks::Now()). | 235 // for too long. |now| is the current time value (TimeTicks::Now()). |
234 // |timeout| is the length of time to wait before timing out an idle socket. | 236 // |timeout| is the length of time to wait before timing out an idle socket. |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 // decoupled from socket connection jobs. A socket request may initiate a | 557 // decoupled from socket connection jobs. A socket request may initiate a |
556 // socket connection job, but there is no guarantee that that socket | 558 // socket connection job, but there is no guarantee that that socket |
557 // connection will service the request (for example, a released socket may | 559 // connection will service the request (for example, a released socket may |
558 // service the request sooner, or a higher priority request may come in | 560 // service the request sooner, or a higher priority request may come in |
559 // afterward and receive the socket from the job). | 561 // afterward and receive the socket from the job). |
560 void EnableLateBindingOfSockets(bool enabled); | 562 void EnableLateBindingOfSockets(bool enabled); |
561 | 563 |
562 } // namespace net | 564 } // namespace net |
563 | 565 |
564 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 566 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
OLD | NEW |