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

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

Issue 328903004: SSL Connect Job Waiting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add separate state for ProcessPendingJobs Created 6 years, 6 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"
12 #include "base/time/time.h" 14 #include "base/time/time.h"
13 #include "net/base/privacy_mode.h" 15 #include "net/base/privacy_mode.h"
14 #include "net/dns/host_resolver.h" 16 #include "net/dns/host_resolver.h"
15 #include "net/http/http_response_info.h" 17 #include "net/http/http_response_info.h"
16 #include "net/socket/client_socket_pool.h" 18 #include "net/socket/client_socket_pool.h"
17 #include "net/socket/client_socket_pool_base.h" 19 #include "net/socket/client_socket_pool_base.h"
18 #include "net/socket/client_socket_pool_histograms.h" 20 #include "net/socket/client_socket_pool_histograms.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 const bool want_spdy_over_npn_; 93 const bool want_spdy_over_npn_;
92 bool ignore_limits_; 94 bool ignore_limits_;
93 95
94 DISALLOW_COPY_AND_ASSIGN(SSLSocketParams); 96 DISALLOW_COPY_AND_ASSIGN(SSLSocketParams);
95 }; 97 };
96 98
97 // SSLConnectJob handles the SSL handshake after setting up the underlying 99 // SSLConnectJob handles the SSL handshake after setting up the underlying
98 // connection as specified in the params. 100 // connection as specified in the params.
99 class SSLConnectJob : public ConnectJob { 101 class SSLConnectJob : public ConnectJob {
100 public: 102 public:
101 SSLConnectJob( 103 // List of SSLConnectJobs that are either in the process of connecting
102 const std::string& group_name, 104 // to or waiting to connect to the same server.
103 RequestPriority priority, 105 typedef std::vector<SSLConnectJob*> PendingJobList;
104 const scoped_refptr<SSLSocketParams>& params, 106
105 const base::TimeDelta& timeout_duration, 107 SSLConnectJob(const std::string& group_name,
wtc 2014/06/26 17:48:17 Please move the comment here: // Note: the SSLC
106 TransportClientSocketPool* transport_pool, 108 RequestPriority priority,
107 SOCKSClientSocketPool* socks_pool, 109 const scoped_refptr<SSLSocketParams>& params,
108 HttpProxyClientSocketPool* http_proxy_pool, 110 const base::TimeDelta& timeout_duration,
109 ClientSocketFactory* client_socket_factory, 111 TransportClientSocketPool* transport_pool,
110 HostResolver* host_resolver, 112 SOCKSClientSocketPool* socks_pool,
111 const SSLClientSocketContext& context, 113 HttpProxyClientSocketPool* http_proxy_pool,
112 Delegate* delegate, 114 ClientSocketFactory* client_socket_factory,
113 NetLog* net_log); 115 HostResolver* host_resolver,
116 const SSLClientSocketContext& context,
117 PendingJobList* pending_jobs_list,
118 Delegate* delegate,
119 NetLog* net_log);
114 virtual ~SSLConnectJob(); 120 virtual ~SSLConnectJob();
115 121
116 // ConnectJob methods. 122 // ConnectJob methods.
117 virtual LoadState GetLoadState() const OVERRIDE; 123 virtual LoadState GetLoadState() const OVERRIDE;
118 124
119 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; 125 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE;
120 126
127 // Enables or disables SSLConnectJob waiting.
128 // If enabled, simultaneous attempts to connect to the same server
129 // will be serialized until an SSL session is cached, allowing those
130 // handshakes to perform a resumption handshake.
131 static NET_EXPORT void EnableJobWaiting(bool enable);
132
133 static bool GetEnableJobWaiting();
wtc 2014/06/26 17:48:17 Nit: this function can be named "JobWaitingEnabled
134
121 private: 135 private:
122 enum State { 136 enum State {
123 STATE_TRANSPORT_CONNECT, 137 STATE_TRANSPORT_CONNECT,
124 STATE_TRANSPORT_CONNECT_COMPLETE, 138 STATE_TRANSPORT_CONNECT_COMPLETE,
125 STATE_SOCKS_CONNECT, 139 STATE_SOCKS_CONNECT,
126 STATE_SOCKS_CONNECT_COMPLETE, 140 STATE_SOCKS_CONNECT_COMPLETE,
127 STATE_TUNNEL_CONNECT, 141 STATE_TUNNEL_CONNECT,
128 STATE_TUNNEL_CONNECT_COMPLETE, 142 STATE_TUNNEL_CONNECT_COMPLETE,
143 STATE_CREATE_SSL_SOCKET,
144 STATE_CHECK_FOR_RESUME,
129 STATE_SSL_CONNECT, 145 STATE_SSL_CONNECT,
130 STATE_SSL_CONNECT_COMPLETE, 146 STATE_SSL_CONNECT_COMPLETE,
147 STATE_PROCESS_PENDING_JOBS,
131 STATE_NONE, 148 STATE_NONE,
132 }; 149 };
133 150
134 void OnIOComplete(int result); 151 void OnIOComplete(int result);
135 152
136 // Runs the state transition loop. 153 // Runs the state transition loop.
137 int DoLoop(int result); 154 int DoLoop(int result);
138 155
139 int DoTransportConnect(); 156 int DoTransportConnect();
140 int DoTransportConnectComplete(int result); 157 int DoTransportConnectComplete(int result);
141 int DoSOCKSConnect(); 158 int DoSOCKSConnect();
142 int DoSOCKSConnectComplete(int result); 159 int DoSOCKSConnectComplete(int result);
143 int DoTunnelConnect(); 160 int DoTunnelConnect();
144 int DoTunnelConnectComplete(int result); 161 int DoTunnelConnectComplete(int result);
162 int DoCreateSSLSocket();
163 int DoCheckForResume();
145 int DoSSLConnect(); 164 int DoSSLConnect();
146 int DoSSLConnectComplete(int result); 165 int DoSSLConnectComplete(int result);
166 int DoProcessPendingJobs(int result);
167
168 // Decides how pending jobs should continue their connection
169 // based upon the success or failure of the leading job.
170 void ProcessPendingJobs(int result);
171
172 // Tells a waiting SSLConnectJob to resume its SSL connection.
173 void ResumeSSLConnection();
147 174
148 // Returns the initial state for the state machine based on the 175 // Returns the initial state for the state machine based on the
149 // |connection_type|. 176 // |connection_type|.
150 static State GetInitialState(SSLSocketParams::ConnectionType connection_type); 177 static State GetInitialState(SSLSocketParams::ConnectionType connection_type);
151 178
152 // Starts the SSL connection process. Returns OK on success and 179 // Starts the SSL connection process. Returns OK on success and
153 // ERR_IO_PENDING if it cannot immediately service the request. 180 // ERR_IO_PENDING if it cannot immediately service the request.
154 // Otherwise, it returns a net error code. 181 // Otherwise, it returns a net error code.
155 virtual int ConnectInternal() OVERRIDE; 182 virtual int ConnectInternal() OVERRIDE;
156 183
184 static bool enable_job_waiting_;
157 scoped_refptr<SSLSocketParams> params_; 185 scoped_refptr<SSLSocketParams> params_;
158 TransportClientSocketPool* const transport_pool_; 186 TransportClientSocketPool* const transport_pool_;
159 SOCKSClientSocketPool* const socks_pool_; 187 SOCKSClientSocketPool* const socks_pool_;
160 HttpProxyClientSocketPool* const http_proxy_pool_; 188 HttpProxyClientSocketPool* const http_proxy_pool_;
161 ClientSocketFactory* const client_socket_factory_; 189 ClientSocketFactory* const client_socket_factory_;
162 HostResolver* const host_resolver_; 190 HostResolver* const host_resolver_;
163 191
164 const SSLClientSocketContext context_; 192 const SSLClientSocketContext context_;
165 193
166 State next_state_; 194 State next_state_;
167 CompletionCallback callback_; 195 CompletionCallback io_callback_;
168 scoped_ptr<ClientSocketHandle> transport_socket_handle_; 196 scoped_ptr<ClientSocketHandle> transport_socket_handle_;
169 scoped_ptr<SSLClientSocket> ssl_socket_; 197 scoped_ptr<SSLClientSocket> ssl_socket_;
170 198
199 // TODO(mshelley) ensure that these pointers are deleted.
200 PendingJobList* pending_jobs_;
171 HttpResponseInfo error_response_info_; 201 HttpResponseInfo error_response_info_;
172 202
173 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); 203 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob);
174 }; 204 };
175 205
176 class NET_EXPORT_PRIVATE SSLClientSocketPool 206 class NET_EXPORT_PRIVATE SSLClientSocketPool
177 : public ClientSocketPool, 207 : public ClientSocketPool,
178 public HigherLayeredPool, 208 public HigherLayeredPool,
179 public SSLConfigService::Observer { 209 public SSLConfigService::Observer {
180 public: 210 public:
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 307
278 // ClientSocketPoolBase::ConnectJobFactory methods. 308 // ClientSocketPoolBase::ConnectJobFactory methods.
279 virtual scoped_ptr<ConnectJob> NewConnectJob( 309 virtual scoped_ptr<ConnectJob> NewConnectJob(
280 const std::string& group_name, 310 const std::string& group_name,
281 const PoolBase::Request& request, 311 const PoolBase::Request& request,
282 ConnectJob::Delegate* delegate) const OVERRIDE; 312 ConnectJob::Delegate* delegate) const OVERRIDE;
283 313
284 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; 314 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE;
285 315
286 private: 316 private:
317 // Maps SSLConnectJob group names to lists of pending connect jobs to
318 // that group name.
319 typedef std::map<std::string, SSLConnectJob::PendingJobList*> PendingJobMap;
320
287 TransportClientSocketPool* const transport_pool_; 321 TransportClientSocketPool* const transport_pool_;
288 SOCKSClientSocketPool* const socks_pool_; 322 SOCKSClientSocketPool* const socks_pool_;
289 HttpProxyClientSocketPool* const http_proxy_pool_; 323 HttpProxyClientSocketPool* const http_proxy_pool_;
290 ClientSocketFactory* const client_socket_factory_; 324 ClientSocketFactory* const client_socket_factory_;
291 HostResolver* const host_resolver_; 325 HostResolver* const host_resolver_;
292 const SSLClientSocketContext context_; 326 const SSLClientSocketContext context_;
293 base::TimeDelta timeout_; 327 base::TimeDelta timeout_;
294 NetLog* net_log_; 328 NetLog* net_log_;
329 scoped_ptr<PendingJobMap> pending_jobs_map_;
wtc 2014/06/26 17:48:17 Please declare this member as a non-pointer, if th
295 330
296 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); 331 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory);
297 }; 332 };
298 333
299 TransportClientSocketPool* const transport_pool_; 334 TransportClientSocketPool* const transport_pool_;
300 SOCKSClientSocketPool* const socks_pool_; 335 SOCKSClientSocketPool* const socks_pool_;
301 HttpProxyClientSocketPool* const http_proxy_pool_; 336 HttpProxyClientSocketPool* const http_proxy_pool_;
302 PoolBase base_; 337 PoolBase base_;
303 const scoped_refptr<SSLConfigService> ssl_config_service_; 338 const scoped_refptr<SSLConfigService> ssl_config_service_;
304 339
305 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); 340 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool);
306 }; 341 };
307 342
308 } // namespace net 343 } // namespace net
309 344
310 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ 345 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698