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

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

Issue 353713005: Implements new, more robust design for communicating between SSLConnectJobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed the structure of pending_sockets_and_callbacks_ and made cl compatible with nss. (Fixed one… Created 6 years, 5 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
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 <string> 9 #include <string>
10 #include <vector>
9 11
10 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
12 #include "base/time/time.h" 15 #include "base/time/time.h"
13 #include "net/base/privacy_mode.h" 16 #include "net/base/privacy_mode.h"
14 #include "net/dns/host_resolver.h" 17 #include "net/dns/host_resolver.h"
15 #include "net/http/http_response_info.h" 18 #include "net/http/http_response_info.h"
16 #include "net/socket/client_socket_pool.h" 19 #include "net/socket/client_socket_pool.h"
17 #include "net/socket/client_socket_pool_base.h" 20 #include "net/socket/client_socket_pool_base.h"
18 #include "net/socket/client_socket_pool_histograms.h" 21 #include "net/socket/client_socket_pool_histograms.h"
19 #include "net/socket/ssl_client_socket.h" 22 #include "net/socket/ssl_client_socket.h"
20 #include "net/ssl/ssl_config_service.h" 23 #include "net/ssl/ssl_config_service.h"
21 24
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 const SSLConfig ssl_config_; 90 const SSLConfig ssl_config_;
88 const PrivacyMode privacy_mode_; 91 const PrivacyMode privacy_mode_;
89 const int load_flags_; 92 const int load_flags_;
90 const bool force_spdy_over_ssl_; 93 const bool force_spdy_over_ssl_;
91 const bool want_spdy_over_npn_; 94 const bool want_spdy_over_npn_;
92 bool ignore_limits_; 95 bool ignore_limits_;
93 96
94 DISALLOW_COPY_AND_ASSIGN(SSLSocketParams); 97 DISALLOW_COPY_AND_ASSIGN(SSLSocketParams);
95 }; 98 };
96 99
100 // SSLConnectJobMessenger handles communication between concurrent
101 // SSLConnectJobs that share the same SSL session cache key.
102 //
103 // SSLConnectJobMessengers tell the session cache when a certain
104 // connection should be monitored for success or failure, and
105 // tell SSLConnectJobs when to pause or resume thier connections.
106 class NET_EXPORT_PRIVATE SSLConnectJobMessenger {
107 public:
108 struct SocketAndCallback {
109 SSLClientSocket* socket;
110 base::Closure callback;
111
112 SocketAndCallback(SSLClientSocket* ssl_socket,
113 base::Closure job_resumption_callback)
114 : socket(ssl_socket), callback(job_resumption_callback) {}
115 };
116
117 typedef std::vector<SocketAndCallback> SSLPendingSocketsAndCallbacks;
118
119 // Returns true if the given |ssl_socket| should continue its
120 // SSL connection.
121 bool CanProceed(SSLClientSocket* ssl_socket);
122
123 // Informs the session cache that it should notify the SSLConnectJobMessenger
124 // upon the completion of |ssl_socket|'s connection.
125 void MonitorConnectionResult(SSLClientSocket* ssl_socket);
126
127 // Adds the socket and its associated callback to the SSLConnectJobMessenger's
128 // list of pending sockets and callbacks.
129 void AddPendingSocket(SSLClientSocket* socket, const base::Closure& callback);
130
131 // Processes pending callbacks when a socket successfully completes
132 // its connection.
133 void OnJobSucceeded();
134
135 // Processes pending callbacks when a socket encounters an error
136 // while completing its connection.
137 void OnJobFailed();
138
139 private:
140 // Runs all callbacks stored in |pending_sockets_and_callbacks_|.
141 void RunAllJobs(std::vector<SocketAndCallback>& pending_socket_and_callbacks);
142
143 SSLPendingSocketsAndCallbacks pending_sockets_and_callbacks_;
144 std::vector<SSLClientSocket*> connecting_sockets_;
145 };
146
97 // SSLConnectJob handles the SSL handshake after setting up the underlying 147 // SSLConnectJob handles the SSL handshake after setting up the underlying
98 // connection as specified in the params. 148 // connection as specified in the params.
99 class SSLConnectJob : public ConnectJob { 149 class SSLConnectJob : public ConnectJob {
100 public: 150 public:
101 SSLConnectJob( 151 // Note: the SSLConnectJob does not own |messenger|.
102 const std::string& group_name, 152 // so it must outlive the job.
103 RequestPriority priority, 153 SSLConnectJob(const std::string& group_name,
104 const scoped_refptr<SSLSocketParams>& params, 154 RequestPriority priority,
105 const base::TimeDelta& timeout_duration, 155 const scoped_refptr<SSLSocketParams>& params,
106 TransportClientSocketPool* transport_pool, 156 const base::TimeDelta& timeout_duration,
107 SOCKSClientSocketPool* socks_pool, 157 TransportClientSocketPool* transport_pool,
108 HttpProxyClientSocketPool* http_proxy_pool, 158 SOCKSClientSocketPool* socks_pool,
109 ClientSocketFactory* client_socket_factory, 159 HttpProxyClientSocketPool* http_proxy_pool,
110 HostResolver* host_resolver, 160 ClientSocketFactory* client_socket_factory,
111 const SSLClientSocketContext& context, 161 HostResolver* host_resolver,
112 Delegate* delegate, 162 const SSLClientSocketContext& context,
113 NetLog* net_log); 163 SSLConnectJobMessenger* messenger,
164 Delegate* delegate,
165 NetLog* net_log);
114 virtual ~SSLConnectJob(); 166 virtual ~SSLConnectJob();
115 167
116 // ConnectJob methods. 168 // ConnectJob methods.
117 virtual LoadState GetLoadState() const OVERRIDE; 169 virtual LoadState GetLoadState() const OVERRIDE;
118 170
119 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; 171 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE;
120 172
121 private: 173 private:
122 enum State { 174 enum State {
123 STATE_TRANSPORT_CONNECT, 175 STATE_TRANSPORT_CONNECT,
124 STATE_TRANSPORT_CONNECT_COMPLETE, 176 STATE_TRANSPORT_CONNECT_COMPLETE,
125 STATE_SOCKS_CONNECT, 177 STATE_SOCKS_CONNECT,
126 STATE_SOCKS_CONNECT_COMPLETE, 178 STATE_SOCKS_CONNECT_COMPLETE,
127 STATE_TUNNEL_CONNECT, 179 STATE_TUNNEL_CONNECT,
128 STATE_TUNNEL_CONNECT_COMPLETE, 180 STATE_TUNNEL_CONNECT_COMPLETE,
181 STATE_CREATE_SSL_SOCKET,
182 STATE_CHECK_FOR_RESUME,
129 STATE_SSL_CONNECT, 183 STATE_SSL_CONNECT,
130 STATE_SSL_CONNECT_COMPLETE, 184 STATE_SSL_CONNECT_COMPLETE,
131 STATE_NONE, 185 STATE_NONE,
132 }; 186 };
133 187
134 void OnIOComplete(int result); 188 void OnIOComplete(int result);
135 189
136 // Runs the state transition loop. 190 // Runs the state transition loop.
137 int DoLoop(int result); 191 int DoLoop(int result);
138 192
139 int DoTransportConnect(); 193 int DoTransportConnect();
140 int DoTransportConnectComplete(int result); 194 int DoTransportConnectComplete(int result);
141 int DoSOCKSConnect(); 195 int DoSOCKSConnect();
142 int DoSOCKSConnectComplete(int result); 196 int DoSOCKSConnectComplete(int result);
143 int DoTunnelConnect(); 197 int DoTunnelConnect();
144 int DoTunnelConnectComplete(int result); 198 int DoTunnelConnectComplete(int result);
199 int DoCreateSSLSocket();
200 int DoCheckForResume();
145 int DoSSLConnect(); 201 int DoSSLConnect();
146 int DoSSLConnectComplete(int result); 202 int DoSSLConnectComplete(int result);
147 203
204 // Tells a waiting SSLConnectJob to resume its SSL connection.
205 void ResumeSSLConnection();
206
148 // Returns the initial state for the state machine based on the 207 // Returns the initial state for the state machine based on the
149 // |connection_type|. 208 // |connection_type|.
150 static State GetInitialState(SSLSocketParams::ConnectionType connection_type); 209 static State GetInitialState(SSLSocketParams::ConnectionType connection_type);
151 210
152 // Starts the SSL connection process. Returns OK on success and 211 // Starts the SSL connection process. Returns OK on success and
153 // ERR_IO_PENDING if it cannot immediately service the request. 212 // ERR_IO_PENDING if it cannot immediately service the request.
154 // Otherwise, it returns a net error code. 213 // Otherwise, it returns a net error code.
155 virtual int ConnectInternal() OVERRIDE; 214 virtual int ConnectInternal() OVERRIDE;
156 215
157 scoped_refptr<SSLSocketParams> params_; 216 scoped_refptr<SSLSocketParams> params_;
158 TransportClientSocketPool* const transport_pool_; 217 TransportClientSocketPool* const transport_pool_;
159 SOCKSClientSocketPool* const socks_pool_; 218 SOCKSClientSocketPool* const socks_pool_;
160 HttpProxyClientSocketPool* const http_proxy_pool_; 219 HttpProxyClientSocketPool* const http_proxy_pool_;
161 ClientSocketFactory* const client_socket_factory_; 220 ClientSocketFactory* const client_socket_factory_;
162 HostResolver* const host_resolver_; 221 HostResolver* const host_resolver_;
163 222
164 const SSLClientSocketContext context_; 223 const SSLClientSocketContext context_;
165 224
166 State next_state_; 225 State next_state_;
167 CompletionCallback callback_; 226 CompletionCallback io_callback_;
168 scoped_ptr<ClientSocketHandle> transport_socket_handle_; 227 scoped_ptr<ClientSocketHandle> transport_socket_handle_;
169 scoped_ptr<SSLClientSocket> ssl_socket_; 228 scoped_ptr<SSLClientSocket> ssl_socket_;
170 229
230 SSLConnectJobMessenger* messenger_;
171 HttpResponseInfo error_response_info_; 231 HttpResponseInfo error_response_info_;
172 232
233 base::WeakPtrFactory<SSLConnectJob> weak_factory_;
234
173 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); 235 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob);
174 }; 236 };
175 237
176 class NET_EXPORT_PRIVATE SSLClientSocketPool 238 class NET_EXPORT_PRIVATE SSLClientSocketPool
177 : public ClientSocketPool, 239 : public ClientSocketPool,
178 public HigherLayeredPool, 240 public HigherLayeredPool,
179 public SSLConfigService::Observer { 241 public SSLConfigService::Observer {
180 public: 242 public:
181 typedef SSLSocketParams SocketParams; 243 typedef SSLSocketParams SocketParams;
182 244
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 339
278 // ClientSocketPoolBase::ConnectJobFactory methods. 340 // ClientSocketPoolBase::ConnectJobFactory methods.
279 virtual scoped_ptr<ConnectJob> NewConnectJob( 341 virtual scoped_ptr<ConnectJob> NewConnectJob(
280 const std::string& group_name, 342 const std::string& group_name,
281 const PoolBase::Request& request, 343 const PoolBase::Request& request,
282 ConnectJob::Delegate* delegate) const OVERRIDE; 344 ConnectJob::Delegate* delegate) const OVERRIDE;
283 345
284 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; 346 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE;
285 347
286 private: 348 private:
349 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects.
350 typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap;
351
287 TransportClientSocketPool* const transport_pool_; 352 TransportClientSocketPool* const transport_pool_;
288 SOCKSClientSocketPool* const socks_pool_; 353 SOCKSClientSocketPool* const socks_pool_;
289 HttpProxyClientSocketPool* const http_proxy_pool_; 354 HttpProxyClientSocketPool* const http_proxy_pool_;
290 ClientSocketFactory* const client_socket_factory_; 355 ClientSocketFactory* const client_socket_factory_;
291 HostResolver* const host_resolver_; 356 HostResolver* const host_resolver_;
292 const SSLClientSocketContext context_; 357 const SSLClientSocketContext context_;
293 base::TimeDelta timeout_; 358 base::TimeDelta timeout_;
294 NetLog* net_log_; 359 NetLog* net_log_;
360 scoped_ptr<MessengerMap> messenger_map_;
295 361
296 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); 362 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory);
297 }; 363 };
298 364
299 TransportClientSocketPool* const transport_pool_; 365 TransportClientSocketPool* const transport_pool_;
300 SOCKSClientSocketPool* const socks_pool_; 366 SOCKSClientSocketPool* const socks_pool_;
301 HttpProxyClientSocketPool* const http_proxy_pool_; 367 HttpProxyClientSocketPool* const http_proxy_pool_;
302 PoolBase base_; 368 PoolBase base_;
303 const scoped_refptr<SSLConfigService> ssl_config_service_; 369 const scoped_refptr<SSLConfigService> ssl_config_service_;
304 370
305 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); 371 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool);
306 }; 372 };
307 373
308 } // namespace net 374 } // namespace net
309 375
310 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ 376 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698