Chromium Code Reviews| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 struct SocketAndCallback { | 107 struct SocketAndCallback { |
| 108 SocketAndCallback(SSLClientSocket* ssl_socket, | 108 SocketAndCallback(SSLClientSocket* ssl_socket, |
| 109 const base::Closure& job_resumption_callback); | 109 const base::Closure& job_resumption_callback); |
| 110 ~SocketAndCallback(); | 110 ~SocketAndCallback(); |
| 111 | 111 |
| 112 SSLClientSocket* socket; | 112 SSLClientSocket* socket; |
| 113 base::Closure callback; | 113 base::Closure callback; |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 typedef std::vector<SocketAndCallback> SSLPendingSocketsAndCallbacks; | 116 typedef std::vector<SocketAndCallback> SSLPendingSocketsAndCallbacks; |
| 117 typedef base::Callback<void(std::string, std::string)> | |
| 118 ConnectionCompleteCallback; | |
|
wtc
2014/08/12 14:51:01
Please document what the two string inputs to Conn
mshelley
2014/08/12 21:47:01
Done.
| |
| 117 | 119 |
| 118 SSLConnectJobMessenger(); | 120 SSLConnectJobMessenger( |
| 121 const ConnectionCompleteCallback& connection_complete_callback, | |
| 122 std::string group_name); | |
|
Ryan Sleevi
2014/08/12 00:27:43
Do you really need |group_name| to be exposed at a
wtc
2014/08/12 14:51:01
If |group_name| is needed, it should be a const re
mshelley
2014/08/12 21:47:02
Done.
| |
| 119 ~SSLConnectJobMessenger(); | 123 ~SSLConnectJobMessenger(); |
| 120 | 124 |
| 121 // Removes |socket| from the set of sockets being monitored. This | 125 // Removes |socket| from the set of sockets being monitored. This |
| 122 // guarantees that |job_resumption_callback| will not be called for | 126 // guarantees that |job_resumption_callback| will not be called for |
| 123 // the socket. | 127 // the socket. |
| 124 void RemovePendingSocket(SSLClientSocket* ssl_socket); | 128 void RemovePendingSocket(SSLClientSocket* ssl_socket); |
| 125 | 129 |
| 126 // Returns true if |ssl_socket|'s Connect() method should be called. | 130 // Returns true if |ssl_socket|'s Connect() method should be called. |
| 127 bool CanProceed(SSLClientSocket* ssl_socket); | 131 bool CanProceed(SSLClientSocket* ssl_socket); |
| 128 | 132 |
| 129 // Configures the SSLConnectJobMessenger to begin monitoring |ssl_socket|'s | 133 // Configures the SSLConnectJobMessenger to begin monitoring |ssl_socket|'s |
| 130 // connection status. After a successful connection, or an error, | 134 // connection status. After a successful connection, or an error, |
| 131 // the messenger will determine which sockets that have been added | 135 // the messenger will determine which sockets that have been added |
| 132 // via AddPendingSocket() to allow to proceed. | 136 // via AddPendingSocket() to allow to proceed. |
| 133 void MonitorConnectionResult(SSLClientSocket* ssl_socket); | 137 void MonitorConnectionResult(SSLClientSocket* ssl_socket); |
| 134 | 138 |
| 135 // Adds |socket| to the list of sockets waiting to Connect(). When | 139 // Adds |socket| to the list of sockets waiting to Connect(). When |
| 136 // the messenger has determined that it's an appropriate time for |socket| | 140 // the messenger has determined that it's an appropriate time for |socket| |
| 137 // to connect, it will invoke |callback|. | 141 // to connect, it will invoke |callback|. |
| 138 // | 142 // |
| 139 // Note: It is an error to call AddPendingSocket() without having first | 143 // Note: It is an error to call AddPendingSocket() without having first |
| 140 // called MonitorConnectionResult() and configuring a socket that WILL | 144 // called MonitorConnectionResult() and configuring a socket that WILL |
| 141 // have Connect() called on it. | 145 // have Connect() called on it. |
| 142 void AddPendingSocket(SSLClientSocket* ssl_socket, | 146 void AddPendingSocket(SSLClientSocket* ssl_socket, |
| 143 const base::Closure& callback); | 147 const base::Closure& callback); |
| 144 | 148 |
| 149 // Returns true if this SSLConnectJobMessenger still has pending | |
| 150 // connection callbacks. | |
| 151 bool IsNeeded(); | |
|
Ryan Sleevi
2014/08/12 00:27:43
Let's rename this then, to better match that it do
mshelley
2014/08/12 21:47:01
Realized I don't actually need this anymore, becau
| |
| 152 | |
| 145 private: | 153 private: |
| 146 // Processes pending callbacks when a socket completes its SSL handshake -- | 154 // Processes pending callbacks when a socket completes its SSL handshake -- |
| 147 // either successfully or unsuccessfully. | 155 // either successfully or unsuccessfully. |
| 148 void OnSSLHandshakeCompleted(); | 156 void OnSSLHandshakeCompleted(); |
| 149 | 157 |
| 150 // Runs all callbacks stored in |pending_sockets_and_callbacks_|. | 158 // Runs all callbacks stored in |pending_sockets_and_callbacks_|. |
| 151 void RunAllCallbacks( | 159 void RunAllCallbacks( |
| 152 const SSLPendingSocketsAndCallbacks& pending_socket_and_callbacks); | 160 const SSLPendingSocketsAndCallbacks& pending_socket_and_callbacks); |
| 153 | 161 |
| 154 base::WeakPtrFactory<SSLConnectJobMessenger> weak_factory_; | |
| 155 | |
| 156 SSLPendingSocketsAndCallbacks pending_sockets_and_callbacks_; | 162 SSLPendingSocketsAndCallbacks pending_sockets_and_callbacks_; |
| 157 // Note: this field is a vector to allow for future design changes. Currently, | 163 // Note: this field is a vector to allow for future design changes. Currently, |
| 158 // this vector should only ever have one entry. | 164 // this vector should only ever have one entry. |
| 159 std::vector<SSLClientSocket*> connecting_sockets_; | 165 std::vector<SSLClientSocket*> connecting_sockets_; |
| 166 | |
| 167 std::string group_name_; | |
| 168 | |
| 169 base::WeakPtrFactory<SSLConnectJobMessenger> weak_factory_; | |
| 170 | |
| 171 const ConnectionCompleteCallback connection_complete_callback_; | |
|
Ryan Sleevi
2014/08/12 00:27:42
Why const?
mshelley
2014/08/12 21:47:01
Done.
| |
| 160 }; | 172 }; |
| 161 | 173 |
| 162 // SSLConnectJob handles the SSL handshake after setting up the underlying | 174 // SSLConnectJob handles the SSL handshake after setting up the underlying |
| 163 // connection as specified in the params. | 175 // connection as specified in the params. |
| 164 class SSLConnectJob : public ConnectJob { | 176 class SSLConnectJob : public ConnectJob { |
| 165 public: | 177 public: |
| 178 // The returned messenger is a pointer to an existing messenger | |
| 179 // owned by the SSLConnectJobFactory. | |
| 180 typedef base::Callback<SSLConnectJobMessenger*(std::string, std::string)> | |
| 181 UncachedSessionCallback; | |
|
Ryan Sleevi
2014/08/12 00:27:43
I guess I'm still unclear what this means, or how
mshelley
2014/08/12 21:47:02
Done.
| |
| 182 | |
| 166 // Note: the SSLConnectJob does not own |messenger| so it must outlive the | 183 // Note: the SSLConnectJob does not own |messenger| so it must outlive the |
| 167 // job. | 184 // job. |
| 168 SSLConnectJob(const std::string& group_name, | 185 SSLConnectJob(const std::string& group_name, |
| 169 RequestPriority priority, | 186 RequestPriority priority, |
| 170 const scoped_refptr<SSLSocketParams>& params, | 187 const scoped_refptr<SSLSocketParams>& params, |
| 171 const base::TimeDelta& timeout_duration, | 188 const base::TimeDelta& timeout_duration, |
| 172 TransportClientSocketPool* transport_pool, | 189 TransportClientSocketPool* transport_pool, |
| 173 SOCKSClientSocketPool* socks_pool, | 190 SOCKSClientSocketPool* socks_pool, |
| 174 HttpProxyClientSocketPool* http_proxy_pool, | 191 HttpProxyClientSocketPool* http_proxy_pool, |
| 175 ClientSocketFactory* client_socket_factory, | 192 ClientSocketFactory* client_socket_factory, |
| 176 HostResolver* host_resolver, | 193 HostResolver* host_resolver, |
| 177 const SSLClientSocketContext& context, | 194 const SSLClientSocketContext& context, |
| 178 SSLConnectJobMessenger* messenger, | 195 UncachedSessionCallback uncached_session_callback, |
|
Ryan Sleevi
2014/08/12 00:27:43
This still feels a bit circular. Perhaps we should
mshelley
2014/08/12 21:47:02
Done.
| |
| 196 bool enable_ssl_connect_job_waiting, | |
| 179 Delegate* delegate, | 197 Delegate* delegate, |
| 180 NetLog* net_log); | 198 NetLog* net_log); |
| 181 virtual ~SSLConnectJob(); | 199 virtual ~SSLConnectJob(); |
| 182 | 200 |
| 183 // ConnectJob methods. | 201 // ConnectJob methods. |
| 184 virtual LoadState GetLoadState() const OVERRIDE; | 202 virtual LoadState GetLoadState() const OVERRIDE; |
| 185 | 203 |
| 186 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; | 204 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; |
| 187 | 205 |
| 206 void RemoveMessenger(const std::string& cache_key); | |
| 207 | |
| 188 private: | 208 private: |
| 189 enum State { | 209 enum State { |
| 190 STATE_TRANSPORT_CONNECT, | 210 STATE_TRANSPORT_CONNECT, |
| 191 STATE_TRANSPORT_CONNECT_COMPLETE, | 211 STATE_TRANSPORT_CONNECT_COMPLETE, |
| 192 STATE_SOCKS_CONNECT, | 212 STATE_SOCKS_CONNECT, |
| 193 STATE_SOCKS_CONNECT_COMPLETE, | 213 STATE_SOCKS_CONNECT_COMPLETE, |
| 194 STATE_TUNNEL_CONNECT, | 214 STATE_TUNNEL_CONNECT, |
| 195 STATE_TUNNEL_CONNECT_COMPLETE, | 215 STATE_TUNNEL_CONNECT_COMPLETE, |
| 196 STATE_CREATE_SSL_SOCKET, | 216 STATE_CREATE_SSL_SOCKET, |
| 197 STATE_CHECK_FOR_RESUME, | 217 STATE_CHECK_FOR_RESUME, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 212 int DoTunnelConnect(); | 232 int DoTunnelConnect(); |
| 213 int DoTunnelConnectComplete(int result); | 233 int DoTunnelConnectComplete(int result); |
| 214 int DoCreateSSLSocket(); | 234 int DoCreateSSLSocket(); |
| 215 int DoCheckForResume(); | 235 int DoCheckForResume(); |
| 216 int DoSSLConnect(); | 236 int DoSSLConnect(); |
| 217 int DoSSLConnectComplete(int result); | 237 int DoSSLConnectComplete(int result); |
| 218 | 238 |
| 219 // Tells a waiting SSLConnectJob to resume its SSL connection. | 239 // Tells a waiting SSLConnectJob to resume its SSL connection. |
| 220 void ResumeSSLConnection(); | 240 void ResumeSSLConnection(); |
| 221 | 241 |
| 242 // Runs a callback informing the SSLClientSocketPool that this | |
| 243 // SSLConnectJob's SSL session is not in the session cache. | |
| 244 void RunUncachedSessionCallback(std::string cache_key); | |
| 245 | |
| 222 // Returns the initial state for the state machine based on the | 246 // Returns the initial state for the state machine based on the |
| 223 // |connection_type|. | 247 // |connection_type|. |
| 224 static State GetInitialState(SSLSocketParams::ConnectionType connection_type); | 248 static State GetInitialState(SSLSocketParams::ConnectionType connection_type); |
| 225 | 249 |
| 226 // Starts the SSL connection process. Returns OK on success and | 250 // Starts the SSL connection process. Returns OK on success and |
| 227 // ERR_IO_PENDING if it cannot immediately service the request. | 251 // ERR_IO_PENDING if it cannot immediately service the request. |
| 228 // Otherwise, it returns a net error code. | 252 // Otherwise, it returns a net error code. |
| 229 virtual int ConnectInternal() OVERRIDE; | 253 virtual int ConnectInternal() OVERRIDE; |
| 230 | 254 |
| 231 scoped_refptr<SSLSocketParams> params_; | 255 scoped_refptr<SSLSocketParams> params_; |
| 232 TransportClientSocketPool* const transport_pool_; | 256 TransportClientSocketPool* const transport_pool_; |
| 233 SOCKSClientSocketPool* const socks_pool_; | 257 SOCKSClientSocketPool* const socks_pool_; |
| 234 HttpProxyClientSocketPool* const http_proxy_pool_; | 258 HttpProxyClientSocketPool* const http_proxy_pool_; |
| 235 ClientSocketFactory* const client_socket_factory_; | 259 ClientSocketFactory* const client_socket_factory_; |
| 236 HostResolver* const host_resolver_; | 260 HostResolver* const host_resolver_; |
| 237 | 261 |
| 238 const SSLClientSocketContext context_; | 262 const SSLClientSocketContext context_; |
| 239 | 263 |
| 240 State next_state_; | 264 State next_state_; |
| 241 CompletionCallback io_callback_; | 265 CompletionCallback io_callback_; |
| 242 scoped_ptr<ClientSocketHandle> transport_socket_handle_; | 266 scoped_ptr<ClientSocketHandle> transport_socket_handle_; |
| 243 scoped_ptr<SSLClientSocket> ssl_socket_; | 267 scoped_ptr<SSLClientSocket> ssl_socket_; |
| 244 | 268 |
| 245 SSLConnectJobMessenger* messenger_; | 269 SSLConnectJobMessenger* messenger_; |
| 246 HttpResponseInfo error_response_info_; | 270 HttpResponseInfo error_response_info_; |
| 247 | 271 |
| 248 base::WeakPtrFactory<SSLConnectJob> weak_factory_; | 272 base::WeakPtrFactory<SSLConnectJob> weak_factory_; |
| 249 | 273 |
| 274 SSLConnectJob::UncachedSessionCallback uncached_session_callback_; | |
| 275 bool enable_ssl_connect_job_waiting_; | |
| 276 | |
| 250 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); | 277 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); |
| 251 }; | 278 }; |
| 252 | 279 |
| 253 class NET_EXPORT_PRIVATE SSLClientSocketPool | 280 class NET_EXPORT_PRIVATE SSLClientSocketPool |
| 254 : public ClientSocketPool, | 281 : public ClientSocketPool, |
| 255 public HigherLayeredPool, | 282 public HigherLayeredPool, |
| 256 public SSLConfigService::Observer { | 283 public SSLConfigService::Observer { |
| 257 public: | 284 public: |
| 258 typedef SSLSocketParams SocketParams; | 285 typedef SSLSocketParams SocketParams; |
| 259 | 286 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 // LowerLayeredPool implementation. | 350 // LowerLayeredPool implementation. |
| 324 virtual bool IsStalled() const OVERRIDE; | 351 virtual bool IsStalled() const OVERRIDE; |
| 325 | 352 |
| 326 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; | 353 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; |
| 327 | 354 |
| 328 virtual void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; | 355 virtual void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; |
| 329 | 356 |
| 330 // HigherLayeredPool implementation. | 357 // HigherLayeredPool implementation. |
| 331 virtual bool CloseOneIdleConnection() OVERRIDE; | 358 virtual bool CloseOneIdleConnection() OVERRIDE; |
| 332 | 359 |
| 360 // Creates an SSLConnectJobMessenger for the given |cache_key| and stores it | |
| 361 // in |messenger_map_|. Returns the new SSLConnectJobMessenger. | |
| 362 SSLConnectJobMessenger* AddSSLConnectJobMessenger(std::string cache_key, | |
| 363 std::string group_name); | |
| 364 void DeleteSSLConnectJobMessenger(std::string cache_key, | |
| 365 std::string group_name); | |
| 366 | |
| 333 private: | 367 private: |
| 334 typedef ClientSocketPoolBase<SSLSocketParams> PoolBase; | 368 typedef ClientSocketPoolBase<SSLSocketParams> PoolBase; |
| 369 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects. | |
| 370 typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap; | |
| 335 | 371 |
| 336 // SSLConfigService::Observer implementation. | 372 // SSLConfigService::Observer implementation. |
| 337 | 373 |
| 338 // When the user changes the SSL config, we flush all idle sockets so they | 374 // When the user changes the SSL config, we flush all idle sockets so they |
| 339 // won't get re-used. | 375 // won't get re-used. |
| 340 virtual void OnSSLConfigChanged() OVERRIDE; | 376 virtual void OnSSLConfigChanged() OVERRIDE; |
| 341 | 377 |
| 342 class SSLConnectJobFactory : public PoolBase::ConnectJobFactory { | 378 class SSLConnectJobFactory : public PoolBase::ConnectJobFactory { |
| 343 public: | 379 public: |
| 344 SSLConnectJobFactory(TransportClientSocketPool* transport_pool, | 380 SSLConnectJobFactory( |
| 345 SOCKSClientSocketPool* socks_pool, | 381 TransportClientSocketPool* transport_pool, |
| 346 HttpProxyClientSocketPool* http_proxy_pool, | 382 SOCKSClientSocketPool* socks_pool, |
| 347 ClientSocketFactory* client_socket_factory, | 383 HttpProxyClientSocketPool* http_proxy_pool, |
| 348 HostResolver* host_resolver, | 384 ClientSocketFactory* client_socket_factory, |
| 349 const SSLClientSocketContext& context, | 385 HostResolver* host_resolver, |
| 350 bool enable_ssl_connect_job_waiting, | 386 const SSLClientSocketContext& context, |
| 351 NetLog* net_log); | 387 bool enable_ssl_connect_job_waiting, |
| 388 SSLConnectJob::UncachedSessionCallback uncached_session_callback, | |
| 389 NetLog* net_log); | |
| 352 | 390 |
| 353 virtual ~SSLConnectJobFactory(); | 391 virtual ~SSLConnectJobFactory(); |
| 354 | 392 |
| 355 // ClientSocketPoolBase::ConnectJobFactory methods. | 393 // ClientSocketPoolBase::ConnectJobFactory methods. |
| 356 virtual scoped_ptr<ConnectJob> NewConnectJob( | 394 virtual scoped_ptr<ConnectJob> NewConnectJob( |
| 357 const std::string& group_name, | 395 const std::string& group_name, |
| 358 const PoolBase::Request& request, | 396 const PoolBase::Request& request, |
| 359 ConnectJob::Delegate* delegate) const OVERRIDE; | 397 ConnectJob::Delegate* delegate) OVERRIDE; |
| 360 | 398 |
| 361 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; | 399 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; |
| 362 | 400 |
| 363 private: | 401 private: |
| 364 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects. | 402 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects. |
| 365 typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap; | 403 typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap; |
| 366 | 404 |
| 367 TransportClientSocketPool* const transport_pool_; | 405 TransportClientSocketPool* const transport_pool_; |
| 368 SOCKSClientSocketPool* const socks_pool_; | 406 SOCKSClientSocketPool* const socks_pool_; |
| 369 HttpProxyClientSocketPool* const http_proxy_pool_; | 407 HttpProxyClientSocketPool* const http_proxy_pool_; |
| 370 ClientSocketFactory* const client_socket_factory_; | 408 ClientSocketFactory* const client_socket_factory_; |
| 371 HostResolver* const host_resolver_; | 409 HostResolver* const host_resolver_; |
| 372 const SSLClientSocketContext context_; | 410 const SSLClientSocketContext context_; |
| 373 base::TimeDelta timeout_; | 411 base::TimeDelta timeout_; |
| 374 bool enable_ssl_connect_job_waiting_; | 412 bool enable_ssl_connect_job_waiting_; |
| 413 SSLConnectJob::UncachedSessionCallback uncached_session_callback_; | |
| 375 NetLog* net_log_; | 414 NetLog* net_log_; |
| 376 // |messenger_map_| is currently a pointer so that an element can be | |
| 377 // added to it inside of the const method NewConnectJob. In the future, | |
| 378 // elements will be added in a different method. | |
| 379 // TODO(mshelley) Change this to a non-pointer. | |
| 380 scoped_ptr<MessengerMap> messenger_map_; | |
| 381 | 415 |
| 382 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); | 416 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); |
| 383 }; | 417 }; |
| 384 | 418 |
| 385 TransportClientSocketPool* const transport_pool_; | 419 TransportClientSocketPool* const transport_pool_; |
| 386 SOCKSClientSocketPool* const socks_pool_; | 420 SOCKSClientSocketPool* const socks_pool_; |
| 387 HttpProxyClientSocketPool* const http_proxy_pool_; | 421 HttpProxyClientSocketPool* const http_proxy_pool_; |
| 388 PoolBase base_; | 422 PoolBase base_; |
| 389 const scoped_refptr<SSLConfigService> ssl_config_service_; | 423 const scoped_refptr<SSLConfigService> ssl_config_service_; |
| 424 MessengerMap messenger_map_; | |
| 390 | 425 |
| 391 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); | 426 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); |
| 392 }; | 427 }; |
| 393 | 428 |
| 394 } // namespace net | 429 } // namespace net |
| 395 | 430 |
| 396 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ | 431 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ |
| OLD | NEW |