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 <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 void OnJobSucceeded(); | 135 void OnJobSucceeded(); |
136 | 136 |
137 // Posts a task to process pending callbacks when a socket encounters an error | 137 // Posts a task to process pending callbacks when a socket encounters an error |
138 // while completing its connection. | 138 // while completing its connection. |
139 void OnJobFailed(); | 139 void OnJobFailed(); |
140 | 140 |
141 // Determines which pending socket should be the next leading connection, | 141 // Determines which pending socket should be the next leading connection, |
142 // and runs that socket's resumption callback. | 142 // and runs that socket's resumption callback. |
143 void ConnectNewLeader(); | 143 void ConnectNewLeader(); |
144 | 144 |
145 // Returns true if this SSLConnectJobMessenger is still in use. | |
146 bool IsNeeded(); | |
Ryan Sleevi
2014/07/25 21:40:07
What does "in use" mean? By who? Better to expand
mshelley
2014/07/28 21:05:32
Done.
| |
147 | |
145 private: | 148 private: |
146 // Runs all callbacks stored in |pending_sockets_and_callbacks_|. | 149 // Runs all callbacks stored in |pending_sockets_and_callbacks_|. |
147 void RunAllJobs( | 150 void RunAllJobs( |
148 std::vector<SocketAndCallback>& pending_sockets_and_callbacks); | 151 std::vector<SocketAndCallback>& pending_sockets_and_callbacks); |
149 | 152 |
150 base::WeakPtrFactory<SSLConnectJobMessenger> weak_factory_; | 153 base::WeakPtrFactory<SSLConnectJobMessenger> weak_factory_; |
151 SSLPendingSocketsAndCallbacks pending_sockets_and_callbacks_; | 154 SSLPendingSocketsAndCallbacks pending_sockets_and_callbacks_; |
152 std::vector<SSLClientSocket*> connecting_sockets_; | 155 std::vector<SSLClientSocket*> connecting_sockets_; |
153 }; | 156 }; |
154 | 157 |
155 // SSLConnectJob handles the SSL handshake after setting up the underlying | 158 // SSLConnectJob handles the SSL handshake after setting up the underlying |
156 // connection as specified in the params. | 159 // connection as specified in the params. |
157 class SSLConnectJob : public ConnectJob { | 160 class SSLConnectJob : public ConnectJob { |
158 public: | 161 public: |
162 typedef base::Callback<SSLConnectJobMessenger*(std::string)> | |
Ryan Sleevi
2014/07/25 21:40:07
What is the ownership semantics of the Messenger p
mshelley
2014/07/28 21:05:32
Done.
| |
163 AddMessengerCallback; | |
164 typedef base::Callback<void(std::string)> DeleteMessengerCallback; | |
165 | |
159 // Note: the SSLConnectJob does not own |messenger|. | 166 // Note: the SSLConnectJob does not own |messenger|. |
160 // so it must outlive the job. | 167 // so it must outlive the job. |
161 SSLConnectJob(const std::string& group_name, | 168 SSLConnectJob(const std::string& group_name, |
162 RequestPriority priority, | 169 RequestPriority priority, |
163 const scoped_refptr<SSLSocketParams>& params, | 170 const scoped_refptr<SSLSocketParams>& params, |
164 const base::TimeDelta& timeout_duration, | 171 const base::TimeDelta& timeout_duration, |
165 TransportClientSocketPool* transport_pool, | 172 TransportClientSocketPool* transport_pool, |
166 SOCKSClientSocketPool* socks_pool, | 173 SOCKSClientSocketPool* socks_pool, |
167 HttpProxyClientSocketPool* http_proxy_pool, | 174 HttpProxyClientSocketPool* http_proxy_pool, |
168 ClientSocketFactory* client_socket_factory, | 175 ClientSocketFactory* client_socket_factory, |
169 HostResolver* host_resolver, | 176 HostResolver* host_resolver, |
170 const SSLClientSocketContext& context, | 177 const SSLClientSocketContext& context, |
171 SSLConnectJobMessenger* messenger, | 178 SSLConnectJobMessenger* messenger, |
179 AddMessengerCallback add_messenger_calblack, | |
180 DeleteMessengerCallback delete_messenger_callback, | |
172 Delegate* delegate, | 181 Delegate* delegate, |
173 NetLog* net_log); | 182 NetLog* net_log); |
174 virtual ~SSLConnectJob(); | 183 virtual ~SSLConnectJob(); |
175 | 184 |
176 // ConnectJob methods. | 185 // ConnectJob methods. |
177 virtual LoadState GetLoadState() const OVERRIDE; | 186 virtual LoadState GetLoadState() const OVERRIDE; |
178 | 187 |
179 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; | 188 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; |
180 | 189 |
181 private: | 190 private: |
(...skipping 23 matching lines...) Expand all Loading... | |
205 int DoTunnelConnect(); | 214 int DoTunnelConnect(); |
206 int DoTunnelConnectComplete(int result); | 215 int DoTunnelConnectComplete(int result); |
207 int DoCreateSSLSocket(); | 216 int DoCreateSSLSocket(); |
208 int DoCheckForResume(); | 217 int DoCheckForResume(); |
209 int DoSSLConnect(); | 218 int DoSSLConnect(); |
210 int DoSSLConnectComplete(int result); | 219 int DoSSLConnectComplete(int result); |
211 | 220 |
212 // Tells a waiting SSLConnectJob to resume its SSL connection. | 221 // Tells a waiting SSLConnectJob to resume its SSL connection. |
213 void ResumeSSLConnection(); | 222 void ResumeSSLConnection(); |
214 | 223 |
224 // Retrieves an SSLConnectJobMessenger from the SSLConnectJobFactory and | |
225 // stores it in the messenger_ field. | |
226 void GetMessenger(std::string cache_key); | |
227 | |
228 // Deletes this job's SSLConnectJobMessenger from the SSLConnectJobFactory's | |
229 // map of messengers, and deletes the messenger itself. | |
230 void DeleteMessenger(std::string cache_key); | |
Ryan Sleevi
2014/07/25 21:40:07
This seems like a layering violation. The SSLConne
mshelley
2014/07/28 21:05:32
Right now, the SSLConnectJobFactory manages the li
| |
231 | |
215 // Returns the initial state for the state machine based on the | 232 // Returns the initial state for the state machine based on the |
216 // |connection_type|. | 233 // |connection_type|. |
217 static State GetInitialState(SSLSocketParams::ConnectionType connection_type); | 234 static State GetInitialState(SSLSocketParams::ConnectionType connection_type); |
218 | 235 |
219 // Starts the SSL connection process. Returns OK on success and | 236 // Starts the SSL connection process. Returns OK on success and |
220 // ERR_IO_PENDING if it cannot immediately service the request. | 237 // ERR_IO_PENDING if it cannot immediately service the request. |
221 // Otherwise, it returns a net error code. | 238 // Otherwise, it returns a net error code. |
222 virtual int ConnectInternal() OVERRIDE; | 239 virtual int ConnectInternal() OVERRIDE; |
223 | 240 |
224 scoped_refptr<SSLSocketParams> params_; | 241 scoped_refptr<SSLSocketParams> params_; |
225 TransportClientSocketPool* const transport_pool_; | 242 TransportClientSocketPool* const transport_pool_; |
226 SOCKSClientSocketPool* const socks_pool_; | 243 SOCKSClientSocketPool* const socks_pool_; |
227 HttpProxyClientSocketPool* const http_proxy_pool_; | 244 HttpProxyClientSocketPool* const http_proxy_pool_; |
228 ClientSocketFactory* const client_socket_factory_; | 245 ClientSocketFactory* const client_socket_factory_; |
229 HostResolver* const host_resolver_; | 246 HostResolver* const host_resolver_; |
230 | 247 |
231 const SSLClientSocketContext context_; | 248 const SSLClientSocketContext context_; |
232 | 249 |
233 State next_state_; | 250 State next_state_; |
234 CompletionCallback io_callback_; | 251 CompletionCallback io_callback_; |
235 scoped_ptr<ClientSocketHandle> transport_socket_handle_; | 252 scoped_ptr<ClientSocketHandle> transport_socket_handle_; |
236 scoped_ptr<SSLClientSocket> ssl_socket_; | 253 scoped_ptr<SSLClientSocket> ssl_socket_; |
237 | 254 |
238 SSLConnectJobMessenger* messenger_; | 255 SSLConnectJobMessenger* messenger_; |
239 HttpResponseInfo error_response_info_; | 256 HttpResponseInfo error_response_info_; |
240 | 257 |
241 base::WeakPtrFactory<SSLConnectJob> weak_factory_; | 258 base::WeakPtrFactory<SSLConnectJob> weak_factory_; |
242 | 259 |
260 AddMessengerCallback add_messenger_callback_; | |
261 DeleteMessengerCallback delete_messenger_callback_; | |
Ryan Sleevi
2014/07/25 21:40:07
What are these callbacks?
Connect() can be called
mshelley
2014/07/28 21:05:32
These are callbacks to methods of the SSLConnectJo
| |
262 | |
243 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); | 263 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); |
244 }; | 264 }; |
245 | 265 |
246 class NET_EXPORT_PRIVATE SSLClientSocketPool | 266 class NET_EXPORT_PRIVATE SSLClientSocketPool |
247 : public ClientSocketPool, | 267 : public ClientSocketPool, |
248 public HigherLayeredPool, | 268 public HigherLayeredPool, |
249 public SSLConfigService::Observer { | 269 public SSLConfigService::Observer { |
250 public: | 270 public: |
251 typedef SSLSocketParams SocketParams; | 271 typedef SSLSocketParams SocketParams; |
252 | 272 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 TransportClientSocketPool* transport_pool, | 358 TransportClientSocketPool* transport_pool, |
339 SOCKSClientSocketPool* socks_pool, | 359 SOCKSClientSocketPool* socks_pool, |
340 HttpProxyClientSocketPool* http_proxy_pool, | 360 HttpProxyClientSocketPool* http_proxy_pool, |
341 ClientSocketFactory* client_socket_factory, | 361 ClientSocketFactory* client_socket_factory, |
342 HostResolver* host_resolver, | 362 HostResolver* host_resolver, |
343 const SSLClientSocketContext& context, | 363 const SSLClientSocketContext& context, |
344 NetLog* net_log); | 364 NetLog* net_log); |
345 | 365 |
346 virtual ~SSLConnectJobFactory() {} | 366 virtual ~SSLConnectJobFactory() {} |
347 | 367 |
368 // Creates an SSLConnectJobMessenger for the given |cache_key| and stores it | |
369 // in |messenger_map_|. Returns the new SSLConnectJobMessenger. | |
370 SSLConnectJobMessenger* AddSSLConnectJobMessenger(std::string cache_key); | |
371 | |
372 // Deletes the entry for the given |cache_key| from the |messenger_map_|. | |
373 void DeleteSSLConnectJobMessenger(std::string cache_key); | |
374 | |
348 // ClientSocketPoolBase::ConnectJobFactory methods. | 375 // ClientSocketPoolBase::ConnectJobFactory methods. |
349 virtual scoped_ptr<ConnectJob> NewConnectJob( | 376 virtual scoped_ptr<ConnectJob> NewConnectJob( |
350 const std::string& group_name, | 377 const std::string& group_name, |
351 const PoolBase::Request& request, | 378 const PoolBase::Request& request, |
352 ConnectJob::Delegate* delegate) const OVERRIDE; | 379 ConnectJob::Delegate* delegate) OVERRIDE; |
353 | 380 |
354 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; | 381 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; |
355 | 382 |
356 private: | 383 private: |
357 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects. | 384 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects. |
358 typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap; | 385 typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap; |
359 | 386 |
360 TransportClientSocketPool* const transport_pool_; | 387 TransportClientSocketPool* const transport_pool_; |
361 SOCKSClientSocketPool* const socks_pool_; | 388 SOCKSClientSocketPool* const socks_pool_; |
362 HttpProxyClientSocketPool* const http_proxy_pool_; | 389 HttpProxyClientSocketPool* const http_proxy_pool_; |
363 ClientSocketFactory* const client_socket_factory_; | 390 ClientSocketFactory* const client_socket_factory_; |
364 HostResolver* const host_resolver_; | 391 HostResolver* const host_resolver_; |
365 const SSLClientSocketContext context_; | 392 const SSLClientSocketContext context_; |
366 base::TimeDelta timeout_; | 393 base::TimeDelta timeout_; |
367 NetLog* net_log_; | 394 NetLog* net_log_; |
368 scoped_ptr<MessengerMap> messenger_map_; | 395 MessengerMap messenger_map_; |
369 | 396 |
370 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); | 397 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); |
371 }; | 398 }; |
372 | 399 |
373 TransportClientSocketPool* const transport_pool_; | 400 TransportClientSocketPool* const transport_pool_; |
374 SOCKSClientSocketPool* const socks_pool_; | 401 SOCKSClientSocketPool* const socks_pool_; |
375 HttpProxyClientSocketPool* const http_proxy_pool_; | 402 HttpProxyClientSocketPool* const http_proxy_pool_; |
376 PoolBase base_; | 403 PoolBase base_; |
377 const scoped_refptr<SSLConfigService> ssl_config_service_; | 404 const scoped_refptr<SSLConfigService> ssl_config_service_; |
378 | 405 |
379 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); | 406 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); |
380 }; | 407 }; |
381 | 408 |
382 } // namespace net | 409 } // namespace net |
383 | 410 |
384 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ | 411 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |