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 26 matching lines...) Expand all Loading... | |
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/net_errors.h" | 41 #include "net/base/net_errors.h" |
42 #include "net/base/net_export.h" | 42 #include "net/base/net_export.h" |
43 #include "net/base/net_log.h" | 43 #include "net/base/net_log.h" |
44 #include "net/base/network_change_notifier.h" | 44 #include "net/base/network_change_notifier.h" |
45 #include "net/base/request_priority.h" | 45 #include "net/base/request_priority.h" |
46 #include "net/socket/client_socket_pool.h" | 46 #include "net/socket/client_socket_pool.h" |
47 #include "net/socket/connect_timing.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 |
51 class ClientSocketHandle; | 52 class ClientSocketHandle; |
52 | 53 |
53 // Returns the client socket reuse policy. | 54 // Returns the client socket reuse policy. |
54 NET_EXPORT_PRIVATE int GetSocketReusePolicy(); | 55 NET_EXPORT_PRIVATE int GetSocketReusePolicy(); |
55 | 56 |
56 // Sets the client socket reuse policy. | 57 // Sets the client socket reuse policy. |
(...skipping 40 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 ConnectTiming& connect_timing() { return connect_timing_; } | |
eroman
2012/12/14 04:08:35
Please make it return a const-reference instead. I
mmenke
2012/12/14 13:36:12
Done.
| |
109 | |
107 const BoundNetLog& net_log() const { return net_log_; } | 110 const BoundNetLog& net_log() const { return net_log_; } |
108 | 111 |
109 protected: | 112 protected: |
110 void set_socket(StreamSocket* socket); | 113 void set_socket(StreamSocket* socket); |
111 StreamSocket* socket() { return socket_.get(); } | 114 StreamSocket* socket() { return socket_.get(); } |
112 void NotifyDelegateOfCompletion(int rv); | 115 void NotifyDelegateOfCompletion(int rv); |
113 void ResetTimer(base::TimeDelta remainingTime); | 116 void ResetTimer(base::TimeDelta remainingTime); |
114 | 117 |
115 private: | 118 private: |
116 virtual int ConnectInternal() = 0; | 119 virtual int ConnectInternal() = 0; |
117 | 120 |
118 void LogConnectStart(); | 121 void LogConnectStart(); |
119 void LogConnectCompletion(int net_error); | 122 void LogConnectCompletion(int net_error); |
120 | 123 |
121 // Alerts the delegate that the ConnectJob has timed out. | 124 // Alerts the delegate that the ConnectJob has timed out. |
122 void OnTimeout(); | 125 void OnTimeout(); |
123 | 126 |
124 const std::string group_name_; | 127 const std::string group_name_; |
125 const base::TimeDelta timeout_duration_; | 128 const base::TimeDelta timeout_duration_; |
126 // Timer to abort jobs that take too long. | 129 // Timer to abort jobs that take too long. |
127 base::OneShotTimer<ConnectJob> timer_; | 130 base::OneShotTimer<ConnectJob> timer_; |
128 Delegate* delegate_; | 131 Delegate* delegate_; |
129 scoped_ptr<StreamSocket> socket_; | 132 scoped_ptr<StreamSocket> socket_; |
130 BoundNetLog net_log_; | 133 BoundNetLog net_log_; |
131 // A ConnectJob is idle until Connect() has been called. | 134 // A ConnectJob is idle until Connect() has been called. |
132 bool idle_; | 135 bool idle_; |
133 | 136 |
137 // Connection establishment timing information. | |
138 ConnectTiming connect_timing_; | |
139 | |
134 DISALLOW_COPY_AND_ASSIGN(ConnectJob); | 140 DISALLOW_COPY_AND_ASSIGN(ConnectJob); |
135 }; | 141 }; |
136 | 142 |
137 namespace internal { | 143 namespace internal { |
138 | 144 |
139 // ClientSocketPoolBaseHelper is an internal class that implements almost all | 145 // ClientSocketPoolBaseHelper is an internal class that implements almost all |
140 // the functionality from ClientSocketPoolBase without using templates. | 146 // the functionality from ClientSocketPoolBase without using templates. |
141 // ClientSocketPoolBase adds templated definitions built on top of | 147 // ClientSocketPoolBase adds templated definitions built on top of |
142 // ClientSocketPoolBaseHelper. This class is not for external use, please use | 148 // ClientSocketPoolBaseHelper. This class is not for external use, please use |
143 // ClientSocketPoolBase instead. | 149 // ClientSocketPoolBase instead. |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 | 492 |
487 // Tries to see if we can handle any more requests for |group|. | 493 // Tries to see if we can handle any more requests for |group|. |
488 void OnAvailableSocketSlot(const std::string& group_name, Group* group); | 494 void OnAvailableSocketSlot(const std::string& group_name, Group* group); |
489 | 495 |
490 // Process a pending socket request for a group. | 496 // Process a pending socket request for a group. |
491 void ProcessPendingRequest(const std::string& group_name, Group* group); | 497 void ProcessPendingRequest(const std::string& group_name, Group* group); |
492 | 498 |
493 // Assigns |socket| to |handle| and updates |group|'s counters appropriately. | 499 // Assigns |socket| to |handle| and updates |group|'s counters appropriately. |
494 void HandOutSocket(StreamSocket* socket, | 500 void HandOutSocket(StreamSocket* socket, |
495 bool reused, | 501 bool reused, |
502 const ConnectTiming& connect_timing, | |
496 ClientSocketHandle* handle, | 503 ClientSocketHandle* handle, |
497 base::TimeDelta time_idle, | 504 base::TimeDelta time_idle, |
498 Group* group, | 505 Group* group, |
499 const BoundNetLog& net_log); | 506 const BoundNetLog& net_log); |
500 | 507 |
501 // Adds |socket| to the list of idle sockets for |group|. | 508 // Adds |socket| to the list of idle sockets for |group|. |
502 void AddIdleSocket(StreamSocket* socket, Group* group); | 509 void AddIdleSocket(StreamSocket* socket, Group* group); |
503 | 510 |
504 // Iterates through |group_map_|, canceling all ConnectJobs and deleting | 511 // Iterates through |group_map_|, canceling all ConnectJobs and deleting |
505 // groups if they are no longer needed. | 512 // 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 | 812 // Histograms for the pool |
806 ClientSocketPoolHistograms* const histograms_; | 813 ClientSocketPoolHistograms* const histograms_; |
807 internal::ClientSocketPoolBaseHelper helper_; | 814 internal::ClientSocketPoolBaseHelper helper_; |
808 | 815 |
809 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); | 816 DISALLOW_COPY_AND_ASSIGN(ClientSocketPoolBase); |
810 }; | 817 }; |
811 | 818 |
812 } // namespace net | 819 } // namespace net |
813 | 820 |
814 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ | 821 #endif // NET_SOCKET_CLIENT_SOCKET_POOL_BASE_H_ |
OLD | NEW |