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 #ifndef NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ | 5 #ifndef NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ |
6 #define NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ | 6 #define NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 struct SocketAndCallback { | 107 struct SocketAndCallback { |
108 SocketAndCallback(SSLClientSocket* ssl_socket, | 108 SocketAndCallback(SSLClientSocket* ssl_socket, |
109 const base::Closure& job_resumption_callback); | 109 const base::Closure& job_resumption_callback); |
110 ~SocketAndCallback(); | 110 ~SocketAndCallback(); |
111 | 111 |
112 SSLClientSocket* socket; | 112 SSLClientSocket* socket; |
113 base::Closure callback; | 113 base::Closure callback; |
114 }; | 114 }; |
115 | 115 |
116 typedef std::vector<SocketAndCallback> SSLPendingSocketsAndCallbacks; | 116 typedef std::vector<SocketAndCallback> SSLPendingSocketsAndCallbacks; |
117 typedef base::Callback<void()> ConnectionCompleteCallback; | |
Ryan Sleevi
2014/08/14 01:20:20
We have a typedef for this already - base::Closure
mshelley
2014/08/14 20:01:36
Done.
| |
117 | 118 |
118 SSLConnectJobMessenger(); | 119 // |connection_complete_callback| is used to inform the client socket pool |
120 // that a connection monitored by the SSLConnectJobMessenger has completed. | |
121 SSLConnectJobMessenger( | |
122 const ConnectionCompleteCallback& connection_complete_callback); | |
wtc
2014/08/14 00:46:46
DESIGN: instead of an abstract callback function,
Ryan Sleevi
2014/08/14 01:20:20
I recommended against this, to avoid introducing a
mshelley
2014/08/14 20:01:37
So is the benefit of passing in the pointer direct
| |
119 ~SSLConnectJobMessenger(); | 123 ~SSLConnectJobMessenger(); |
120 | 124 |
121 // Removes |socket| from the set of sockets being monitored. This | 125 // Removes |socket| from the set of sockets being monitored. This |
122 // guarantees that |job_resumption_callback| will not be called for | 126 // guarantees that |job_resumption_callback| will not be called for |
123 // the socket. | 127 // the socket. |
124 void RemovePendingSocket(SSLClientSocket* ssl_socket); | 128 void RemovePendingSocket(SSLClientSocket* ssl_socket); |
125 | 129 |
126 // Returns true if |ssl_socket|'s Connect() method should be called. | 130 // Returns true if |ssl_socket|'s Connect() method should be called. |
127 bool CanProceed(SSLClientSocket* ssl_socket); | 131 bool CanProceed(SSLClientSocket* ssl_socket); |
128 | 132 |
(...skipping 15 matching lines...) Expand all Loading... | |
144 | 148 |
145 private: | 149 private: |
146 // Processes pending callbacks when a socket completes its SSL handshake -- | 150 // Processes pending callbacks when a socket completes its SSL handshake -- |
147 // either successfully or unsuccessfully. | 151 // either successfully or unsuccessfully. |
148 void OnSSLHandshakeCompleted(); | 152 void OnSSLHandshakeCompleted(); |
149 | 153 |
150 // Runs all callbacks stored in |pending_sockets_and_callbacks_|. | 154 // Runs all callbacks stored in |pending_sockets_and_callbacks_|. |
151 void RunAllCallbacks( | 155 void RunAllCallbacks( |
152 const SSLPendingSocketsAndCallbacks& pending_socket_and_callbacks); | 156 const SSLPendingSocketsAndCallbacks& pending_socket_and_callbacks); |
153 | 157 |
154 base::WeakPtrFactory<SSLConnectJobMessenger> weak_factory_; | |
155 | |
156 SSLPendingSocketsAndCallbacks pending_sockets_and_callbacks_; | 158 SSLPendingSocketsAndCallbacks pending_sockets_and_callbacks_; |
157 // Note: this field is a vector to allow for future design changes. Currently, | 159 // Note: this field is a vector to allow for future design changes. Currently, |
158 // this vector should only ever have one entry. | 160 // this vector should only ever have one entry. |
159 std::vector<SSLClientSocket*> connecting_sockets_; | 161 std::vector<SSLClientSocket*> connecting_sockets_; |
162 | |
163 ConnectionCompleteCallback connection_complete_callback_; | |
164 | |
165 base::WeakPtrFactory<SSLConnectJobMessenger> weak_factory_; | |
160 }; | 166 }; |
161 | 167 |
162 // SSLConnectJob handles the SSL handshake after setting up the underlying | 168 // SSLConnectJob handles the SSL handshake after setting up the underlying |
163 // connection as specified in the params. | 169 // connection as specified in the params. |
164 class SSLConnectJob : public ConnectJob { | 170 class SSLConnectJob : public ConnectJob { |
165 public: | 171 public: |
172 // Callback to allow the SSLConnectJob to obtain an SSLConnectJobMessenger to | |
173 // coordinate connecting. The SSLConnectJob will supply a unique identifer | |
174 // (ex: the SSL session cache key), with the expectation that the same | |
175 // Messenger | |
176 // will be returned for all such ConnectJobs. | |
wtc
2014/08/14 00:46:46
Please reformat this comment block.
mshelley
2014/08/14 20:01:37
Done.
| |
177 // | |
178 // Note: It will only be called for situations where the SSL session cache | |
179 // does not already have a candidate session to resume. | |
180 typedef base::Callback<SSLConnectJobMessenger*(const std::string&)> | |
181 GetMessengerForUncachedSessionCallback; | |
wtc
2014/08/14 00:46:46
Nit: I would shorten this type to "GetMessengerCal
mshelley
2014/08/14 20:01:37
Done.
| |
182 | |
166 // Note: the SSLConnectJob does not own |messenger| so it must outlive the | 183 // Note: the SSLConnectJob does not own |messenger| so it must outlive the |
167 // job. | 184 // job. |
168 SSLConnectJob(const std::string& group_name, | 185 SSLConnectJob( |
169 RequestPriority priority, | 186 const std::string& group_name, |
170 const scoped_refptr<SSLSocketParams>& params, | 187 RequestPriority priority, |
171 const base::TimeDelta& timeout_duration, | 188 const scoped_refptr<SSLSocketParams>& params, |
172 TransportClientSocketPool* transport_pool, | 189 const base::TimeDelta& timeout_duration, |
173 SOCKSClientSocketPool* socks_pool, | 190 TransportClientSocketPool* transport_pool, |
174 HttpProxyClientSocketPool* http_proxy_pool, | 191 SOCKSClientSocketPool* socks_pool, |
175 ClientSocketFactory* client_socket_factory, | 192 HttpProxyClientSocketPool* http_proxy_pool, |
176 HostResolver* host_resolver, | 193 ClientSocketFactory* client_socket_factory, |
177 const SSLClientSocketContext& context, | 194 HostResolver* host_resolver, |
178 SSLConnectJobMessenger* messenger, | 195 const SSLClientSocketContext& context, |
179 Delegate* delegate, | 196 const GetMessengerForUncachedSessionCallback& uncached_session_callback, |
wtc
2014/08/14 00:46:46
Between the "get messenger" and the "uncached sess
wtc
2014/08/14 00:46:46
DESIGN: I would just pass a SSLClientSocketPool* p
Ryan Sleevi
2014/08/14 01:20:20
Same comment re: coupling.
To date, there's nothi
mshelley
2014/08/14 20:01:37
Done.
| |
180 NetLog* net_log); | 197 Delegate* delegate, |
198 NetLog* net_log); | |
181 virtual ~SSLConnectJob(); | 199 virtual ~SSLConnectJob(); |
182 | 200 |
183 // ConnectJob methods. | 201 // ConnectJob methods. |
184 virtual LoadState GetLoadState() const OVERRIDE; | 202 virtual LoadState GetLoadState() const OVERRIDE; |
185 | 203 |
186 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; | 204 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; |
187 | 205 |
188 private: | 206 private: |
189 enum State { | 207 enum State { |
190 STATE_TRANSPORT_CONNECT, | 208 STATE_TRANSPORT_CONNECT, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 const SSLClientSocketContext context_; | 256 const SSLClientSocketContext context_; |
239 | 257 |
240 State next_state_; | 258 State next_state_; |
241 CompletionCallback io_callback_; | 259 CompletionCallback io_callback_; |
242 scoped_ptr<ClientSocketHandle> transport_socket_handle_; | 260 scoped_ptr<ClientSocketHandle> transport_socket_handle_; |
243 scoped_ptr<SSLClientSocket> ssl_socket_; | 261 scoped_ptr<SSLClientSocket> ssl_socket_; |
244 | 262 |
245 SSLConnectJobMessenger* messenger_; | 263 SSLConnectJobMessenger* messenger_; |
246 HttpResponseInfo error_response_info_; | 264 HttpResponseInfo error_response_info_; |
247 | 265 |
266 SSLConnectJob::GetMessengerForUncachedSessionCallback | |
wtc
2014/08/14 00:46:46
You should be able to omit "SSLConnectJob::".
mshelley
2014/08/14 20:01:37
Done.
| |
267 uncached_session_callback_; | |
268 | |
248 base::WeakPtrFactory<SSLConnectJob> weak_factory_; | 269 base::WeakPtrFactory<SSLConnectJob> weak_factory_; |
249 | 270 |
250 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); | 271 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); |
251 }; | 272 }; |
252 | 273 |
253 class NET_EXPORT_PRIVATE SSLClientSocketPool | 274 class NET_EXPORT_PRIVATE SSLClientSocketPool |
254 : public ClientSocketPool, | 275 : public ClientSocketPool, |
255 public HigherLayeredPool, | 276 public HigherLayeredPool, |
256 public SSLConfigService::Observer { | 277 public SSLConfigService::Observer { |
257 public: | 278 public: |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 // LowerLayeredPool implementation. | 344 // LowerLayeredPool implementation. |
324 virtual bool IsStalled() const OVERRIDE; | 345 virtual bool IsStalled() const OVERRIDE; |
325 | 346 |
326 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; | 347 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; |
327 | 348 |
328 virtual void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; | 349 virtual void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; |
329 | 350 |
330 // HigherLayeredPool implementation. | 351 // HigherLayeredPool implementation. |
331 virtual bool CloseOneIdleConnection() OVERRIDE; | 352 virtual bool CloseOneIdleConnection() OVERRIDE; |
332 | 353 |
354 // Creates an SSLConnectJobMessenger for the given ssl session |cache_key| | |
wtc
2014/08/14 00:46:45
This comment is not accurate because the method ma
mshelley
2014/08/14 20:01:37
Done.
| |
355 // and stores it in |messenger_map_|. Returns the new SSLConnectJobMessenger. | |
356 SSLConnectJobMessenger* AddSSLConnectJobMessenger( | |
357 const std::string& cache_key); | |
358 void DeleteSSLConnectJobMessenger(const std::string& cache_key); | |
359 | |
333 private: | 360 private: |
334 typedef ClientSocketPoolBase<SSLSocketParams> PoolBase; | 361 typedef ClientSocketPoolBase<SSLSocketParams> PoolBase; |
362 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects. | |
363 typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap; | |
335 | 364 |
336 // SSLConfigService::Observer implementation. | 365 // SSLConfigService::Observer implementation. |
337 | 366 |
338 // When the user changes the SSL config, we flush all idle sockets so they | 367 // When the user changes the SSL config, we flush all idle sockets so they |
339 // won't get re-used. | 368 // won't get re-used. |
340 virtual void OnSSLConfigChanged() OVERRIDE; | 369 virtual void OnSSLConfigChanged() OVERRIDE; |
341 | 370 |
342 class SSLConnectJobFactory : public PoolBase::ConnectJobFactory { | 371 class SSLConnectJobFactory : public PoolBase::ConnectJobFactory { |
343 public: | 372 public: |
344 SSLConnectJobFactory(TransportClientSocketPool* transport_pool, | 373 SSLConnectJobFactory(TransportClientSocketPool* transport_pool, |
345 SOCKSClientSocketPool* socks_pool, | 374 SOCKSClientSocketPool* socks_pool, |
346 HttpProxyClientSocketPool* http_proxy_pool, | 375 HttpProxyClientSocketPool* http_proxy_pool, |
347 ClientSocketFactory* client_socket_factory, | 376 ClientSocketFactory* client_socket_factory, |
348 HostResolver* host_resolver, | 377 HostResolver* host_resolver, |
349 const SSLClientSocketContext& context, | 378 const SSLClientSocketContext& context, |
350 bool enable_ssl_connect_job_waiting, | 379 SSLConnectJob::GetMessengerForUncachedSessionCallback |
380 uncached_session_callback, | |
wtc
2014/08/14 00:46:46
Rename this "get_messenger_callback".
mshelley
2014/08/14 20:01:36
Done.
| |
351 NetLog* net_log); | 381 NetLog* net_log); |
352 | 382 |
353 virtual ~SSLConnectJobFactory(); | 383 virtual ~SSLConnectJobFactory(); |
354 | 384 |
355 // ClientSocketPoolBase::ConnectJobFactory methods. | 385 // ClientSocketPoolBase::ConnectJobFactory methods. |
356 virtual scoped_ptr<ConnectJob> NewConnectJob( | 386 virtual scoped_ptr<ConnectJob> NewConnectJob( |
357 const std::string& group_name, | 387 const std::string& group_name, |
358 const PoolBase::Request& request, | 388 const PoolBase::Request& request, |
359 ConnectJob::Delegate* delegate) const OVERRIDE; | 389 ConnectJob::Delegate* delegate) const OVERRIDE; |
360 | 390 |
361 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; | 391 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; |
362 | 392 |
363 private: | 393 private: |
364 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects. | |
365 typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap; | |
366 | |
367 TransportClientSocketPool* const transport_pool_; | 394 TransportClientSocketPool* const transport_pool_; |
368 SOCKSClientSocketPool* const socks_pool_; | 395 SOCKSClientSocketPool* const socks_pool_; |
369 HttpProxyClientSocketPool* const http_proxy_pool_; | 396 HttpProxyClientSocketPool* const http_proxy_pool_; |
370 ClientSocketFactory* const client_socket_factory_; | 397 ClientSocketFactory* const client_socket_factory_; |
371 HostResolver* const host_resolver_; | 398 HostResolver* const host_resolver_; |
372 const SSLClientSocketContext context_; | 399 const SSLClientSocketContext context_; |
373 base::TimeDelta timeout_; | 400 base::TimeDelta timeout_; |
374 bool enable_ssl_connect_job_waiting_; | 401 SSLConnectJob::GetMessengerForUncachedSessionCallback |
402 uncached_session_callback_; | |
wtc
2014/08/14 00:46:45
Rename this "get_messenger_callback".
mshelley
2014/08/14 20:01:36
Done.
| |
375 NetLog* net_log_; | 403 NetLog* net_log_; |
376 // |messenger_map_| is currently a pointer so that an element can be | |
377 // added to it inside of the const method NewConnectJob. In the future, | |
378 // elements will be added in a different method. | |
379 // TODO(mshelley) Change this to a non-pointer. | |
380 scoped_ptr<MessengerMap> messenger_map_; | |
381 | 404 |
382 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); | 405 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); |
383 }; | 406 }; |
384 | 407 |
385 TransportClientSocketPool* const transport_pool_; | 408 TransportClientSocketPool* const transport_pool_; |
386 SOCKSClientSocketPool* const socks_pool_; | 409 SOCKSClientSocketPool* const socks_pool_; |
387 HttpProxyClientSocketPool* const http_proxy_pool_; | 410 HttpProxyClientSocketPool* const http_proxy_pool_; |
388 PoolBase base_; | 411 PoolBase base_; |
389 const scoped_refptr<SSLConfigService> ssl_config_service_; | 412 const scoped_refptr<SSLConfigService> ssl_config_service_; |
413 MessengerMap messenger_map_; | |
414 bool enable_ssl_connect_job_waiting_; | |
390 | 415 |
391 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); | 416 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); |
392 }; | 417 }; |
393 | 418 |
394 } // namespace net | 419 } // namespace net |
395 | 420 |
396 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ | 421 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |