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" |
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" |
19 #include "net/socket/ssl_client_socket.h" | 21 #include "net/socket/ssl_client_socket.h" |
22 #include "net/socket/ssl_client_socket_openssl.h" | |
wtc
2014/06/19 19:38:11
Remove this header.
mshelley1
2014/06/24 17:03:59
Done.
| |
20 #include "net/ssl/ssl_config_service.h" | 23 #include "net/ssl/ssl_config_service.h" |
21 | 24 |
22 namespace net { | 25 namespace net { |
23 | 26 |
24 class CertVerifier; | 27 class CertVerifier; |
25 class ClientSocketFactory; | 28 class ClientSocketFactory; |
26 class ConnectJobFactory; | 29 class ConnectJobFactory; |
27 class CTVerifier; | 30 class CTVerifier; |
28 class HostPortPair; | 31 class HostPortPair; |
29 class HttpProxyClientSocketPool; | 32 class HttpProxyClientSocketPool; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
97 // SSLConnectJob handles the SSL handshake after setting up the underlying | 100 // SSLConnectJob handles the SSL handshake after setting up the underlying |
98 // connection as specified in the params. | 101 // connection as specified in the params. |
99 class SSLConnectJob : public ConnectJob { | 102 class SSLConnectJob : public ConnectJob { |
100 public: | 103 public: |
101 SSLConnectJob( | 104 // List of SSLConnectJobs that are either in the process of connecting |
102 const std::string& group_name, | 105 // to or waiting to connect to the same server. |
103 RequestPriority priority, | 106 typedef std::vector<SSLConnectJob*> PendingJobList; |
104 const scoped_refptr<SSLSocketParams>& params, | 107 |
105 const base::TimeDelta& timeout_duration, | 108 SSLConnectJob(const std::string& group_name, |
106 TransportClientSocketPool* transport_pool, | 109 RequestPriority priority, |
107 SOCKSClientSocketPool* socks_pool, | 110 const scoped_refptr<SSLSocketParams>& params, |
108 HttpProxyClientSocketPool* http_proxy_pool, | 111 const base::TimeDelta& timeout_duration, |
109 ClientSocketFactory* client_socket_factory, | 112 TransportClientSocketPool* transport_pool, |
110 HostResolver* host_resolver, | 113 SOCKSClientSocketPool* socks_pool, |
111 const SSLClientSocketContext& context, | 114 HttpProxyClientSocketPool* http_proxy_pool, |
112 Delegate* delegate, | 115 ClientSocketFactory* client_socket_factory, |
113 NetLog* net_log); | 116 HostResolver* host_resolver, |
117 const SSLClientSocketContext& context, | |
118 PendingJobList* pending_jobs_list, | |
119 Delegate* delegate, | |
120 NetLog* net_log); | |
114 virtual ~SSLConnectJob(); | 121 virtual ~SSLConnectJob(); |
115 | 122 |
116 // ConnectJob methods. | 123 // ConnectJob methods. |
117 virtual LoadState GetLoadState() const OVERRIDE; | 124 virtual LoadState GetLoadState() const OVERRIDE; |
118 | 125 |
119 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; | 126 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; |
120 | 127 |
128 // Allows a command line flag to enable SSLConnectJob waiting | |
wtc
2014/06/19 19:38:11
Nit: the comment should avoid describing a particu
mshelley1
2014/06/24 17:03:59
Done.
| |
129 static NET_EXPORT void EnableJobWaiting(bool enable); | |
130 | |
121 private: | 131 private: |
122 enum State { | 132 enum State { |
123 STATE_TRANSPORT_CONNECT, | 133 STATE_TRANSPORT_CONNECT, |
124 STATE_TRANSPORT_CONNECT_COMPLETE, | 134 STATE_TRANSPORT_CONNECT_COMPLETE, |
125 STATE_SOCKS_CONNECT, | 135 STATE_SOCKS_CONNECT, |
126 STATE_SOCKS_CONNECT_COMPLETE, | 136 STATE_SOCKS_CONNECT_COMPLETE, |
127 STATE_TUNNEL_CONNECT, | 137 STATE_TUNNEL_CONNECT, |
128 STATE_TUNNEL_CONNECT_COMPLETE, | 138 STATE_TUNNEL_CONNECT_COMPLETE, |
139 STATE_CREATE_SSL_SOCKET, | |
140 STATE_CHECK_FOR_RESUME, | |
129 STATE_SSL_CONNECT, | 141 STATE_SSL_CONNECT, |
130 STATE_SSL_CONNECT_COMPLETE, | 142 STATE_SSL_CONNECT_COMPLETE, |
131 STATE_NONE, | 143 STATE_NONE, |
132 }; | 144 }; |
133 | 145 |
134 void OnIOComplete(int result); | 146 void OnIOComplete(int result); |
135 | 147 |
136 // Runs the state transition loop. | 148 // Runs the state transition loop. |
137 int DoLoop(int result); | 149 int DoLoop(int result); |
138 | 150 |
139 int DoTransportConnect(); | 151 int DoTransportConnect(); |
140 int DoTransportConnectComplete(int result); | 152 int DoTransportConnectComplete(int result); |
141 int DoSOCKSConnect(); | 153 int DoSOCKSConnect(); |
142 int DoSOCKSConnectComplete(int result); | 154 int DoSOCKSConnectComplete(int result); |
143 int DoTunnelConnect(); | 155 int DoTunnelConnect(); |
144 int DoTunnelConnectComplete(int result); | 156 int DoTunnelConnectComplete(int result); |
157 int DoCreateSSLSocket(); | |
158 int DoCheckForResume(); | |
145 int DoSSLConnect(); | 159 int DoSSLConnect(); |
146 int DoSSLConnectComplete(int result); | 160 int DoSSLConnectComplete(int result); |
147 | 161 |
162 // Decides how pending jobs should continue their connection | |
163 // based upon the success or failure of the leading job. | |
164 void ProcessPendingJobs(int result); | |
165 | |
166 // Tells a waiting SSLConnectJob to resume its SSL connection. | |
167 void ResumeSSLConnection(); | |
168 | |
169 static bool enable_job_waiting_; | |
170 | |
148 // Returns the initial state for the state machine based on the | 171 // Returns the initial state for the state machine based on the |
149 // |connection_type|. | 172 // |connection_type|. |
150 static State GetInitialState(SSLSocketParams::ConnectionType connection_type); | 173 static State GetInitialState(SSLSocketParams::ConnectionType connection_type); |
151 | 174 |
152 // Starts the SSL connection process. Returns OK on success and | 175 // Starts the SSL connection process. Returns OK on success and |
153 // ERR_IO_PENDING if it cannot immediately service the request. | 176 // ERR_IO_PENDING if it cannot immediately service the request. |
154 // Otherwise, it returns a net error code. | 177 // Otherwise, it returns a net error code. |
155 virtual int ConnectInternal() OVERRIDE; | 178 virtual int ConnectInternal() OVERRIDE; |
156 | 179 |
157 scoped_refptr<SSLSocketParams> params_; | 180 scoped_refptr<SSLSocketParams> params_; |
158 TransportClientSocketPool* const transport_pool_; | 181 TransportClientSocketPool* const transport_pool_; |
159 SOCKSClientSocketPool* const socks_pool_; | 182 SOCKSClientSocketPool* const socks_pool_; |
160 HttpProxyClientSocketPool* const http_proxy_pool_; | 183 HttpProxyClientSocketPool* const http_proxy_pool_; |
161 ClientSocketFactory* const client_socket_factory_; | 184 ClientSocketFactory* const client_socket_factory_; |
162 HostResolver* const host_resolver_; | 185 HostResolver* const host_resolver_; |
163 | 186 |
164 const SSLClientSocketContext context_; | 187 const SSLClientSocketContext context_; |
165 | 188 |
166 State next_state_; | 189 State next_state_; |
167 CompletionCallback callback_; | 190 CompletionCallback io_callback_; |
168 scoped_ptr<ClientSocketHandle> transport_socket_handle_; | 191 scoped_ptr<ClientSocketHandle> transport_socket_handle_; |
169 scoped_ptr<SSLClientSocket> ssl_socket_; | 192 scoped_ptr<SSLClientSocket> ssl_socket_; |
170 | 193 |
194 PendingJobList* pending_jobs_; | |
171 HttpResponseInfo error_response_info_; | 195 HttpResponseInfo error_response_info_; |
172 | 196 |
173 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); | 197 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); |
174 }; | 198 }; |
175 | 199 |
176 class NET_EXPORT_PRIVATE SSLClientSocketPool | 200 class NET_EXPORT_PRIVATE SSLClientSocketPool |
177 : public ClientSocketPool, | 201 : public ClientSocketPool, |
178 public HigherLayeredPool, | 202 public HigherLayeredPool, |
179 public SSLConfigService::Observer { | 203 public SSLConfigService::Observer { |
180 public: | 204 public: |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 | 301 |
278 // ClientSocketPoolBase::ConnectJobFactory methods. | 302 // ClientSocketPoolBase::ConnectJobFactory methods. |
279 virtual scoped_ptr<ConnectJob> NewConnectJob( | 303 virtual scoped_ptr<ConnectJob> NewConnectJob( |
280 const std::string& group_name, | 304 const std::string& group_name, |
281 const PoolBase::Request& request, | 305 const PoolBase::Request& request, |
282 ConnectJob::Delegate* delegate) const OVERRIDE; | 306 ConnectJob::Delegate* delegate) const OVERRIDE; |
283 | 307 |
284 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; | 308 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; |
285 | 309 |
286 private: | 310 private: |
311 // Maps SSLConnectJob group names to lists of pending connect jobs to | |
312 // that group name. | |
313 typedef std::map<std::string, SSLConnectJob::PendingJobList*> PendingJobMap; | |
314 | |
287 TransportClientSocketPool* const transport_pool_; | 315 TransportClientSocketPool* const transport_pool_; |
288 SOCKSClientSocketPool* const socks_pool_; | 316 SOCKSClientSocketPool* const socks_pool_; |
289 HttpProxyClientSocketPool* const http_proxy_pool_; | 317 HttpProxyClientSocketPool* const http_proxy_pool_; |
290 ClientSocketFactory* const client_socket_factory_; | 318 ClientSocketFactory* const client_socket_factory_; |
291 HostResolver* const host_resolver_; | 319 HostResolver* const host_resolver_; |
292 const SSLClientSocketContext context_; | 320 const SSLClientSocketContext context_; |
293 base::TimeDelta timeout_; | 321 base::TimeDelta timeout_; |
294 NetLog* net_log_; | 322 NetLog* net_log_; |
323 scoped_ptr<PendingJobMap> pending_jobs_map_; | |
wtc
2014/06/19 19:38:11
It saves a memory allocation from the heap to decl
mshelley1
2014/06/24 17:03:59
Done.
| |
295 | 324 |
296 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); | 325 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); |
297 }; | 326 }; |
298 | 327 |
299 TransportClientSocketPool* const transport_pool_; | 328 TransportClientSocketPool* const transport_pool_; |
300 SOCKSClientSocketPool* const socks_pool_; | 329 SOCKSClientSocketPool* const socks_pool_; |
301 HttpProxyClientSocketPool* const http_proxy_pool_; | 330 HttpProxyClientSocketPool* const http_proxy_pool_; |
302 PoolBase base_; | 331 PoolBase base_; |
303 const scoped_refptr<SSLConfigService> ssl_config_service_; | 332 const scoped_refptr<SSLConfigService> ssl_config_service_; |
304 | 333 |
305 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); | 334 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); |
306 }; | 335 }; |
307 | 336 |
308 } // namespace net | 337 } // namespace net |
309 | 338 |
310 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ | 339 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |