OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 291 |
292 // NetworkChangeNotifier::Observer methods: | 292 // NetworkChangeNotifier::Observer methods: |
293 virtual void OnIPAddressChanged(); | 293 virtual void OnIPAddressChanged(); |
294 | 294 |
295 private: | 295 private: |
296 friend class base::RefCounted<ClientSocketPoolBaseHelper>; | 296 friend class base::RefCounted<ClientSocketPoolBaseHelper>; |
297 | 297 |
298 // Entry for a persistent socket which became idle at time |start_time|. | 298 // Entry for a persistent socket which became idle at time |start_time|. |
299 struct IdleSocket { | 299 struct IdleSocket { |
300 IdleSocket() : socket(NULL) {} | 300 IdleSocket() : socket(NULL) {} |
301 ClientSocket* socket; | |
302 base::TimeTicks start_time; | |
303 | 301 |
304 // An idle socket should be removed if it can't be reused, or has been idle | 302 // An idle socket should be removed if it can't be reused, or has been idle |
305 // for too long. |now| is the current time value (TimeTicks::Now()). | 303 // for too long. |now| is the current time value (TimeTicks::Now()). |
306 // |timeout| is the length of time to wait before timing out an idle socket. | 304 // |timeout| is the length of time to wait before timing out an idle socket. |
307 // | 305 // |
308 // An idle socket can't be reused if it is disconnected or has received | 306 // An idle socket can't be reused if it is disconnected or has received |
309 // data unexpectedly (hence no longer idle). The unread data would be | 307 // data unexpectedly (hence no longer idle). The unread data would be |
310 // mistaken for the beginning of the next response if we were to reuse the | 308 // mistaken for the beginning of the next response if we were to reuse the |
311 // socket for a new request. | 309 // socket for a new request. |
312 bool ShouldCleanup(base::TimeTicks now, base::TimeDelta timeout) const; | 310 bool ShouldCleanup(base::TimeTicks now, base::TimeDelta timeout) const; |
| 311 |
| 312 ClientSocket* socket; |
| 313 base::TimeTicks start_time; |
313 }; | 314 }; |
314 | 315 |
315 typedef std::deque<const Request* > RequestQueue; | 316 typedef std::deque<const Request* > RequestQueue; |
316 typedef std::map<const ClientSocketHandle*, const Request*> RequestMap; | 317 typedef std::map<const ClientSocketHandle*, const Request*> RequestMap; |
317 | 318 |
318 // A Group is allocated per group_name when there are idle sockets or pending | 319 // A Group is allocated per group_name when there are idle sockets or pending |
319 // requests. Otherwise, the Group object is removed from the map. | 320 // requests. Otherwise, the Group object is removed from the map. |
320 // |active_socket_count| tracks the number of sockets held by clients. | 321 // |active_socket_count| tracks the number of sockets held by clients. |
321 class Group { | 322 class Group { |
322 public: | 323 public: |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 // Histograms for the pool | 737 // Histograms for the pool |
737 ClientSocketPoolHistograms* const histograms_; | 738 ClientSocketPoolHistograms* const histograms_; |
738 internal::ClientSocketPoolBaseHelper helper_; | 739 internal::ClientSocketPoolBaseHelper helper_; |
739 | 740 |
740 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); | 741 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); |
741 }; | 742 }; |
742 | 743 |
743 } // namespace net | 744 } // namespace net |
744 | 745 |
745 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 746 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
OLD | NEW |