Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: net/socket/ssl_client_socket_pool.h

Issue 476313004: Change the lifespan of SSlConnectJobMessengers so that they are created (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mark the SSLConnectJobMessenger constructor as explicit Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/socket/ssl_client_socket_openssl.cc ('k') | net/socket/ssl_client_socket_pool.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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| is run when a connection monitored by the
119 // SSLConnectJobMessenger has completed and we are finished with the
120 // SSLConnectJobMessenger.
121 explicit SSLConnectJobMessenger(
122 const base::Closure& messenger_finished_callback);
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
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 base::Closure messenger_finished_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 will be returned for all such ConnectJobs.
176 //
177 // Note: It will only be called for situations where the SSL session cache
178 // does not already have a candidate session to resume.
179 typedef base::Callback<SSLConnectJobMessenger*(const std::string&)>
180 GetMessengerCallback;
181
166 // Note: the SSLConnectJob does not own |messenger| so it must outlive the 182 // Note: the SSLConnectJob does not own |messenger| so it must outlive the
167 // job. 183 // job.
168 SSLConnectJob(const std::string& group_name, 184 SSLConnectJob(const std::string& group_name,
169 RequestPriority priority, 185 RequestPriority priority,
170 const scoped_refptr<SSLSocketParams>& params, 186 const scoped_refptr<SSLSocketParams>& params,
171 const base::TimeDelta& timeout_duration, 187 const base::TimeDelta& timeout_duration,
172 TransportClientSocketPool* transport_pool, 188 TransportClientSocketPool* transport_pool,
173 SOCKSClientSocketPool* socks_pool, 189 SOCKSClientSocketPool* socks_pool,
174 HttpProxyClientSocketPool* http_proxy_pool, 190 HttpProxyClientSocketPool* http_proxy_pool,
175 ClientSocketFactory* client_socket_factory, 191 ClientSocketFactory* client_socket_factory,
176 HostResolver* host_resolver, 192 HostResolver* host_resolver,
177 const SSLClientSocketContext& context, 193 const SSLClientSocketContext& context,
178 SSLConnectJobMessenger* messenger, 194 const GetMessengerCallback& get_messenger_callback,
179 Delegate* delegate, 195 Delegate* delegate,
180 NetLog* net_log); 196 NetLog* net_log);
181 virtual ~SSLConnectJob(); 197 virtual ~SSLConnectJob();
182 198
183 // ConnectJob methods. 199 // ConnectJob methods.
184 virtual LoadState GetLoadState() const OVERRIDE; 200 virtual LoadState GetLoadState() const OVERRIDE;
185 201
186 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; 202 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE;
187 203
188 private: 204 private:
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 const SSLClientSocketContext context_; 254 const SSLClientSocketContext context_;
239 255
240 State next_state_; 256 State next_state_;
241 CompletionCallback io_callback_; 257 CompletionCallback io_callback_;
242 scoped_ptr<ClientSocketHandle> transport_socket_handle_; 258 scoped_ptr<ClientSocketHandle> transport_socket_handle_;
243 scoped_ptr<SSLClientSocket> ssl_socket_; 259 scoped_ptr<SSLClientSocket> ssl_socket_;
244 260
245 SSLConnectJobMessenger* messenger_; 261 SSLConnectJobMessenger* messenger_;
246 HttpResponseInfo error_response_info_; 262 HttpResponseInfo error_response_info_;
247 263
264 GetMessengerCallback get_messenger_callback_;
265
248 base::WeakPtrFactory<SSLConnectJob> weak_factory_; 266 base::WeakPtrFactory<SSLConnectJob> weak_factory_;
249 267
250 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); 268 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob);
251 }; 269 };
252 270
253 class NET_EXPORT_PRIVATE SSLClientSocketPool 271 class NET_EXPORT_PRIVATE SSLClientSocketPool
254 : public ClientSocketPool, 272 : public ClientSocketPool,
255 public HigherLayeredPool, 273 public HigherLayeredPool,
256 public SSLConfigService::Observer { 274 public SSLConfigService::Observer {
257 public: 275 public:
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 // LowerLayeredPool implementation. 341 // LowerLayeredPool implementation.
324 virtual bool IsStalled() const OVERRIDE; 342 virtual bool IsStalled() const OVERRIDE;
325 343
326 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; 344 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE;
327 345
328 virtual void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; 346 virtual void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE;
329 347
330 // HigherLayeredPool implementation. 348 // HigherLayeredPool implementation.
331 virtual bool CloseOneIdleConnection() OVERRIDE; 349 virtual bool CloseOneIdleConnection() OVERRIDE;
332 350
351 // Gets the SSLConnectJobMessenger for the given ssl session |cache_key|. If
352 // none exits, it creates one and stores it in |messenger_map_|.
353 SSLConnectJobMessenger* GetOrCreateSSLConnectJobMessenger(
354 const std::string& cache_key);
355 void DeleteSSLConnectJobMessenger(const std::string& cache_key);
356
333 private: 357 private:
334 typedef ClientSocketPoolBase<SSLSocketParams> PoolBase; 358 typedef ClientSocketPoolBase<SSLSocketParams> PoolBase;
359 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects.
360 typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap;
335 361
336 // SSLConfigService::Observer implementation. 362 // SSLConfigService::Observer implementation.
337 363
338 // When the user changes the SSL config, we flush all idle sockets so they 364 // When the user changes the SSL config, we flush all idle sockets so they
339 // won't get re-used. 365 // won't get re-used.
340 virtual void OnSSLConfigChanged() OVERRIDE; 366 virtual void OnSSLConfigChanged() OVERRIDE;
341 367
342 class SSLConnectJobFactory : public PoolBase::ConnectJobFactory { 368 class SSLConnectJobFactory : public PoolBase::ConnectJobFactory {
343 public: 369 public:
344 SSLConnectJobFactory(TransportClientSocketPool* transport_pool, 370 SSLConnectJobFactory(
345 SOCKSClientSocketPool* socks_pool, 371 TransportClientSocketPool* transport_pool,
346 HttpProxyClientSocketPool* http_proxy_pool, 372 SOCKSClientSocketPool* socks_pool,
347 ClientSocketFactory* client_socket_factory, 373 HttpProxyClientSocketPool* http_proxy_pool,
348 HostResolver* host_resolver, 374 ClientSocketFactory* client_socket_factory,
349 const SSLClientSocketContext& context, 375 HostResolver* host_resolver,
350 bool enable_ssl_connect_job_waiting, 376 const SSLClientSocketContext& context,
351 NetLog* net_log); 377 const SSLConnectJob::GetMessengerCallback& get_messenger_callback,
378 NetLog* net_log);
352 379
353 virtual ~SSLConnectJobFactory(); 380 virtual ~SSLConnectJobFactory();
354 381
355 // ClientSocketPoolBase::ConnectJobFactory methods. 382 // ClientSocketPoolBase::ConnectJobFactory methods.
356 virtual scoped_ptr<ConnectJob> NewConnectJob( 383 virtual scoped_ptr<ConnectJob> NewConnectJob(
357 const std::string& group_name, 384 const std::string& group_name,
358 const PoolBase::Request& request, 385 const PoolBase::Request& request,
359 ConnectJob::Delegate* delegate) const OVERRIDE; 386 ConnectJob::Delegate* delegate) const OVERRIDE;
360 387
361 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; 388 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE;
362 389
363 private: 390 private:
364 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects.
365 typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap;
366
367 TransportClientSocketPool* const transport_pool_; 391 TransportClientSocketPool* const transport_pool_;
368 SOCKSClientSocketPool* const socks_pool_; 392 SOCKSClientSocketPool* const socks_pool_;
369 HttpProxyClientSocketPool* const http_proxy_pool_; 393 HttpProxyClientSocketPool* const http_proxy_pool_;
370 ClientSocketFactory* const client_socket_factory_; 394 ClientSocketFactory* const client_socket_factory_;
371 HostResolver* const host_resolver_; 395 HostResolver* const host_resolver_;
372 const SSLClientSocketContext context_; 396 const SSLClientSocketContext context_;
373 base::TimeDelta timeout_; 397 base::TimeDelta timeout_;
374 bool enable_ssl_connect_job_waiting_; 398 SSLConnectJob::GetMessengerCallback get_messenger_callback_;
375 NetLog* net_log_; 399 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 400
382 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); 401 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory);
383 }; 402 };
384 403
385 TransportClientSocketPool* const transport_pool_; 404 TransportClientSocketPool* const transport_pool_;
386 SOCKSClientSocketPool* const socks_pool_; 405 SOCKSClientSocketPool* const socks_pool_;
387 HttpProxyClientSocketPool* const http_proxy_pool_; 406 HttpProxyClientSocketPool* const http_proxy_pool_;
388 PoolBase base_; 407 PoolBase base_;
389 const scoped_refptr<SSLConfigService> ssl_config_service_; 408 const scoped_refptr<SSLConfigService> ssl_config_service_;
409 MessengerMap messenger_map_;
410 bool enable_ssl_connect_job_waiting_;
390 411
391 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); 412 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool);
392 }; 413 };
393 414
394 } // namespace net 415 } // namespace net
395 416
396 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ 417 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_
OLDNEW
« no previous file with comments | « net/socket/ssl_client_socket_openssl.cc ('k') | net/socket/ssl_client_socket_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698