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 20 matching lines...) Expand all Loading... |
31 | 31 |
32 #include "base/basictypes.h" | 32 #include "base/basictypes.h" |
33 #include "base/memory/ref_counted.h" | 33 #include "base/memory/ref_counted.h" |
34 #include "base/memory/scoped_ptr.h" | 34 #include "base/memory/scoped_ptr.h" |
35 #include "base/memory/weak_ptr.h" | 35 #include "base/memory/weak_ptr.h" |
36 #include "base/time.h" | 36 #include "base/time.h" |
37 #include "base/timer.h" | 37 #include "base/timer.h" |
38 #include "net/base/address_list.h" | 38 #include "net/base/address_list.h" |
39 #include "net/base/completion_callback.h" | 39 #include "net/base/completion_callback.h" |
40 #include "net/base/load_states.h" | 40 #include "net/base/load_states.h" |
| 41 #include "net/base/load_timing_info.h" |
41 #include "net/base/net_errors.h" | 42 #include "net/base/net_errors.h" |
42 #include "net/base/net_export.h" | 43 #include "net/base/net_export.h" |
43 #include "net/base/net_log.h" | 44 #include "net/base/net_log.h" |
44 #include "net/base/network_change_notifier.h" | 45 #include "net/base/network_change_notifier.h" |
45 #include "net/base/request_priority.h" | 46 #include "net/base/request_priority.h" |
46 #include "net/socket/client_socket_pool.h" | 47 #include "net/socket/client_socket_pool.h" |
47 #include "net/socket/stream_socket.h" | 48 #include "net/socket/stream_socket.h" |
48 | 49 |
49 namespace net { | 50 namespace net { |
50 | 51 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // if it succeeded. | 98 // if it succeeded. |
98 int Connect(); | 99 int Connect(); |
99 | 100 |
100 virtual LoadState GetLoadState() const = 0; | 101 virtual LoadState GetLoadState() const = 0; |
101 | 102 |
102 // If Connect returns an error (or OnConnectJobComplete reports an error | 103 // If Connect returns an error (or OnConnectJobComplete reports an error |
103 // result) this method will be called, allowing the pool to add | 104 // result) this method will be called, allowing the pool to add |
104 // additional error state to the ClientSocketHandle (post late-binding). | 105 // additional error state to the ClientSocketHandle (post late-binding). |
105 virtual void GetAdditionalErrorState(ClientSocketHandle* handle) {} | 106 virtual void GetAdditionalErrorState(ClientSocketHandle* handle) {} |
106 | 107 |
| 108 const LoadTimingInfo::ConnectTiming& connect_timing() const { |
| 109 return connect_timing_; |
| 110 } |
| 111 |
107 const BoundNetLog& net_log() const { return net_log_; } | 112 const BoundNetLog& net_log() const { return net_log_; } |
108 | 113 |
109 protected: | 114 protected: |
110 void set_socket(StreamSocket* socket); | 115 void set_socket(StreamSocket* socket); |
111 StreamSocket* socket() { return socket_.get(); } | 116 StreamSocket* socket() { return socket_.get(); } |
112 void NotifyDelegateOfCompletion(int rv); | 117 void NotifyDelegateOfCompletion(int rv); |
113 void ResetTimer(base::TimeDelta remainingTime); | 118 void ResetTimer(base::TimeDelta remainingTime); |
114 | 119 |
| 120 // Connection establishment timing information. |
| 121 LoadTimingInfo::ConnectTiming connect_timing_; |
| 122 |
115 private: | 123 private: |
116 virtual int ConnectInternal() = 0; | 124 virtual int ConnectInternal() = 0; |
117 | 125 |
118 void LogConnectStart(); | 126 void LogConnectStart(); |
119 void LogConnectCompletion(int net_error); | 127 void LogConnectCompletion(int net_error); |
120 | 128 |
121 // Alerts the delegate that the ConnectJob has timed out. | 129 // Alerts the delegate that the ConnectJob has timed out. |
122 void OnTimeout(); | 130 void OnTimeout(); |
123 | 131 |
124 const std::string group_name_; | 132 const std::string group_name_; |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 | 494 |
487 // Tries to see if we can handle any more requests for |group|. | 495 // Tries to see if we can handle any more requests for |group|. |
488 void OnAvailableSocketSlot(const std::string& group_name, Group* group); | 496 void OnAvailableSocketSlot(const std::string& group_name, Group* group); |
489 | 497 |
490 // Process a pending socket request for a group. | 498 // Process a pending socket request for a group. |
491 void ProcessPendingRequest(const std::string& group_name, Group* group); | 499 void ProcessPendingRequest(const std::string& group_name, Group* group); |
492 | 500 |
493 // Assigns |socket| to |handle| and updates |group|'s counters appropriately. | 501 // Assigns |socket| to |handle| and updates |group|'s counters appropriately. |
494 void HandOutSocket(StreamSocket* socket, | 502 void HandOutSocket(StreamSocket* socket, |
495 bool reused, | 503 bool reused, |
| 504 const LoadTimingInfo::ConnectTiming& connect_timing, |
496 ClientSocketHandle* handle, | 505 ClientSocketHandle* handle, |
497 base::TimeDelta time_idle, | 506 base::TimeDelta time_idle, |
498 Group* group, | 507 Group* group, |
499 const BoundNetLog& net_log); | 508 const BoundNetLog& net_log); |
500 | 509 |
501 // Adds |socket| to the list of idle sockets for |group|. | 510 // Adds |socket| to the list of idle sockets for |group|. |
502 void AddIdleSocket(StreamSocket* socket, Group* group); | 511 void AddIdleSocket(StreamSocket* socket, Group* group); |
503 | 512 |
504 // Iterates through |group_map_|, canceling all ConnectJobs and deleting | 513 // Iterates through |group_map_|, canceling all ConnectJobs and deleting |
505 // groups if they are no longer needed. | 514 // groups if they are no longer needed. |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 // Histograms for the pool | 814 // Histograms for the pool |
806 ClientSocketPoolHistograms* const histograms_; | 815 ClientSocketPoolHistograms* const histograms_; |
807 internal::ClientSocketPoolBaseHelper helper_; | 816 internal::ClientSocketPoolBaseHelper helper_; |
808 | 817 |
809 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); | 818 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); |
810 }; | 819 }; |
811 | 820 |
812 } // namespace net | 821 } // namespace net |
813 | 822 |
814 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 823 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
OLD | NEW |