OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef NET_SOCKET_WEBSOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ | 5 #ifndef NET_SOCKET_WEBSOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ |
6 #define NET_SOCKET_WEBSOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ | 6 #define NET_SOCKET_WEBSOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 RequestPriority priority, | 45 RequestPriority priority, |
46 ClientSocketPool::RespectLimits respect_limits, | 46 ClientSocketPool::RespectLimits respect_limits, |
47 const scoped_refptr<TransportSocketParams>& params, | 47 const scoped_refptr<TransportSocketParams>& params, |
48 base::TimeDelta timeout_duration, | 48 base::TimeDelta timeout_duration, |
49 const CompletionCallback& callback, | 49 const CompletionCallback& callback, |
50 ClientSocketFactory* client_socket_factory, | 50 ClientSocketFactory* client_socket_factory, |
51 HostResolver* host_resolver, | 51 HostResolver* host_resolver, |
52 ClientSocketHandle* handle, | 52 ClientSocketHandle* handle, |
53 Delegate* delegate, | 53 Delegate* delegate, |
54 NetLog* pool_net_log, | 54 NetLog* pool_net_log, |
55 const BoundNetLog& request_net_log); | 55 const NetLogWithSource& request_net_log); |
56 ~WebSocketTransportConnectJob() override; | 56 ~WebSocketTransportConnectJob() override; |
57 | 57 |
58 // Unlike normal socket pools, the WebSocketTransportClientPool uses | 58 // Unlike normal socket pools, the WebSocketTransportClientPool uses |
59 // early-binding of sockets. | 59 // early-binding of sockets. |
60 ClientSocketHandle* handle() const { return handle_; } | 60 ClientSocketHandle* handle() const { return handle_; } |
61 | 61 |
62 // Stash the callback from RequestSocket() here for convenience. | 62 // Stash the callback from RequestSocket() here for convenience. |
63 const CompletionCallback& callback() const { return callback_; } | 63 const CompletionCallback& callback() const { return callback_; } |
64 | 64 |
65 const BoundNetLog& request_net_log() const { return request_net_log_; } | 65 const NetLogWithSource& request_net_log() const { return request_net_log_; } |
66 | 66 |
67 // ConnectJob methods. | 67 // ConnectJob methods. |
68 LoadState GetLoadState() const override; | 68 LoadState GetLoadState() const override; |
69 | 69 |
70 private: | 70 private: |
71 friend class WebSocketTransportConnectSubJob; | 71 friend class WebSocketTransportConnectSubJob; |
72 friend class WebSocketEndpointLockManager; | 72 friend class WebSocketEndpointLockManager; |
73 | 73 |
74 enum State { | 74 enum State { |
75 STATE_RESOLVE_HOST, | 75 STATE_RESOLVE_HOST, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // in parallel. If the list of IPv6 addresses is non-empty, then the IPv6 jobs | 114 // in parallel. If the list of IPv6 addresses is non-empty, then the IPv6 jobs |
115 // go first, followed after |kIPv6FallbackTimerInMs| by the IPv4 | 115 // go first, followed after |kIPv6FallbackTimerInMs| by the IPv4 |
116 // addresses. First sub-job to establish a connection wins. | 116 // addresses. First sub-job to establish a connection wins. |
117 std::unique_ptr<WebSocketTransportConnectSubJob> ipv4_job_; | 117 std::unique_ptr<WebSocketTransportConnectSubJob> ipv4_job_; |
118 std::unique_ptr<WebSocketTransportConnectSubJob> ipv6_job_; | 118 std::unique_ptr<WebSocketTransportConnectSubJob> ipv6_job_; |
119 | 119 |
120 base::OneShotTimer fallback_timer_; | 120 base::OneShotTimer fallback_timer_; |
121 TransportConnectJob::RaceResult race_result_; | 121 TransportConnectJob::RaceResult race_result_; |
122 ClientSocketHandle* const handle_; | 122 ClientSocketHandle* const handle_; |
123 CompletionCallback callback_; | 123 CompletionCallback callback_; |
124 BoundNetLog request_net_log_; | 124 NetLogWithSource request_net_log_; |
125 | 125 |
126 bool had_ipv4_; | 126 bool had_ipv4_; |
127 bool had_ipv6_; | 127 bool had_ipv6_; |
128 | 128 |
129 DISALLOW_COPY_AND_ASSIGN(WebSocketTransportConnectJob); | 129 DISALLOW_COPY_AND_ASSIGN(WebSocketTransportConnectJob); |
130 }; | 130 }; |
131 | 131 |
132 class NET_EXPORT_PRIVATE WebSocketTransportClientSocketPool | 132 class NET_EXPORT_PRIVATE WebSocketTransportClientSocketPool |
133 : public TransportClientSocketPool { | 133 : public TransportClientSocketPool { |
134 public: | 134 public: |
(...skipping 12 matching lines...) Expand all Loading... |
147 // returned to ReleaseSocket() in a timely fashion. | 147 // returned to ReleaseSocket() in a timely fashion. |
148 static void UnlockEndpoint(ClientSocketHandle* handle); | 148 static void UnlockEndpoint(ClientSocketHandle* handle); |
149 | 149 |
150 // ClientSocketPool implementation. | 150 // ClientSocketPool implementation. |
151 int RequestSocket(const std::string& group_name, | 151 int RequestSocket(const std::string& group_name, |
152 const void* resolve_info, | 152 const void* resolve_info, |
153 RequestPriority priority, | 153 RequestPriority priority, |
154 RespectLimits respect_limits, | 154 RespectLimits respect_limits, |
155 ClientSocketHandle* handle, | 155 ClientSocketHandle* handle, |
156 const CompletionCallback& callback, | 156 const CompletionCallback& callback, |
157 const BoundNetLog& net_log) override; | 157 const NetLogWithSource& net_log) override; |
158 void RequestSockets(const std::string& group_name, | 158 void RequestSockets(const std::string& group_name, |
159 const void* params, | 159 const void* params, |
160 int num_sockets, | 160 int num_sockets, |
161 const BoundNetLog& net_log) override; | 161 const NetLogWithSource& net_log) override; |
162 void CancelRequest(const std::string& group_name, | 162 void CancelRequest(const std::string& group_name, |
163 ClientSocketHandle* handle) override; | 163 ClientSocketHandle* handle) override; |
164 void ReleaseSocket(const std::string& group_name, | 164 void ReleaseSocket(const std::string& group_name, |
165 std::unique_ptr<StreamSocket> socket, | 165 std::unique_ptr<StreamSocket> socket, |
166 int id) override; | 166 int id) override; |
167 void FlushWithError(int error) override; | 167 void FlushWithError(int error) override; |
168 void CloseIdleSockets() override; | 168 void CloseIdleSockets() override; |
169 int IdleSocketCount() const override; | 169 int IdleSocketCount() const override; |
170 int IdleSocketCountInGroup(const std::string& group_name) const override; | 170 int IdleSocketCountInGroup(const std::string& group_name) const override; |
171 LoadState GetLoadState(const std::string& group_name, | 171 LoadState GetLoadState(const std::string& group_name, |
(...skipping 21 matching lines...) Expand all Loading... |
193 DISALLOW_COPY_AND_ASSIGN(ConnectJobDelegate); | 193 DISALLOW_COPY_AND_ASSIGN(ConnectJobDelegate); |
194 }; | 194 }; |
195 | 195 |
196 // Store the arguments from a call to RequestSocket() that has stalled so we | 196 // Store the arguments from a call to RequestSocket() that has stalled so we |
197 // can replay it when there are available socket slots. | 197 // can replay it when there are available socket slots. |
198 struct StalledRequest { | 198 struct StalledRequest { |
199 StalledRequest(const scoped_refptr<TransportSocketParams>& params, | 199 StalledRequest(const scoped_refptr<TransportSocketParams>& params, |
200 RequestPriority priority, | 200 RequestPriority priority, |
201 ClientSocketHandle* handle, | 201 ClientSocketHandle* handle, |
202 const CompletionCallback& callback, | 202 const CompletionCallback& callback, |
203 const BoundNetLog& net_log); | 203 const NetLogWithSource& net_log); |
204 StalledRequest(const StalledRequest& other); | 204 StalledRequest(const StalledRequest& other); |
205 ~StalledRequest(); | 205 ~StalledRequest(); |
206 const scoped_refptr<TransportSocketParams> params; | 206 const scoped_refptr<TransportSocketParams> params; |
207 const RequestPriority priority; | 207 const RequestPriority priority; |
208 ClientSocketHandle* const handle; | 208 ClientSocketHandle* const handle; |
209 const CompletionCallback callback; | 209 const CompletionCallback callback; |
210 const BoundNetLog net_log; | 210 const NetLogWithSource net_log; |
211 }; | 211 }; |
212 | 212 |
213 friend class ConnectJobDelegate; | 213 friend class ConnectJobDelegate; |
214 | 214 |
215 typedef std::map<const ClientSocketHandle*, WebSocketTransportConnectJob*> | 215 typedef std::map<const ClientSocketHandle*, WebSocketTransportConnectJob*> |
216 PendingConnectsMap; | 216 PendingConnectsMap; |
217 // This is a list so that we can remove requests from the middle, and also | 217 // This is a list so that we can remove requests from the middle, and also |
218 // so that iterators are not invalidated unless the corresponding request is | 218 // so that iterators are not invalidated unless the corresponding request is |
219 // removed. | 219 // removed. |
220 typedef std::list<StalledRequest> StalledRequestQueue; | 220 typedef std::list<StalledRequest> StalledRequestQueue; |
221 typedef std::map<const ClientSocketHandle*, StalledRequestQueue::iterator> | 221 typedef std::map<const ClientSocketHandle*, StalledRequestQueue::iterator> |
222 StalledRequestMap; | 222 StalledRequestMap; |
223 | 223 |
224 // Tries to hand out the socket connected by |job|. |result| must be (async) | 224 // Tries to hand out the socket connected by |job|. |result| must be (async) |
225 // result of WebSocketTransportConnectJob::Connect(). Returns true iff it has | 225 // result of WebSocketTransportConnectJob::Connect(). Returns true iff it has |
226 // handed out a socket. | 226 // handed out a socket. |
227 bool TryHandOutSocket(int result, WebSocketTransportConnectJob* job); | 227 bool TryHandOutSocket(int result, WebSocketTransportConnectJob* job); |
228 void OnConnectJobComplete(int result, WebSocketTransportConnectJob* job); | 228 void OnConnectJobComplete(int result, WebSocketTransportConnectJob* job); |
229 void InvokeUserCallbackLater(ClientSocketHandle* handle, | 229 void InvokeUserCallbackLater(ClientSocketHandle* handle, |
230 const CompletionCallback& callback, | 230 const CompletionCallback& callback, |
231 int rv); | 231 int rv); |
232 void InvokeUserCallback(ClientSocketHandle* handle, | 232 void InvokeUserCallback(ClientSocketHandle* handle, |
233 const CompletionCallback& callback, | 233 const CompletionCallback& callback, |
234 int rv); | 234 int rv); |
235 bool ReachedMaxSocketsLimit() const; | 235 bool ReachedMaxSocketsLimit() const; |
236 void HandOutSocket(std::unique_ptr<StreamSocket> socket, | 236 void HandOutSocket(std::unique_ptr<StreamSocket> socket, |
237 const LoadTimingInfo::ConnectTiming& connect_timing, | 237 const LoadTimingInfo::ConnectTiming& connect_timing, |
238 ClientSocketHandle* handle, | 238 ClientSocketHandle* handle, |
239 const BoundNetLog& net_log); | 239 const NetLogWithSource& net_log); |
240 void AddJob(ClientSocketHandle* handle, | 240 void AddJob(ClientSocketHandle* handle, |
241 std::unique_ptr<WebSocketTransportConnectJob> connect_job); | 241 std::unique_ptr<WebSocketTransportConnectJob> connect_job); |
242 bool DeleteJob(ClientSocketHandle* handle); | 242 bool DeleteJob(ClientSocketHandle* handle); |
243 const WebSocketTransportConnectJob* LookupConnectJob( | 243 const WebSocketTransportConnectJob* LookupConnectJob( |
244 const ClientSocketHandle* handle) const; | 244 const ClientSocketHandle* handle) const; |
245 void ActivateStalledRequest(); | 245 void ActivateStalledRequest(); |
246 bool DeleteStalledRequest(ClientSocketHandle* handle); | 246 bool DeleteStalledRequest(ClientSocketHandle* handle); |
247 | 247 |
248 ConnectJobDelegate connect_job_delegate_; | 248 ConnectJobDelegate connect_job_delegate_; |
249 std::set<const ClientSocketHandle*> pending_callbacks_; | 249 std::set<const ClientSocketHandle*> pending_callbacks_; |
250 PendingConnectsMap pending_connects_; | 250 PendingConnectsMap pending_connects_; |
251 StalledRequestQueue stalled_request_queue_; | 251 StalledRequestQueue stalled_request_queue_; |
252 StalledRequestMap stalled_request_map_; | 252 StalledRequestMap stalled_request_map_; |
253 NetLog* const pool_net_log_; | 253 NetLog* const pool_net_log_; |
254 ClientSocketFactory* const client_socket_factory_; | 254 ClientSocketFactory* const client_socket_factory_; |
255 HostResolver* const host_resolver_; | 255 HostResolver* const host_resolver_; |
256 const int max_sockets_; | 256 const int max_sockets_; |
257 int handed_out_socket_count_; | 257 int handed_out_socket_count_; |
258 bool flushing_; | 258 bool flushing_; |
259 | 259 |
260 base::WeakPtrFactory<WebSocketTransportClientSocketPool> weak_factory_; | 260 base::WeakPtrFactory<WebSocketTransportClientSocketPool> weak_factory_; |
261 | 261 |
262 DISALLOW_COPY_AND_ASSIGN(WebSocketTransportClientSocketPool); | 262 DISALLOW_COPY_AND_ASSIGN(WebSocketTransportClientSocketPool); |
263 }; | 263 }; |
264 | 264 |
265 } // namespace net | 265 } // namespace net |
266 | 266 |
267 #endif // NET_SOCKET_WEBSOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ | 267 #endif // NET_SOCKET_WEBSOCKET_TRANSPORT_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |