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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | 117 |
118 SSLConnectJobMessenger(); | 118 // |messenger_finished_callback| when a connection monitored by the |
119 // SSLConnectJobMessenger has completed. | |
120 SSLConnectJobMessenger(const base::Closure& messenger_finished_callback); | |
119 ~SSLConnectJobMessenger(); | 121 ~SSLConnectJobMessenger(); |
120 | 122 |
121 // Removes |socket| from the set of sockets being monitored. This | 123 // Removes |socket| from the set of sockets being monitored. This |
122 // guarantees that |job_resumption_callback| will not be called for | 124 // guarantees that |job_resumption_callback| will not be called for |
123 // the socket. | 125 // the socket. |
124 void RemovePendingSocket(SSLClientSocket* ssl_socket); | 126 void RemovePendingSocket(SSLClientSocket* ssl_socket); |
125 | 127 |
126 // Returns true if |ssl_socket|'s Connect() method should be called. | 128 // Returns ture if |ssl_socket|'s Connect() method should be called. |
Ryan Sleevi
2014/08/15 19:18:48
typo: true
| |
127 bool CanProceed(SSLClientSocket* ssl_socket); | 129 bool CanProceed(SSLClientSocket* ssl_socket); |
128 | 130 |
129 // Configures the SSLConnectJobMessenger to begin monitoring |ssl_socket|'s | 131 // Configures the SSLConnectJobMessenger to begin monitoring |ssl_socket|'s |
130 // connection status. After a successful connection, or an error, | 132 // connection status. After a successful connection, or an error, |
131 // the messenger will determine which sockets that have been added | 133 // the messenger will determine which sockets that have been added |
132 // via AddPendingSocket() to allow to proceed. | 134 // via AddPendingSocket() to allow to proceed. |
133 void MonitorConnectionResult(SSLClientSocket* ssl_socket); | 135 void MonitorConnectionResult(SSLClientSocket* ssl_socket); |
134 | 136 |
135 // Adds |socket| to the list of sockets waiting to Connect(). When | 137 // Adds |socket| to the list of sockets waiting to Connect(). When |
136 // the messenger has determined that it's an appropriate time for |socket| | 138 // the messenger has determined that it's an appropriate time for |socket| |
137 // to connect, it will invoke |callback|. | 139 // to connect, it will invoke |callback|. |
138 // | 140 // |
139 // Note: It is an error to call AddPendingSocket() without having first | 141 // Note: It is an error to call AddPendingSocket() without having first |
140 // called MonitorConnectionResult() and configuring a socket that WILL | 142 // called MonitorConnectionResult() and configuring a socket that WILL |
141 // have Connect() called on it. | 143 // have Connect() called on it. |
142 void AddPendingSocket(SSLClientSocket* ssl_socket, | 144 void AddPendingSocket(SSLClientSocket* ssl_socket, |
143 const base::Closure& callback); | 145 const base::Closure& callback); |
144 | 146 |
145 private: | 147 private: |
146 // Processes pending callbacks when a socket completes its SSL handshake -- | 148 // Processes pending callbacks when a socket completes its SSL handshake -- |
147 // either successfully or unsuccessfully. | 149 // either successfully or unsuccessfully. |
148 void OnSSLHandshakeCompleted(); | 150 void OnSSLHandshakeCompleted(); |
149 | 151 |
150 // Runs all callbacks stored in |pending_sockets_and_callbacks_|. | 152 // Runs all callbacks stored in |pending_sockets_and_callbacks_|. |
151 void RunAllCallbacks( | 153 void RunAllCallbacks( |
152 const SSLPendingSocketsAndCallbacks& pending_socket_and_callbacks); | 154 const SSLPendingSocketsAndCallbacks& pending_socket_and_callbacks); |
153 | 155 |
154 base::WeakPtrFactory<SSLConnectJobMessenger> weak_factory_; | |
155 | |
156 SSLPendingSocketsAndCallbacks pending_sockets_and_callbacks_; | 156 SSLPendingSocketsAndCallbacks pending_sockets_and_callbacks_; |
157 // Note: this field is a vector to allow for future design changes. Currently, | 157 // Note: this field is a vector to allow for future design changes. Currently, |
158 // this vector should only ever have one entry. | 158 // this vector should only ever have one entry. |
159 std::vector<SSLClientSocket*> connecting_sockets_; | 159 std::vector<SSLClientSocket*> connecting_sockets_; |
160 | |
161 base::Closure messenger_finished_callback_; | |
162 | |
163 base::WeakPtrFactory<SSLConnectJobMessenger> weak_factory_; | |
160 }; | 164 }; |
161 | 165 |
162 // SSLConnectJob handles the SSL handshake after setting up the underlying | 166 // SSLConnectJob handles the SSL handshake after setting up the underlying |
163 // connection as specified in the params. | 167 // connection as specified in the params. |
164 class SSLConnectJob : public ConnectJob { | 168 class SSLConnectJob : public ConnectJob { |
165 public: | 169 public: |
170 // Callback to allow the SSLConnectJob to obtain an SSLConnectJobMessenger to | |
171 // coordinate connecting. The SSLConnectJob will supply a unique identifer | |
172 // (ex: the SSL session cache key), with the expectation that the same | |
173 // Messenger will be returned for all such ConnectJobs. | |
174 // | |
175 // Note: It will only be called for situations where the SSL session cache | |
176 // does not already have a candidate session to resume. | |
177 typedef base::Callback<SSLConnectJobMessenger*(const std::string&)> | |
178 GetMessengerCallback; | |
179 | |
166 // Note: the SSLConnectJob does not own |messenger| so it must outlive the | 180 // Note: the SSLConnectJob does not own |messenger| so it must outlive the |
167 // job. | 181 // job. |
168 SSLConnectJob(const std::string& group_name, | 182 SSLConnectJob(const std::string& group_name, |
169 RequestPriority priority, | 183 RequestPriority priority, |
170 const scoped_refptr<SSLSocketParams>& params, | 184 const scoped_refptr<SSLSocketParams>& params, |
171 const base::TimeDelta& timeout_duration, | 185 const base::TimeDelta& timeout_duration, |
172 TransportClientSocketPool* transport_pool, | 186 TransportClientSocketPool* transport_pool, |
173 SOCKSClientSocketPool* socks_pool, | 187 SOCKSClientSocketPool* socks_pool, |
174 HttpProxyClientSocketPool* http_proxy_pool, | 188 HttpProxyClientSocketPool* http_proxy_pool, |
175 ClientSocketFactory* client_socket_factory, | 189 ClientSocketFactory* client_socket_factory, |
176 HostResolver* host_resolver, | 190 HostResolver* host_resolver, |
177 const SSLClientSocketContext& context, | 191 const SSLClientSocketContext& context, |
178 SSLConnectJobMessenger* messenger, | 192 const GetMessengerCallback& get_messenger_callback, |
179 Delegate* delegate, | 193 Delegate* delegate, |
180 NetLog* net_log); | 194 NetLog* net_log); |
181 virtual ~SSLConnectJob(); | 195 virtual ~SSLConnectJob(); |
182 | 196 |
183 // ConnectJob methods. | 197 // ConnectJob methods. |
184 virtual LoadState GetLoadState() const OVERRIDE; | 198 virtual LoadState GetLoadState() const OVERRIDE; |
185 | 199 |
186 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; | 200 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; |
187 | 201 |
188 private: | 202 private: |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 const SSLClientSocketContext context_; | 252 const SSLClientSocketContext context_; |
239 | 253 |
240 State next_state_; | 254 State next_state_; |
241 CompletionCallback io_callback_; | 255 CompletionCallback io_callback_; |
242 scoped_ptr<ClientSocketHandle> transport_socket_handle_; | 256 scoped_ptr<ClientSocketHandle> transport_socket_handle_; |
243 scoped_ptr<SSLClientSocket> ssl_socket_; | 257 scoped_ptr<SSLClientSocket> ssl_socket_; |
244 | 258 |
245 SSLConnectJobMessenger* messenger_; | 259 SSLConnectJobMessenger* messenger_; |
246 HttpResponseInfo error_response_info_; | 260 HttpResponseInfo error_response_info_; |
247 | 261 |
262 GetMessengerCallback get_messenger_callback_; | |
263 | |
248 base::WeakPtrFactory<SSLConnectJob> weak_factory_; | 264 base::WeakPtrFactory<SSLConnectJob> weak_factory_; |
249 | 265 |
250 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); | 266 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); |
251 }; | 267 }; |
252 | 268 |
253 class NET_EXPORT_PRIVATE SSLClientSocketPool | 269 class NET_EXPORT_PRIVATE SSLClientSocketPool |
254 : public ClientSocketPool, | 270 : public ClientSocketPool, |
255 public HigherLayeredPool, | 271 public HigherLayeredPool, |
256 public SSLConfigService::Observer { | 272 public SSLConfigService::Observer { |
257 public: | 273 public: |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 // LowerLayeredPool implementation. | 339 // LowerLayeredPool implementation. |
324 virtual bool IsStalled() const OVERRIDE; | 340 virtual bool IsStalled() const OVERRIDE; |
325 | 341 |
326 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; | 342 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; |
327 | 343 |
328 virtual void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; | 344 virtual void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; |
329 | 345 |
330 // HigherLayeredPool implementation. | 346 // HigherLayeredPool implementation. |
331 virtual bool CloseOneIdleConnection() OVERRIDE; | 347 virtual bool CloseOneIdleConnection() OVERRIDE; |
332 | 348 |
349 // Gets the SSLConnectJobMessenger for the given ssl session |cache_key|. If | |
350 // none exits, it creates one and stores it in |messenger_map_|. | |
351 SSLConnectJobMessenger* GetOrCreateSSLConnectJobMessenger( | |
352 const std::string& cache_key); | |
353 void DeleteSSLConnectJobMessenger(const std::string& cache_key); | |
354 | |
333 private: | 355 private: |
334 typedef ClientSocketPoolBase<SSLSocketParams> PoolBase; | 356 typedef ClientSocketPoolBase<SSLSocketParams> PoolBase; |
357 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects. | |
358 typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap; | |
335 | 359 |
336 // SSLConfigService::Observer implementation. | 360 // SSLConfigService::Observer implementation. |
337 | 361 |
338 // When the user changes the SSL config, we flush all idle sockets so they | 362 // When the user changes the SSL config, we flush all idle sockets so they |
339 // won't get re-used. | 363 // won't get re-used. |
340 virtual void OnSSLConfigChanged() OVERRIDE; | 364 virtual void OnSSLConfigChanged() OVERRIDE; |
341 | 365 |
342 class SSLConnectJobFactory : public PoolBase::ConnectJobFactory { | 366 class SSLConnectJobFactory : public PoolBase::ConnectJobFactory { |
343 public: | 367 public: |
344 SSLConnectJobFactory(TransportClientSocketPool* transport_pool, | 368 SSLConnectJobFactory( |
345 SOCKSClientSocketPool* socks_pool, | 369 TransportClientSocketPool* transport_pool, |
346 HttpProxyClientSocketPool* http_proxy_pool, | 370 SOCKSClientSocketPool* socks_pool, |
347 ClientSocketFactory* client_socket_factory, | 371 HttpProxyClientSocketPool* http_proxy_pool, |
348 HostResolver* host_resolver, | 372 ClientSocketFactory* client_socket_factory, |
349 const SSLClientSocketContext& context, | 373 HostResolver* host_resolver, |
350 bool enable_ssl_connect_job_waiting, | 374 const SSLClientSocketContext& context, |
351 NetLog* net_log); | 375 const SSLConnectJob::GetMessengerCallback& get_messenger_callback, |
376 NetLog* net_log); | |
352 | 377 |
353 virtual ~SSLConnectJobFactory(); | 378 virtual ~SSLConnectJobFactory(); |
354 | 379 |
355 // ClientSocketPoolBase::ConnectJobFactory methods. | 380 // ClientSocketPoolBase::ConnectJobFactory methods. |
356 virtual scoped_ptr<ConnectJob> NewConnectJob( | 381 virtual scoped_ptr<ConnectJob> NewConnectJob( |
357 const std::string& group_name, | 382 const std::string& group_name, |
358 const PoolBase::Request& request, | 383 const PoolBase::Request& request, |
359 ConnectJob::Delegate* delegate) const OVERRIDE; | 384 ConnectJob::Delegate* delegate) const OVERRIDE; |
360 | 385 |
361 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; | 386 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; |
362 | 387 |
363 private: | 388 private: |
364 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects. | |
365 typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap; | |
366 | |
367 TransportClientSocketPool* const transport_pool_; | 389 TransportClientSocketPool* const transport_pool_; |
368 SOCKSClientSocketPool* const socks_pool_; | 390 SOCKSClientSocketPool* const socks_pool_; |
369 HttpProxyClientSocketPool* const http_proxy_pool_; | 391 HttpProxyClientSocketPool* const http_proxy_pool_; |
370 ClientSocketFactory* const client_socket_factory_; | 392 ClientSocketFactory* const client_socket_factory_; |
371 HostResolver* const host_resolver_; | 393 HostResolver* const host_resolver_; |
372 const SSLClientSocketContext context_; | 394 const SSLClientSocketContext context_; |
373 base::TimeDelta timeout_; | 395 base::TimeDelta timeout_; |
374 bool enable_ssl_connect_job_waiting_; | 396 SSLConnectJob::GetMessengerCallback get_messenger_callback_; |
375 NetLog* net_log_; | 397 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 | 398 |
382 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); | 399 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); |
383 }; | 400 }; |
384 | 401 |
385 TransportClientSocketPool* const transport_pool_; | 402 TransportClientSocketPool* const transport_pool_; |
386 SOCKSClientSocketPool* const socks_pool_; | 403 SOCKSClientSocketPool* const socks_pool_; |
387 HttpProxyClientSocketPool* const http_proxy_pool_; | 404 HttpProxyClientSocketPool* const http_proxy_pool_; |
388 PoolBase base_; | 405 PoolBase base_; |
389 const scoped_refptr<SSLConfigService> ssl_config_service_; | 406 const scoped_refptr<SSLConfigService> ssl_config_service_; |
407 MessengerMap messenger_map_; | |
408 bool enable_ssl_connect_job_waiting_; | |
390 | 409 |
391 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); | 410 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); |
392 }; | 411 }; |
393 | 412 |
394 } // namespace net | 413 } // namespace net |
395 | 414 |
396 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ | 415 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |