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 // The input string to ConnectionCompleteCallback is the SSL session cache key | |
118 // associated with this messenger. | |
119 typedef base::Callback<void(const std::string&)> ConnectionCompleteCallback; | |
Ryan Sleevi
2014/08/13 01:02:15
Usually we annotate callbacks like
typedef base::C
mshelley
2014/08/13 08:10:00
Done.
| |
117 | 120 |
118 SSLConnectJobMessenger(); | 121 SSLConnectJobMessenger( |
122 const ConnectionCompleteCallback& connection_complete_callback); | |
Ryan Sleevi
2014/08/13 01:02:15
A bit of documentation is needed here to explain w
| |
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 std::string group_name_; | |
Ryan Sleevi
2014/08/13 01:02:15
No longer needed?
mshelley
2014/08/13 08:09:59
Done.
| |
164 | |
165 base::WeakPtrFactory<SSLConnectJobMessenger> weak_factory_; | |
Ryan Sleevi
2014/08/13 01:02:15
WeakPtrFactory's should always be last.
mshelley
2014/08/13 08:09:59
Done.
| |
166 | |
167 ConnectionCompleteCallback connection_complete_callback_; | |
160 }; | 168 }; |
161 | 169 |
162 // SSLConnectJob handles the SSL handshake after setting up the underlying | 170 // SSLConnectJob handles the SSL handshake after setting up the underlying |
163 // connection as specified in the params. | 171 // connection as specified in the params. |
164 class SSLConnectJob : public ConnectJob { | 172 class SSLConnectJob : public ConnectJob { |
165 public: | 173 public: |
174 // The returned messenger is a pointer to an existing messenger | |
175 // owned by the SSLClientSocketPool. | |
Ryan Sleevi
2014/08/13 01:02:15
// Callback to allow the SSLConnectJob to obtain a
mshelley
2014/08/13 08:09:59
Done.
| |
176 typedef base::Callback<SSLConnectJobMessenger*(const std::string&)> | |
177 GetMessengerForUncachedSessionCallback; | |
178 | |
166 // Note: the SSLConnectJob does not own |messenger| so it must outlive the | 179 // Note: the SSLConnectJob does not own |messenger| so it must outlive the |
167 // job. | 180 // job. |
168 SSLConnectJob(const std::string& group_name, | 181 SSLConnectJob( |
169 RequestPriority priority, | 182 const std::string& group_name, |
170 const scoped_refptr<SSLSocketParams>& params, | 183 RequestPriority priority, |
171 const base::TimeDelta& timeout_duration, | 184 const scoped_refptr<SSLSocketParams>& params, |
172 TransportClientSocketPool* transport_pool, | 185 const base::TimeDelta& timeout_duration, |
173 SOCKSClientSocketPool* socks_pool, | 186 TransportClientSocketPool* transport_pool, |
174 HttpProxyClientSocketPool* http_proxy_pool, | 187 SOCKSClientSocketPool* socks_pool, |
175 ClientSocketFactory* client_socket_factory, | 188 HttpProxyClientSocketPool* http_proxy_pool, |
176 HostResolver* host_resolver, | 189 ClientSocketFactory* client_socket_factory, |
177 const SSLClientSocketContext& context, | 190 HostResolver* host_resolver, |
178 SSLConnectJobMessenger* messenger, | 191 const SSLClientSocketContext& context, |
179 Delegate* delegate, | 192 GetMessengerForUncachedSessionCallback uncached_session_callback, |
Ryan Sleevi
2014/08/13 01:02:15
const-ref the callback.
mshelley
2014/08/13 08:09:59
Done.
| |
180 NetLog* net_log); | 193 bool enable_ssl_connect_job_waiting, |
194 Delegate* delegate, | |
195 NetLog* net_log); | |
181 virtual ~SSLConnectJob(); | 196 virtual ~SSLConnectJob(); |
182 | 197 |
183 // ConnectJob methods. | 198 // ConnectJob methods. |
184 virtual LoadState GetLoadState() const OVERRIDE; | 199 virtual LoadState GetLoadState() const OVERRIDE; |
185 | 200 |
186 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; | 201 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; |
187 | 202 |
188 private: | 203 private: |
189 enum State { | 204 enum State { |
190 STATE_TRANSPORT_CONNECT, | 205 STATE_TRANSPORT_CONNECT, |
(...skipping 21 matching lines...) Expand all Loading... | |
212 int DoTunnelConnect(); | 227 int DoTunnelConnect(); |
213 int DoTunnelConnectComplete(int result); | 228 int DoTunnelConnectComplete(int result); |
214 int DoCreateSSLSocket(); | 229 int DoCreateSSLSocket(); |
215 int DoCheckForResume(); | 230 int DoCheckForResume(); |
216 int DoSSLConnect(); | 231 int DoSSLConnect(); |
217 int DoSSLConnectComplete(int result); | 232 int DoSSLConnectComplete(int result); |
218 | 233 |
219 // Tells a waiting SSLConnectJob to resume its SSL connection. | 234 // Tells a waiting SSLConnectJob to resume its SSL connection. |
220 void ResumeSSLConnection(); | 235 void ResumeSSLConnection(); |
221 | 236 |
237 // Runs a callback informing the SSLClientSocketPool that this | |
238 // SSLConnectJob's SSL session is not in the session cache. | |
239 void RunGetMessengerForUncachedSessionCallback(const std::string& cache_key); | |
240 | |
222 // Returns the initial state for the state machine based on the | 241 // Returns the initial state for the state machine based on the |
223 // |connection_type|. | 242 // |connection_type|. |
224 static State GetInitialState(SSLSocketParams::ConnectionType connection_type); | 243 static State GetInitialState(SSLSocketParams::ConnectionType connection_type); |
225 | 244 |
226 // Starts the SSL connection process. Returns OK on success and | 245 // Starts the SSL connection process. Returns OK on success and |
227 // ERR_IO_PENDING if it cannot immediately service the request. | 246 // ERR_IO_PENDING if it cannot immediately service the request. |
228 // Otherwise, it returns a net error code. | 247 // Otherwise, it returns a net error code. |
229 virtual int ConnectInternal() OVERRIDE; | 248 virtual int ConnectInternal() OVERRIDE; |
230 | 249 |
231 scoped_refptr<SSLSocketParams> params_; | 250 scoped_refptr<SSLSocketParams> params_; |
232 TransportClientSocketPool* const transport_pool_; | 251 TransportClientSocketPool* const transport_pool_; |
233 SOCKSClientSocketPool* const socks_pool_; | 252 SOCKSClientSocketPool* const socks_pool_; |
234 HttpProxyClientSocketPool* const http_proxy_pool_; | 253 HttpProxyClientSocketPool* const http_proxy_pool_; |
235 ClientSocketFactory* const client_socket_factory_; | 254 ClientSocketFactory* const client_socket_factory_; |
236 HostResolver* const host_resolver_; | 255 HostResolver* const host_resolver_; |
237 | 256 |
238 const SSLClientSocketContext context_; | 257 const SSLClientSocketContext context_; |
239 | 258 |
240 State next_state_; | 259 State next_state_; |
241 CompletionCallback io_callback_; | 260 CompletionCallback io_callback_; |
242 scoped_ptr<ClientSocketHandle> transport_socket_handle_; | 261 scoped_ptr<ClientSocketHandle> transport_socket_handle_; |
243 scoped_ptr<SSLClientSocket> ssl_socket_; | 262 scoped_ptr<SSLClientSocket> ssl_socket_; |
244 | 263 |
245 SSLConnectJobMessenger* messenger_; | 264 SSLConnectJobMessenger* messenger_; |
246 HttpResponseInfo error_response_info_; | 265 HttpResponseInfo error_response_info_; |
247 | 266 |
248 base::WeakPtrFactory<SSLConnectJob> weak_factory_; | 267 base::WeakPtrFactory<SSLConnectJob> weak_factory_; |
249 | 268 |
269 SSLConnectJob::GetMessengerForUncachedSessionCallback | |
270 uncached_session_callback_; | |
271 bool enable_ssl_connect_job_waiting_; | |
Ryan Sleevi
2014/08/13 01:02:15
1) Document
2) Is the bool really needed?
mshelley
2014/08/13 08:09:59
It can be avoided -- previously I thought I needed
| |
272 | |
250 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); | 273 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); |
251 }; | 274 }; |
252 | 275 |
253 class NET_EXPORT_PRIVATE SSLClientSocketPool | 276 class NET_EXPORT_PRIVATE SSLClientSocketPool |
254 : public ClientSocketPool, | 277 : public ClientSocketPool, |
255 public HigherLayeredPool, | 278 public HigherLayeredPool, |
256 public SSLConfigService::Observer { | 279 public SSLConfigService::Observer { |
257 public: | 280 public: |
258 typedef SSLSocketParams SocketParams; | 281 typedef SSLSocketParams SocketParams; |
259 | 282 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 // LowerLayeredPool implementation. | 346 // LowerLayeredPool implementation. |
324 virtual bool IsStalled() const OVERRIDE; | 347 virtual bool IsStalled() const OVERRIDE; |
325 | 348 |
326 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; | 349 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; |
327 | 350 |
328 virtual void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; | 351 virtual void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; |
329 | 352 |
330 // HigherLayeredPool implementation. | 353 // HigherLayeredPool implementation. |
331 virtual bool CloseOneIdleConnection() OVERRIDE; | 354 virtual bool CloseOneIdleConnection() OVERRIDE; |
332 | 355 |
356 // Creates an SSLConnectJobMessenger for the given |cache_key| and stores it | |
357 // in |messenger_map_|. Returns the new SSLConnectJobMessenger. | |
358 SSLConnectJobMessenger* AddSSLConnectJobMessenger( | |
359 const std::string& cache_key); | |
360 void DeleteSSLConnectJobMessenger(const std::string& cache_key); | |
Ryan Sleevi
2014/08/13 01:02:15
what's cache_key? group_name? session id? Somethin
mshelley
2014/08/13 08:09:59
Done.
| |
361 | |
333 private: | 362 private: |
334 typedef ClientSocketPoolBase<SSLSocketParams> PoolBase; | 363 typedef ClientSocketPoolBase<SSLSocketParams> PoolBase; |
364 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects. | |
365 typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap; | |
335 | 366 |
336 // SSLConfigService::Observer implementation. | 367 // SSLConfigService::Observer implementation. |
337 | 368 |
338 // When the user changes the SSL config, we flush all idle sockets so they | 369 // When the user changes the SSL config, we flush all idle sockets so they |
339 // won't get re-used. | 370 // won't get re-used. |
340 virtual void OnSSLConfigChanged() OVERRIDE; | 371 virtual void OnSSLConfigChanged() OVERRIDE; |
341 | 372 |
342 class SSLConnectJobFactory : public PoolBase::ConnectJobFactory { | 373 class SSLConnectJobFactory : public PoolBase::ConnectJobFactory { |
343 public: | 374 public: |
344 SSLConnectJobFactory(TransportClientSocketPool* transport_pool, | 375 SSLConnectJobFactory(TransportClientSocketPool* transport_pool, |
345 SOCKSClientSocketPool* socks_pool, | 376 SOCKSClientSocketPool* socks_pool, |
346 HttpProxyClientSocketPool* http_proxy_pool, | 377 HttpProxyClientSocketPool* http_proxy_pool, |
347 ClientSocketFactory* client_socket_factory, | 378 ClientSocketFactory* client_socket_factory, |
348 HostResolver* host_resolver, | 379 HostResolver* host_resolver, |
349 const SSLClientSocketContext& context, | 380 const SSLClientSocketContext& context, |
350 bool enable_ssl_connect_job_waiting, | 381 bool enable_ssl_connect_job_waiting, |
382 SSLConnectJob::GetMessengerForUncachedSessionCallback | |
383 uncached_session_callback, | |
351 NetLog* net_log); | 384 NetLog* net_log); |
352 | 385 |
353 virtual ~SSLConnectJobFactory(); | 386 virtual ~SSLConnectJobFactory(); |
354 | 387 |
355 // ClientSocketPoolBase::ConnectJobFactory methods. | 388 // ClientSocketPoolBase::ConnectJobFactory methods. |
356 virtual scoped_ptr<ConnectJob> NewConnectJob( | 389 virtual scoped_ptr<ConnectJob> NewConnectJob( |
357 const std::string& group_name, | 390 const std::string& group_name, |
358 const PoolBase::Request& request, | 391 const PoolBase::Request& request, |
359 ConnectJob::Delegate* delegate) const OVERRIDE; | 392 ConnectJob::Delegate* delegate) const OVERRIDE; |
360 | 393 |
361 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; | 394 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; |
362 | 395 |
363 private: | 396 private: |
364 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects. | 397 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects. |
365 typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap; | 398 typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap; |
366 | 399 |
367 TransportClientSocketPool* const transport_pool_; | 400 TransportClientSocketPool* const transport_pool_; |
368 SOCKSClientSocketPool* const socks_pool_; | 401 SOCKSClientSocketPool* const socks_pool_; |
369 HttpProxyClientSocketPool* const http_proxy_pool_; | 402 HttpProxyClientSocketPool* const http_proxy_pool_; |
370 ClientSocketFactory* const client_socket_factory_; | 403 ClientSocketFactory* const client_socket_factory_; |
371 HostResolver* const host_resolver_; | 404 HostResolver* const host_resolver_; |
372 const SSLClientSocketContext context_; | 405 const SSLClientSocketContext context_; |
373 base::TimeDelta timeout_; | 406 base::TimeDelta timeout_; |
374 bool enable_ssl_connect_job_waiting_; | 407 bool enable_ssl_connect_job_waiting_; |
408 SSLConnectJob::GetMessengerForUncachedSessionCallback | |
409 uncached_session_callback_; | |
375 NetLog* net_log_; | 410 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 | 411 |
382 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); | 412 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); |
383 }; | 413 }; |
384 | 414 |
385 TransportClientSocketPool* const transport_pool_; | 415 TransportClientSocketPool* const transport_pool_; |
386 SOCKSClientSocketPool* const socks_pool_; | 416 SOCKSClientSocketPool* const socks_pool_; |
387 HttpProxyClientSocketPool* const http_proxy_pool_; | 417 HttpProxyClientSocketPool* const http_proxy_pool_; |
388 PoolBase base_; | 418 PoolBase base_; |
389 const scoped_refptr<SSLConfigService> ssl_config_service_; | 419 const scoped_refptr<SSLConfigService> ssl_config_service_; |
420 MessengerMap messenger_map_; | |
390 | 421 |
391 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); | 422 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); |
392 }; | 423 }; |
393 | 424 |
394 } // namespace net | 425 } // namespace net |
395 | 426 |
396 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ | 427 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |