| Index: net/socket/ssl_client_socket_pool.h
|
| diff --git a/net/socket/ssl_client_socket_pool.h b/net/socket/ssl_client_socket_pool.h
|
| index e03b76ade6ab5946e2d981e7d7802b1cb70d6dba..2a9e57b5330f8841b82114c07aaa39fbac949fc0 100644
|
| --- a/net/socket/ssl_client_socket_pool.h
|
| +++ b/net/socket/ssl_client_socket_pool.h
|
| @@ -5,7 +5,9 @@
|
| #ifndef NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_
|
| #define NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_
|
|
|
| +#include <map>
|
| #include <string>
|
| +#include <vector>
|
|
|
| #include "base/memory/ref_counted.h"
|
| #include "base/memory/scoped_ptr.h"
|
| @@ -94,23 +96,88 @@ class NET_EXPORT_PRIVATE SSLSocketParams
|
| DISALLOW_COPY_AND_ASSIGN(SSLSocketParams);
|
| };
|
|
|
| +// SSLConnectJobMessenger handles communication between concurrent
|
| +// SSLConnectJobs that share the same SSL session cache key.
|
| +//
|
| +// SSLConnectJobMessengers tell the session cache when a certain
|
| +// connection should be monitored for success or failure, and
|
| +// tell SSLConnectJobs when to pause or resume their connections.
|
| +class SSLConnectJobMessenger {
|
| + public:
|
| + struct SocketAndCallback {
|
| + SocketAndCallback(SSLClientSocket* ssl_socket,
|
| + const base::Closure& job_resumption_callback);
|
| + ~SocketAndCallback();
|
| +
|
| + SSLClientSocket* socket;
|
| + base::Closure callback;
|
| + };
|
| +
|
| + typedef std::vector<SocketAndCallback> SSLPendingSocketsAndCallbacks;
|
| +
|
| + SSLConnectJobMessenger();
|
| + ~SSLConnectJobMessenger();
|
| +
|
| + // Removes |socket| from the set of sockets being monitored. This
|
| + // guarantees that |job_resumption_callback| will not be called for
|
| + // the socket.
|
| + void RemovePendingSocket(SSLClientSocket* ssl_socket);
|
| +
|
| + // Returns true if |ssl_socket|'s Connect() method should be called.
|
| + bool CanProceed(SSLClientSocket* ssl_socket);
|
| +
|
| + // Configures the SSLConnectJobMessenger to begin monitoring |ssl_socket|'s
|
| + // connection status. After a successful connection, or an error,
|
| + // the messenger will determine which sockets that have been added
|
| + // via AddPendingSocket() to allow to proceed.
|
| + void MonitorConnectionResult(SSLClientSocket* ssl_socket);
|
| +
|
| + // Adds |socket| to the list of sockets waiting to Connect(). When
|
| + // the messenger has determined that it's an appropriate time for |socket|
|
| + // to connect, it will asynchronously invoke |callback|.
|
| + //
|
| + // Note: It is an error to call AddPendingSocket() without having first
|
| + // called MonitorConnectionResult() and configuring a socket that WILL
|
| + // have Connect() called on it.
|
| + void AddPendingSocket(SSLClientSocket* ssl_socket,
|
| + const base::Closure& callback);
|
| +
|
| + private:
|
| + // Processes pending callbacks when a socket completes its SSL handshake --
|
| + // either successfully or unsuccessfully.
|
| + void OnSSLHandshakeCompleted();
|
| +
|
| + // Runs all callbacks stored in |pending_sockets_and_callbacks_|.
|
| + void RunAllCallbacks(
|
| + const SSLPendingSocketsAndCallbacks& pending_socket_and_callbacks);
|
| +
|
| + base::WeakPtrFactory<SSLConnectJobMessenger> weak_factory_;
|
| +
|
| + SSLPendingSocketsAndCallbacks pending_sockets_and_callbacks_;
|
| + // Note: this field is a vector to allow for future design changes. Currently,
|
| + // this vector should only ever have one entry.
|
| + std::vector<SSLClientSocket*> connecting_sockets_;
|
| +};
|
| +
|
| // SSLConnectJob handles the SSL handshake after setting up the underlying
|
| // connection as specified in the params.
|
| class SSLConnectJob : public ConnectJob {
|
| public:
|
| - SSLConnectJob(
|
| - const std::string& group_name,
|
| - RequestPriority priority,
|
| - const scoped_refptr<SSLSocketParams>& params,
|
| - const base::TimeDelta& timeout_duration,
|
| - TransportClientSocketPool* transport_pool,
|
| - SOCKSClientSocketPool* socks_pool,
|
| - HttpProxyClientSocketPool* http_proxy_pool,
|
| - ClientSocketFactory* client_socket_factory,
|
| - HostResolver* host_resolver,
|
| - const SSLClientSocketContext& context,
|
| - Delegate* delegate,
|
| - NetLog* net_log);
|
| + // Note: the SSLConnectJob does not own |messenger| so it must outlive the
|
| + // job.
|
| + SSLConnectJob(const std::string& group_name,
|
| + RequestPriority priority,
|
| + const scoped_refptr<SSLSocketParams>& params,
|
| + const base::TimeDelta& timeout_duration,
|
| + TransportClientSocketPool* transport_pool,
|
| + SOCKSClientSocketPool* socks_pool,
|
| + HttpProxyClientSocketPool* http_proxy_pool,
|
| + ClientSocketFactory* client_socket_factory,
|
| + HostResolver* host_resolver,
|
| + const SSLClientSocketContext& context,
|
| + SSLConnectJobMessenger* messenger,
|
| + Delegate* delegate,
|
| + NetLog* net_log);
|
| virtual ~SSLConnectJob();
|
|
|
| // ConnectJob methods.
|
| @@ -126,6 +193,8 @@ class SSLConnectJob : public ConnectJob {
|
| STATE_SOCKS_CONNECT_COMPLETE,
|
| STATE_TUNNEL_CONNECT,
|
| STATE_TUNNEL_CONNECT_COMPLETE,
|
| + STATE_CREATE_SSL_SOCKET,
|
| + STATE_CHECK_FOR_RESUME,
|
| STATE_SSL_CONNECT,
|
| STATE_SSL_CONNECT_COMPLETE,
|
| STATE_NONE,
|
| @@ -142,9 +211,14 @@ class SSLConnectJob : public ConnectJob {
|
| int DoSOCKSConnectComplete(int result);
|
| int DoTunnelConnect();
|
| int DoTunnelConnectComplete(int result);
|
| + int DoCreateSSLSocket();
|
| + int DoCheckForResume();
|
| int DoSSLConnect();
|
| int DoSSLConnectComplete(int result);
|
|
|
| + // Tells a waiting SSLConnectJob to resume its SSL connection.
|
| + void ResumeSSLConnection();
|
| +
|
| // Returns the initial state for the state machine based on the
|
| // |connection_type|.
|
| static State GetInitialState(SSLSocketParams::ConnectionType connection_type);
|
| @@ -164,12 +238,15 @@ class SSLConnectJob : public ConnectJob {
|
| const SSLClientSocketContext context_;
|
|
|
| State next_state_;
|
| - CompletionCallback callback_;
|
| + CompletionCallback io_callback_;
|
| scoped_ptr<ClientSocketHandle> transport_socket_handle_;
|
| scoped_ptr<SSLClientSocket> ssl_socket_;
|
|
|
| + SSLConnectJobMessenger* messenger_;
|
| HttpResponseInfo error_response_info_;
|
|
|
| + base::WeakPtrFactory<SSLConnectJob> weak_factory_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(SSLConnectJob);
|
| };
|
|
|
| @@ -182,22 +259,22 @@ class NET_EXPORT_PRIVATE SSLClientSocketPool
|
|
|
| // Only the pools that will be used are required. i.e. if you never
|
| // try to create an SSL over SOCKS socket, |socks_pool| may be NULL.
|
| - SSLClientSocketPool(
|
| - int max_sockets,
|
| - int max_sockets_per_group,
|
| - ClientSocketPoolHistograms* histograms,
|
| - HostResolver* host_resolver,
|
| - CertVerifier* cert_verifier,
|
| - ServerBoundCertService* server_bound_cert_service,
|
| - TransportSecurityState* transport_security_state,
|
| - CTVerifier* cert_transparency_verifier,
|
| - const std::string& ssl_session_cache_shard,
|
| - ClientSocketFactory* client_socket_factory,
|
| - TransportClientSocketPool* transport_pool,
|
| - SOCKSClientSocketPool* socks_pool,
|
| - HttpProxyClientSocketPool* http_proxy_pool,
|
| - SSLConfigService* ssl_config_service,
|
| - NetLog* net_log);
|
| + SSLClientSocketPool(int max_sockets,
|
| + int max_sockets_per_group,
|
| + ClientSocketPoolHistograms* histograms,
|
| + HostResolver* host_resolver,
|
| + CertVerifier* cert_verifier,
|
| + ServerBoundCertService* server_bound_cert_service,
|
| + TransportSecurityState* transport_security_state,
|
| + CTVerifier* cert_transparency_verifier,
|
| + const std::string& ssl_session_cache_shard,
|
| + ClientSocketFactory* client_socket_factory,
|
| + TransportClientSocketPool* transport_pool,
|
| + SOCKSClientSocketPool* socks_pool,
|
| + HttpProxyClientSocketPool* http_proxy_pool,
|
| + SSLConfigService* ssl_config_service,
|
| + bool enable_ssl_connect_job_waiting,
|
| + NetLog* net_log);
|
|
|
| virtual ~SSLClientSocketPool();
|
|
|
| @@ -264,16 +341,16 @@ class NET_EXPORT_PRIVATE SSLClientSocketPool
|
|
|
| class SSLConnectJobFactory : public PoolBase::ConnectJobFactory {
|
| public:
|
| - SSLConnectJobFactory(
|
| - TransportClientSocketPool* transport_pool,
|
| - SOCKSClientSocketPool* socks_pool,
|
| - HttpProxyClientSocketPool* http_proxy_pool,
|
| - ClientSocketFactory* client_socket_factory,
|
| - HostResolver* host_resolver,
|
| - const SSLClientSocketContext& context,
|
| - NetLog* net_log);
|
| + SSLConnectJobFactory(TransportClientSocketPool* transport_pool,
|
| + SOCKSClientSocketPool* socks_pool,
|
| + HttpProxyClientSocketPool* http_proxy_pool,
|
| + ClientSocketFactory* client_socket_factory,
|
| + HostResolver* host_resolver,
|
| + const SSLClientSocketContext& context,
|
| + bool enable_ssl_connect_job_waiting,
|
| + NetLog* net_log);
|
|
|
| - virtual ~SSLConnectJobFactory() {}
|
| + virtual ~SSLConnectJobFactory();
|
|
|
| // ClientSocketPoolBase::ConnectJobFactory methods.
|
| virtual scoped_ptr<ConnectJob> NewConnectJob(
|
| @@ -284,6 +361,9 @@ class NET_EXPORT_PRIVATE SSLClientSocketPool
|
| virtual base::TimeDelta ConnectionTimeout() const OVERRIDE;
|
|
|
| private:
|
| + // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects.
|
| + typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap;
|
| +
|
| TransportClientSocketPool* const transport_pool_;
|
| SOCKSClientSocketPool* const socks_pool_;
|
| HttpProxyClientSocketPool* const http_proxy_pool_;
|
| @@ -291,7 +371,13 @@ class NET_EXPORT_PRIVATE SSLClientSocketPool
|
| HostResolver* const host_resolver_;
|
| const SSLClientSocketContext context_;
|
| base::TimeDelta timeout_;
|
| + bool enable_ssl_connect_job_waiting_;
|
| NetLog* net_log_;
|
| + // |messenger_map_| is currently a pointer so that an element can be
|
| + // added to it inside of the const method NewConnectJob. In the future,
|
| + // elements will be added in a different method.
|
| + // TODO(mshelley) Change this to a non-pointer.
|
| + scoped_ptr<MessengerMap> messenger_map_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory);
|
| };
|
|
|