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" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 // Note: the SSLConnectJob does not own pending_jobs_list |
106 TransportClientSocketPool* transport_pool, | 108 // so it must outlive the job. |
Ryan Sleevi
2014/06/24 23:40:44
I think the "Note:" here is probably best omitted.
mshelley1
2014/06/25 17:03:56
Done.
| |
107 SOCKSClientSocketPool* socks_pool, | 109 SSLConnectJob(const std::string& group_name, |
108 HttpProxyClientSocketPool* http_proxy_pool, | 110 RequestPriority priority, |
109 ClientSocketFactory* client_socket_factory, | 111 const scoped_refptr<SSLSocketParams>& params, |
110 HostResolver* host_resolver, | 112 const base::TimeDelta& timeout_duration, |
111 const SSLClientSocketContext& context, | 113 TransportClientSocketPool* transport_pool, |
112 Delegate* delegate, | 114 SOCKSClientSocketPool* socks_pool, |
113 NetLog* net_log); | 115 HttpProxyClientSocketPool* http_proxy_pool, |
116 ClientSocketFactory* client_socket_factory, | |
117 HostResolver* host_resolver, | |
118 const SSLClientSocketContext& context, | |
119 PendingJobList* pending_jobs_list, | |
120 Delegate* delegate, | |
121 NetLog* net_log); | |
114 virtual ~SSLConnectJob(); | 122 virtual ~SSLConnectJob(); |
115 | 123 |
116 // ConnectJob methods. | 124 // ConnectJob methods. |
117 virtual LoadState GetLoadState() const OVERRIDE; | 125 virtual LoadState GetLoadState() const OVERRIDE; |
118 | 126 |
119 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; | 127 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; |
120 | 128 |
129 // Enable SSLConnectJob waiting if |enable| is true. | |
Ryan Sleevi
2014/06/24 23:40:44
// Enables or disables SSLConnectJob waiting.
// I
mshelley1
2014/06/25 17:03:56
Done.
| |
130 static NET_EXPORT void EnableJobWaiting(bool enable); | |
131 | |
132 static bool GetEnableJobWaiting(); | |
133 | |
121 private: | 134 private: |
122 enum State { | 135 enum State { |
123 STATE_TRANSPORT_CONNECT, | 136 STATE_TRANSPORT_CONNECT, |
124 STATE_TRANSPORT_CONNECT_COMPLETE, | 137 STATE_TRANSPORT_CONNECT_COMPLETE, |
125 STATE_SOCKS_CONNECT, | 138 STATE_SOCKS_CONNECT, |
126 STATE_SOCKS_CONNECT_COMPLETE, | 139 STATE_SOCKS_CONNECT_COMPLETE, |
127 STATE_TUNNEL_CONNECT, | 140 STATE_TUNNEL_CONNECT, |
128 STATE_TUNNEL_CONNECT_COMPLETE, | 141 STATE_TUNNEL_CONNECT_COMPLETE, |
142 STATE_CREATE_SSL_SOCKET, | |
143 STATE_CHECK_FOR_RESUME, | |
129 STATE_SSL_CONNECT, | 144 STATE_SSL_CONNECT, |
130 STATE_SSL_CONNECT_COMPLETE, | 145 STATE_SSL_CONNECT_COMPLETE, |
131 STATE_NONE, | 146 STATE_NONE, |
132 }; | 147 }; |
133 | 148 |
134 void OnIOComplete(int result); | 149 void OnIOComplete(int result); |
135 | 150 |
136 // Runs the state transition loop. | 151 // Runs the state transition loop. |
137 int DoLoop(int result); | 152 int DoLoop(int result); |
138 | 153 |
139 int DoTransportConnect(); | 154 int DoTransportConnect(); |
140 int DoTransportConnectComplete(int result); | 155 int DoTransportConnectComplete(int result); |
141 int DoSOCKSConnect(); | 156 int DoSOCKSConnect(); |
142 int DoSOCKSConnectComplete(int result); | 157 int DoSOCKSConnectComplete(int result); |
143 int DoTunnelConnect(); | 158 int DoTunnelConnect(); |
144 int DoTunnelConnectComplete(int result); | 159 int DoTunnelConnectComplete(int result); |
160 int DoCreateSSLSocket(); | |
161 int DoCheckForResume(); | |
145 int DoSSLConnect(); | 162 int DoSSLConnect(); |
146 int DoSSLConnectComplete(int result); | 163 int DoSSLConnectComplete(int result); |
147 | 164 |
165 // Decides how pending jobs should continue their connection | |
166 // based upon the success or failure of the leading job. | |
167 void ProcessPendingJobs(int result); | |
168 | |
169 // Tells a waiting SSLConnectJob to resume its SSL connection. | |
170 void ResumeSSLConnection(); | |
171 | |
172 static bool enable_job_waiting_; | |
173 | |
148 // Returns the initial state for the state machine based on the | 174 // Returns the initial state for the state machine based on the |
149 // |connection_type|. | 175 // |connection_type|. |
150 static State GetInitialState(SSLSocketParams::ConnectionType connection_type); | 176 static State GetInitialState(SSLSocketParams::ConnectionType connection_type); |
151 | 177 |
152 // Starts the SSL connection process. Returns OK on success and | 178 // Starts the SSL connection process. Returns OK on success and |
153 // ERR_IO_PENDING if it cannot immediately service the request. | 179 // ERR_IO_PENDING if it cannot immediately service the request. |
154 // Otherwise, it returns a net error code. | 180 // Otherwise, it returns a net error code. |
155 virtual int ConnectInternal() OVERRIDE; | 181 virtual int ConnectInternal() OVERRIDE; |
156 | 182 |
157 scoped_refptr<SSLSocketParams> params_; | 183 scoped_refptr<SSLSocketParams> params_; |
158 TransportClientSocketPool* const transport_pool_; | 184 TransportClientSocketPool* const transport_pool_; |
159 SOCKSClientSocketPool* const socks_pool_; | 185 SOCKSClientSocketPool* const socks_pool_; |
160 HttpProxyClientSocketPool* const http_proxy_pool_; | 186 HttpProxyClientSocketPool* const http_proxy_pool_; |
161 ClientSocketFactory* const client_socket_factory_; | 187 ClientSocketFactory* const client_socket_factory_; |
162 HostResolver* const host_resolver_; | 188 HostResolver* const host_resolver_; |
163 | 189 |
164 const SSLClientSocketContext context_; | 190 const SSLClientSocketContext context_; |
165 | 191 |
166 State next_state_; | 192 State next_state_; |
167 CompletionCallback callback_; | 193 CompletionCallback io_callback_; |
168 scoped_ptr<ClientSocketHandle> transport_socket_handle_; | 194 scoped_ptr<ClientSocketHandle> transport_socket_handle_; |
169 scoped_ptr<SSLClientSocket> ssl_socket_; | 195 scoped_ptr<SSLClientSocket> ssl_socket_; |
170 | 196 |
197 // TODO(mshelley) ensure that these pointers are deleted. | |
Ryan Sleevi
2014/06/24 23:40:44
Is this TODO still applicable?
mshelley1
2014/06/25 17:03:56
Yes -- I need to make sure that the pending jobs i
| |
198 PendingJobList* pending_jobs_; | |
171 HttpResponseInfo error_response_info_; | 199 HttpResponseInfo error_response_info_; |
172 | 200 |
173 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); | 201 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); |
174 }; | 202 }; |
175 | 203 |
176 class NET_EXPORT_PRIVATE SSLClientSocketPool | 204 class NET_EXPORT_PRIVATE SSLClientSocketPool |
177 : public ClientSocketPool, | 205 : public ClientSocketPool, |
178 public HigherLayeredPool, | 206 public HigherLayeredPool, |
179 public SSLConfigService::Observer { | 207 public SSLConfigService::Observer { |
180 public: | 208 public: |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 | 305 |
278 // ClientSocketPoolBase::ConnectJobFactory methods. | 306 // ClientSocketPoolBase::ConnectJobFactory methods. |
279 virtual scoped_ptr<ConnectJob> NewConnectJob( | 307 virtual scoped_ptr<ConnectJob> NewConnectJob( |
280 const std::string& group_name, | 308 const std::string& group_name, |
281 const PoolBase::Request& request, | 309 const PoolBase::Request& request, |
282 ConnectJob::Delegate* delegate) const OVERRIDE; | 310 ConnectJob::Delegate* delegate) const OVERRIDE; |
283 | 311 |
284 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; | 312 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; |
285 | 313 |
286 private: | 314 private: |
315 // Maps SSLConnectJob group names to lists of pending connect jobs to | |
316 // that group name. | |
317 typedef std::map<std::string, SSLConnectJob::PendingJobList*> PendingJobMap; | |
318 | |
287 TransportClientSocketPool* const transport_pool_; | 319 TransportClientSocketPool* const transport_pool_; |
288 SOCKSClientSocketPool* const socks_pool_; | 320 SOCKSClientSocketPool* const socks_pool_; |
289 HttpProxyClientSocketPool* const http_proxy_pool_; | 321 HttpProxyClientSocketPool* const http_proxy_pool_; |
290 ClientSocketFactory* const client_socket_factory_; | 322 ClientSocketFactory* const client_socket_factory_; |
291 HostResolver* const host_resolver_; | 323 HostResolver* const host_resolver_; |
292 const SSLClientSocketContext context_; | 324 const SSLClientSocketContext context_; |
293 base::TimeDelta timeout_; | 325 base::TimeDelta timeout_; |
294 NetLog* net_log_; | 326 NetLog* net_log_; |
327 scoped_ptr<PendingJobMap> pending_jobs_map_; | |
Ryan Sleevi
2014/06/24 23:40:44
Why can't this just be a PendingJobsMap?
That is,
mshelley1
2014/06/25 17:03:56
If this is just a PendingJobsMap then I can't inse
Ryan Sleevi
2014/06/25 19:13:21
Ah, I missed that.
Yeah, it's definitely weird, a
| |
295 | 328 |
296 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); | 329 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); |
297 }; | 330 }; |
298 | 331 |
299 TransportClientSocketPool* const transport_pool_; | 332 TransportClientSocketPool* const transport_pool_; |
300 SOCKSClientSocketPool* const socks_pool_; | 333 SOCKSClientSocketPool* const socks_pool_; |
301 HttpProxyClientSocketPool* const http_proxy_pool_; | 334 HttpProxyClientSocketPool* const http_proxy_pool_; |
302 PoolBase base_; | 335 PoolBase base_; |
303 const scoped_refptr<SSLConfigService> ssl_config_service_; | 336 const scoped_refptr<SSLConfigService> ssl_config_service_; |
304 | 337 |
305 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); | 338 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); |
306 }; | 339 }; |
307 | 340 |
308 } // namespace net | 341 } // namespace net |
309 | 342 |
310 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ | 343 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |