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 <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 Loading... | |
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 | |
Ryan Sleevi
2014/06/26 01:47:16
Surely there's more to say here ;)
mshelley
2014/07/01 02:35:23
Done.
| |
102 class NET_EXPORT SSLConnectJobMessenger { | |
103 public: | |
104 // SSLPendingSocketsAndCallbacks manages the callback and socket | |
105 // associated with a pending ssl connection. | |
106 class SSLPendingSocketsAndCallbacks { | |
Ryan Sleevi
2014/06/26 01:47:16
This class should be private (and forward declared
mshelley
2014/07/01 02:35:23
Done.
| |
107 public: | |
108 SSLPendingSocketsAndCallbacks() { | |
109 pending_sockets_ = ScopedVector<scoped_ptr<SSLClientSocket> >(); | |
110 callbacks_ = std::vector<base::Closure>(); | |
Ryan Sleevi
2014/06/26 01:47:16
This isn't needed; callbacks_ default ctor will ru
mshelley
2014/07/01 02:35:22
Done.
| |
111 } | |
112 | |
113 SSLPendingSocketsAndCallbacks(SSLPendingSocketsAndCallbacks& ref) { | |
Ryan Sleevi
2014/06/26 01:47:16
This is a pretty dangerous constructor. Why was it
mshelley
2014/07/01 02:35:22
My intent was to implement the copy constructor --
Ryan Sleevi
2014/07/08 22:34:01
The style guide actively discourages this ( http:/
| |
114 pending_sockets_.swap(ref.pending_sockets_); | |
115 callbacks_.swap(ref.callbacks_); | |
116 } | |
117 | |
118 SSLClientSocket* push_back(scoped_ptr<SSLClientSocket> socket, | |
119 const base::Closure& cb) { | |
Ryan Sleevi
2014/06/26 01:47:16
naming: AddSocket?
mshelley
2014/07/01 02:35:22
Done.
| |
120 pending_sockets_.push_back(&socket); | |
121 callbacks_.push_back(cb); | |
122 return socket.release(); | |
123 } | |
124 | |
125 void clear() { | |
Ryan Sleevi
2014/06/26 01:47:16
style: clear() -> Clear()
mshelley
2014/07/01 02:35:22
Done.
| |
126 pending_sockets_.clear(); | |
127 callbacks_.clear(); | |
128 } | |
129 | |
130 // Tells all pending connections to resume. | |
131 void RunAllJobs() { | |
132 for (std::vector<base::Closure>::iterator it = callbacks_.begin(); | |
133 it != callbacks_.end(); | |
134 it++) | |
135 it->Run(); | |
Ryan Sleevi
2014/06/26 01:47:16
style: braces on multi-lines.
mshelley
2014/07/01 02:35:22
Isn't the body of this loop only one line though?
| |
136 } | |
137 | |
138 scoped_ptr<SSLClientSocket> GetFirstSocket() { | |
139 return pending_sockets_[0]->Pass(); | |
Ryan Sleevi
2014/06/26 01:47:16
safety: DCHECK(!pending_sockets_.empty()) ?
mshelley
2014/07/01 02:35:22
Done.
| |
140 } | |
141 | |
142 base::Closure GetFirstCallback() { return callbacks_[0]; } | |
Ryan Sleevi
2014/06/26 01:47:16
ditto safety
mshelley
2014/07/01 02:35:23
Done.
| |
143 | |
144 void EraseFirstEntry() { | |
Ryan Sleevi
2014/06/26 01:47:16
DANGER: if .begin() == .end(), this will explode.
mshelley
2014/07/01 02:35:23
Done.
| |
145 pending_sockets_.erase(pending_sockets_.begin()); | |
146 callbacks_.erase(callbacks_.begin()); | |
147 } | |
148 | |
149 private: | |
150 ScopedVector<scoped_ptr<SSLClientSocket> > pending_sockets_; | |
151 std::vector<base::Closure> callbacks_; | |
152 }; | |
153 | |
154 // Sets rv to true if the given |ssl_socket| should continue its | |
155 // SSL connection. | |
Ryan Sleevi
2014/06/26 01:47:16
STYLE: We don't pass output values as-ref; always
mshelley
2014/07/01 02:35:23
Done.
| |
156 SSLClientSocket* CanProceed(scoped_ptr<SSLClientSocket> ssl_socket, int& rv); | |
157 | |
158 // Informs the session cache that it should notify the SSLConnectJobMessenger | |
159 // upon the completion of |ssl_socket|'s connection. | |
160 SSLClientSocket* NotifyOfCompletion(scoped_ptr<SSLClientSocket> ssl_socket, | |
161 const base::Closure& cb); | |
Ryan Sleevi
2014/06/26 01:47:16
Ditto here. You're transferring ownership, but wha
mshelley
2014/07/01 02:35:23
Done.
| |
162 | |
163 // Processes pending callbacks when a socket successfully completes | |
164 // its connection. | |
165 void OnJobSucceeded(); | |
166 | |
167 // Processes pending callbacks when a socket encounters an error | |
168 // while completing its connection. | |
169 void OnJobFailed(); | |
170 | |
171 private: | |
172 SSLPendingSocketsAndCallbacks pending_sockets_and_callbacks_; | |
173 ScopedVector<scoped_ptr<SSLClientSocket> > connecting_sockets_; | |
174 }; | |
175 | |
97 // SSLConnectJob handles the SSL handshake after setting up the underlying | 176 // SSLConnectJob handles the SSL handshake after setting up the underlying |
98 // connection as specified in the params. | 177 // connection as specified in the params. |
99 class SSLConnectJob : public ConnectJob { | 178 class SSLConnectJob : public ConnectJob { |
100 public: | 179 public: |
101 SSLConnectJob( | 180 // Note: the SSLConnectJob does not own pending_jobs_list |
wtc
2014/06/27 00:36:49
This comment needs to be updated because there is
mshelley
2014/07/01 02:35:23
Done.
| |
102 const std::string& group_name, | 181 // so it must outlive the job. |
103 RequestPriority priority, | 182 SSLConnectJob(const std::string& group_name, |
104 const scoped_refptr<SSLSocketParams>& params, | 183 RequestPriority priority, |
105 const base::TimeDelta& timeout_duration, | 184 const scoped_refptr<SSLSocketParams>& params, |
106 TransportClientSocketPool* transport_pool, | 185 const base::TimeDelta& timeout_duration, |
107 SOCKSClientSocketPool* socks_pool, | 186 TransportClientSocketPool* transport_pool, |
108 HttpProxyClientSocketPool* http_proxy_pool, | 187 SOCKSClientSocketPool* socks_pool, |
109 ClientSocketFactory* client_socket_factory, | 188 HttpProxyClientSocketPool* http_proxy_pool, |
110 HostResolver* host_resolver, | 189 ClientSocketFactory* client_socket_factory, |
111 const SSLClientSocketContext& context, | 190 HostResolver* host_resolver, |
112 Delegate* delegate, | 191 const SSLClientSocketContext& context, |
113 NetLog* net_log); | 192 SSLConnectJobMessenger* messenger, |
193 Delegate* delegate, | |
194 NetLog* net_log); | |
114 virtual ~SSLConnectJob(); | 195 virtual ~SSLConnectJob(); |
115 | 196 |
116 // ConnectJob methods. | 197 // ConnectJob methods. |
117 virtual LoadState GetLoadState() const OVERRIDE; | 198 virtual LoadState GetLoadState() const OVERRIDE; |
118 | 199 |
119 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; | 200 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; |
120 | 201 |
202 base::WeakPtr<SSLConnectJob> GetWeakPtr(); | |
203 | |
204 // Enable SSLConnectJob waiting if |enable| is true. | |
205 static NET_EXPORT void EnableJobWaiting(bool enable); | |
206 | |
207 static bool GetEnableJobWaiting(); | |
208 | |
121 private: | 209 private: |
122 enum State { | 210 enum State { |
123 STATE_TRANSPORT_CONNECT, | 211 STATE_TRANSPORT_CONNECT, |
124 STATE_TRANSPORT_CONNECT_COMPLETE, | 212 STATE_TRANSPORT_CONNECT_COMPLETE, |
125 STATE_SOCKS_CONNECT, | 213 STATE_SOCKS_CONNECT, |
126 STATE_SOCKS_CONNECT_COMPLETE, | 214 STATE_SOCKS_CONNECT_COMPLETE, |
127 STATE_TUNNEL_CONNECT, | 215 STATE_TUNNEL_CONNECT, |
128 STATE_TUNNEL_CONNECT_COMPLETE, | 216 STATE_TUNNEL_CONNECT_COMPLETE, |
217 STATE_CREATE_SSL_SOCKET, | |
218 STATE_CHECK_FOR_RESUME, | |
129 STATE_SSL_CONNECT, | 219 STATE_SSL_CONNECT, |
130 STATE_SSL_CONNECT_COMPLETE, | 220 STATE_SSL_CONNECT_COMPLETE, |
131 STATE_NONE, | 221 STATE_NONE, |
132 }; | 222 }; |
133 | 223 |
134 void OnIOComplete(int result); | 224 void OnIOComplete(int result); |
135 | 225 |
136 // Runs the state transition loop. | 226 // Runs the state transition loop. |
137 int DoLoop(int result); | 227 int DoLoop(int result); |
138 | 228 |
139 int DoTransportConnect(); | 229 int DoTransportConnect(); |
140 int DoTransportConnectComplete(int result); | 230 int DoTransportConnectComplete(int result); |
141 int DoSOCKSConnect(); | 231 int DoSOCKSConnect(); |
142 int DoSOCKSConnectComplete(int result); | 232 int DoSOCKSConnectComplete(int result); |
143 int DoTunnelConnect(); | 233 int DoTunnelConnect(); |
144 int DoTunnelConnectComplete(int result); | 234 int DoTunnelConnectComplete(int result); |
235 int DoCreateSSLSocket(); | |
236 int DoCheckForResume(); | |
145 int DoSSLConnect(); | 237 int DoSSLConnect(); |
146 int DoSSLConnectComplete(int result); | 238 int DoSSLConnectComplete(int result); |
147 | 239 |
240 // Tells a waiting SSLConnectJob to resume its SSL connection. | |
241 void ResumeSSLConnection(); | |
242 | |
243 static bool enable_job_waiting_; | |
244 | |
148 // Returns the initial state for the state machine based on the | 245 // Returns the initial state for the state machine based on the |
149 // |connection_type|. | 246 // |connection_type|. |
150 static State GetInitialState(SSLSocketParams::ConnectionType connection_type); | 247 static State GetInitialState(SSLSocketParams::ConnectionType connection_type); |
151 | 248 |
152 // Starts the SSL connection process. Returns OK on success and | 249 // Starts the SSL connection process. Returns OK on success and |
153 // ERR_IO_PENDING if it cannot immediately service the request. | 250 // ERR_IO_PENDING if it cannot immediately service the request. |
154 // Otherwise, it returns a net error code. | 251 // Otherwise, it returns a net error code. |
155 virtual int ConnectInternal() OVERRIDE; | 252 virtual int ConnectInternal() OVERRIDE; |
156 | 253 |
157 scoped_refptr<SSLSocketParams> params_; | 254 scoped_refptr<SSLSocketParams> params_; |
158 TransportClientSocketPool* const transport_pool_; | 255 TransportClientSocketPool* const transport_pool_; |
159 SOCKSClientSocketPool* const socks_pool_; | 256 SOCKSClientSocketPool* const socks_pool_; |
160 HttpProxyClientSocketPool* const http_proxy_pool_; | 257 HttpProxyClientSocketPool* const http_proxy_pool_; |
161 ClientSocketFactory* const client_socket_factory_; | 258 ClientSocketFactory* const client_socket_factory_; |
162 HostResolver* const host_resolver_; | 259 HostResolver* const host_resolver_; |
163 | 260 |
164 const SSLClientSocketContext context_; | 261 const SSLClientSocketContext context_; |
165 | 262 |
166 State next_state_; | 263 State next_state_; |
167 CompletionCallback callback_; | 264 CompletionCallback io_callback_; |
168 scoped_ptr<ClientSocketHandle> transport_socket_handle_; | 265 scoped_ptr<ClientSocketHandle> transport_socket_handle_; |
169 scoped_ptr<SSLClientSocket> ssl_socket_; | 266 scoped_ptr<SSLClientSocket> ssl_socket_; |
170 | 267 |
268 SSLConnectJobMessenger* messenger_; | |
171 HttpResponseInfo error_response_info_; | 269 HttpResponseInfo error_response_info_; |
172 | 270 |
271 base::WeakPtrFactory<SSLConnectJob> weak_factory_; | |
272 | |
173 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); | 273 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); |
174 }; | 274 }; |
175 | 275 |
176 class NET_EXPORT_PRIVATE SSLClientSocketPool | 276 class NET_EXPORT_PRIVATE SSLClientSocketPool |
177 : public ClientSocketPool, | 277 : public ClientSocketPool, |
178 public HigherLayeredPool, | 278 public HigherLayeredPool, |
179 public SSLConfigService::Observer { | 279 public SSLConfigService::Observer { |
180 public: | 280 public: |
181 typedef SSLSocketParams SocketParams; | 281 typedef SSLSocketParams SocketParams; |
182 | 282 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 | 377 |
278 // ClientSocketPoolBase::ConnectJobFactory methods. | 378 // ClientSocketPoolBase::ConnectJobFactory methods. |
279 virtual scoped_ptr<ConnectJob> NewConnectJob( | 379 virtual scoped_ptr<ConnectJob> NewConnectJob( |
280 const std::string& group_name, | 380 const std::string& group_name, |
281 const PoolBase::Request& request, | 381 const PoolBase::Request& request, |
282 ConnectJob::Delegate* delegate) const OVERRIDE; | 382 ConnectJob::Delegate* delegate) const OVERRIDE; |
283 | 383 |
284 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; | 384 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; |
285 | 385 |
286 private: | 386 private: |
387 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects. | |
388 typedef std::map<std::string, SSLConnectJobMessenger*> PendingJobMap; | |
389 | |
287 TransportClientSocketPool* const transport_pool_; | 390 TransportClientSocketPool* const transport_pool_; |
288 SOCKSClientSocketPool* const socks_pool_; | 391 SOCKSClientSocketPool* const socks_pool_; |
289 HttpProxyClientSocketPool* const http_proxy_pool_; | 392 HttpProxyClientSocketPool* const http_proxy_pool_; |
290 ClientSocketFactory* const client_socket_factory_; | 393 ClientSocketFactory* const client_socket_factory_; |
291 HostResolver* const host_resolver_; | 394 HostResolver* const host_resolver_; |
292 const SSLClientSocketContext context_; | 395 const SSLClientSocketContext context_; |
293 base::TimeDelta timeout_; | 396 base::TimeDelta timeout_; |
294 NetLog* net_log_; | 397 NetLog* net_log_; |
398 scoped_ptr<PendingJobMap> pending_jobs_map_; | |
295 | 399 |
296 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); | 400 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); |
297 }; | 401 }; |
298 | 402 |
299 TransportClientSocketPool* const transport_pool_; | 403 TransportClientSocketPool* const transport_pool_; |
300 SOCKSClientSocketPool* const socks_pool_; | 404 SOCKSClientSocketPool* const socks_pool_; |
301 HttpProxyClientSocketPool* const http_proxy_pool_; | 405 HttpProxyClientSocketPool* const http_proxy_pool_; |
302 PoolBase base_; | 406 PoolBase base_; |
303 const scoped_refptr<SSLConfigService> ssl_config_service_; | 407 const scoped_refptr<SSLConfigService> ssl_config_service_; |
304 | 408 |
305 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); | 409 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); |
306 }; | 410 }; |
307 | 411 |
308 } // namespace net | 412 } // namespace net |
309 | 413 |
310 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ | 414 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |