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 <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" |
| 14 #include "base/memory/scoped_vector.h" | |
|
wtc
2014/07/11 00:48:55
Delete this. You aren't using ScopedVector any mor
mshelley
2014/07/11 23:26:28
Done.
| |
| 12 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 13 #include "net/base/privacy_mode.h" | 16 #include "net/base/privacy_mode.h" |
| 14 #include "net/dns/host_resolver.h" | 17 #include "net/dns/host_resolver.h" |
| 15 #include "net/http/http_response_info.h" | 18 #include "net/http/http_response_info.h" |
| 16 #include "net/socket/client_socket_pool.h" | 19 #include "net/socket/client_socket_pool.h" |
| 17 #include "net/socket/client_socket_pool_base.h" | 20 #include "net/socket/client_socket_pool_base.h" |
| 18 #include "net/socket/client_socket_pool_histograms.h" | 21 #include "net/socket/client_socket_pool_histograms.h" |
| 19 #include "net/socket/ssl_client_socket.h" | 22 #include "net/socket/ssl_client_socket.h" |
| 20 #include "net/ssl/ssl_config_service.h" | 23 #include "net/ssl/ssl_config_service.h" |
| 21 | 24 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 const SSLConfig ssl_config_; | 90 const SSLConfig ssl_config_; |
| 88 const PrivacyMode privacy_mode_; | 91 const PrivacyMode privacy_mode_; |
| 89 const int load_flags_; | 92 const int load_flags_; |
| 90 const bool force_spdy_over_ssl_; | 93 const bool force_spdy_over_ssl_; |
| 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 |
| 100 // SSLConnectJobMessenger handles communication between concurrent | |
| 101 // SSLConnectJobs that share the same SSL session cache key. | |
| 102 // | |
| 103 // SSLConnectJobMessengers tell the session cache when a certain | |
| 104 // connection should be monitored for success or failure, and | |
| 105 // tell SSLConnectJobs when to pause or resume thier connections. | |
| 106 class NET_EXPORT_PRIVATE SSLConnectJobMessenger { | |
| 107 public: | |
| 108 struct SocketAndCallback { | |
| 109 SSLClientSocket* socket; | |
| 110 base::Closure callback; | |
| 111 | |
| 112 SocketAndCallback(SSLClientSocket* ssl_socket, | |
| 113 base::Closure job_resumption_callback) | |
| 114 : socket(ssl_socket), callback(job_resumption_callback) {} | |
|
wtc
2014/07/11 00:48:55
List the constructor before data members. See the
mshelley
2014/07/11 23:26:28
Done.
| |
| 115 }; | |
| 116 | |
| 117 typedef std::vector<SocketAndCallback> SSLPendingSocketsAndCallbacks; | |
| 118 | |
| 119 // Returns true if the given |ssl_socket| should continue its | |
| 120 // SSL connection. | |
| 121 bool CanProceed(SSLClientSocket* ssl_socket); | |
| 122 | |
| 123 // Informs the session cache that it should notify the SSLConnectJobMessenger | |
| 124 // upon the completion of |ssl_socket|'s connection. | |
| 125 void MonitorConnectionResult(SSLClientSocket* ssl_socket); | |
| 126 | |
| 127 // Adds the socket and its associated callback to the SSLConnectJobMessenger's | |
| 128 // list of pending sockets and callbacks. | |
| 129 void AddPendingSocket(SSLClientSocket* socket, const base::Closure& callback); | |
| 130 | |
| 131 // Processes pending callbacks when a socket successfully completes | |
| 132 // its connection. | |
| 133 void OnJobSucceeded(); | |
| 134 | |
| 135 // Processes pending callbacks when a socket encounters an error | |
| 136 // while completing its connection. | |
| 137 void OnJobFailed(); | |
|
wtc
2014/07/11 00:48:55
I think OnJobSucceeded and OnJobFailed can be priv
mshelley
2014/07/11 23:26:27
Done.
| |
| 138 | |
| 139 private: | |
| 140 // Runs all callbacks stored in |pending_sockets_and_callbacks_|. | |
| 141 void RunAllJobs(std::vector<SocketAndCallback>& pending_socket_and_callbacks); | |
|
wtc
2014/07/11 00:48:55
RunAllJobs => RunAllCallbacks
The input should be
mshelley
2014/07/11 23:26:28
Done.
| |
| 142 | |
| 143 SSLPendingSocketsAndCallbacks pending_sockets_and_callbacks_; | |
| 144 std::vector<SSLClientSocket*> connecting_sockets_; | |
|
wtc
2014/07/11 00:48:55
IMPORTANT: if there can be only one connecting soc
mshelley
2014/07/11 23:26:28
Done.
| |
| 145 }; | |
| 146 | |
| 97 // SSLConnectJob handles the SSL handshake after setting up the underlying | 147 // SSLConnectJob handles the SSL handshake after setting up the underlying |
| 98 // connection as specified in the params. | 148 // connection as specified in the params. |
| 99 class SSLConnectJob : public ConnectJob { | 149 class SSLConnectJob : public ConnectJob { |
| 100 public: | 150 public: |
| 101 SSLConnectJob( | 151 // Note: the SSLConnectJob does not own |messenger|. |
| 102 const std::string& group_name, | 152 // so it must outlive the job. |
| 103 RequestPriority priority, | 153 SSLConnectJob(const std::string& group_name, |
| 104 const scoped_refptr<SSLSocketParams>& params, | 154 RequestPriority priority, |
| 105 const base::TimeDelta& timeout_duration, | 155 const scoped_refptr<SSLSocketParams>& params, |
| 106 TransportClientSocketPool* transport_pool, | 156 const base::TimeDelta& timeout_duration, |
| 107 SOCKSClientSocketPool* socks_pool, | 157 TransportClientSocketPool* transport_pool, |
| 108 HttpProxyClientSocketPool* http_proxy_pool, | 158 SOCKSClientSocketPool* socks_pool, |
| 109 ClientSocketFactory* client_socket_factory, | 159 HttpProxyClientSocketPool* http_proxy_pool, |
| 110 HostResolver* host_resolver, | 160 ClientSocketFactory* client_socket_factory, |
| 111 const SSLClientSocketContext& context, | 161 HostResolver* host_resolver, |
| 112 Delegate* delegate, | 162 const SSLClientSocketContext& context, |
| 113 NetLog* net_log); | 163 SSLConnectJobMessenger* messenger, |
| 164 Delegate* delegate, | |
| 165 NetLog* net_log); | |
| 114 virtual ~SSLConnectJob(); | 166 virtual ~SSLConnectJob(); |
| 115 | 167 |
| 116 // ConnectJob methods. | 168 // ConnectJob methods. |
| 117 virtual LoadState GetLoadState() const OVERRIDE; | 169 virtual LoadState GetLoadState() const OVERRIDE; |
| 118 | 170 |
| 119 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; | 171 virtual void GetAdditionalErrorState(ClientSocketHandle * handle) OVERRIDE; |
| 120 | 172 |
| 121 private: | 173 private: |
| 122 enum State { | 174 enum State { |
| 123 STATE_TRANSPORT_CONNECT, | 175 STATE_TRANSPORT_CONNECT, |
| 124 STATE_TRANSPORT_CONNECT_COMPLETE, | 176 STATE_TRANSPORT_CONNECT_COMPLETE, |
| 125 STATE_SOCKS_CONNECT, | 177 STATE_SOCKS_CONNECT, |
| 126 STATE_SOCKS_CONNECT_COMPLETE, | 178 STATE_SOCKS_CONNECT_COMPLETE, |
| 127 STATE_TUNNEL_CONNECT, | 179 STATE_TUNNEL_CONNECT, |
| 128 STATE_TUNNEL_CONNECT_COMPLETE, | 180 STATE_TUNNEL_CONNECT_COMPLETE, |
| 181 STATE_CREATE_SSL_SOCKET, | |
| 182 STATE_CHECK_FOR_RESUME, | |
| 129 STATE_SSL_CONNECT, | 183 STATE_SSL_CONNECT, |
| 130 STATE_SSL_CONNECT_COMPLETE, | 184 STATE_SSL_CONNECT_COMPLETE, |
| 131 STATE_NONE, | 185 STATE_NONE, |
| 132 }; | 186 }; |
| 133 | 187 |
| 134 void OnIOComplete(int result); | 188 void OnIOComplete(int result); |
| 135 | 189 |
| 136 // Runs the state transition loop. | 190 // Runs the state transition loop. |
| 137 int DoLoop(int result); | 191 int DoLoop(int result); |
| 138 | 192 |
| 139 int DoTransportConnect(); | 193 int DoTransportConnect(); |
| 140 int DoTransportConnectComplete(int result); | 194 int DoTransportConnectComplete(int result); |
| 141 int DoSOCKSConnect(); | 195 int DoSOCKSConnect(); |
| 142 int DoSOCKSConnectComplete(int result); | 196 int DoSOCKSConnectComplete(int result); |
| 143 int DoTunnelConnect(); | 197 int DoTunnelConnect(); |
| 144 int DoTunnelConnectComplete(int result); | 198 int DoTunnelConnectComplete(int result); |
| 199 int DoCreateSSLSocket(); | |
| 200 int DoCheckForResume(); | |
| 145 int DoSSLConnect(); | 201 int DoSSLConnect(); |
| 146 int DoSSLConnectComplete(int result); | 202 int DoSSLConnectComplete(int result); |
| 147 | 203 |
| 204 // Tells a waiting SSLConnectJob to resume its SSL connection. | |
| 205 void ResumeSSLConnection(); | |
| 206 | |
| 148 // Returns the initial state for the state machine based on the | 207 // Returns the initial state for the state machine based on the |
| 149 // |connection_type|. | 208 // |connection_type|. |
| 150 static State GetInitialState(SSLSocketParams::ConnectionType connection_type); | 209 static State GetInitialState(SSLSocketParams::ConnectionType connection_type); |
| 151 | 210 |
| 152 // Starts the SSL connection process. Returns OK on success and | 211 // Starts the SSL connection process. Returns OK on success and |
| 153 // ERR_IO_PENDING if it cannot immediately service the request. | 212 // ERR_IO_PENDING if it cannot immediately service the request. |
| 154 // Otherwise, it returns a net error code. | 213 // Otherwise, it returns a net error code. |
| 155 virtual int ConnectInternal() OVERRIDE; | 214 virtual int ConnectInternal() OVERRIDE; |
| 156 | 215 |
| 157 scoped_refptr<SSLSocketParams> params_; | 216 scoped_refptr<SSLSocketParams> params_; |
| 158 TransportClientSocketPool* const transport_pool_; | 217 TransportClientSocketPool* const transport_pool_; |
| 159 SOCKSClientSocketPool* const socks_pool_; | 218 SOCKSClientSocketPool* const socks_pool_; |
| 160 HttpProxyClientSocketPool* const http_proxy_pool_; | 219 HttpProxyClientSocketPool* const http_proxy_pool_; |
| 161 ClientSocketFactory* const client_socket_factory_; | 220 ClientSocketFactory* const client_socket_factory_; |
| 162 HostResolver* const host_resolver_; | 221 HostResolver* const host_resolver_; |
| 163 | 222 |
| 164 const SSLClientSocketContext context_; | 223 const SSLClientSocketContext context_; |
| 165 | 224 |
| 166 State next_state_; | 225 State next_state_; |
| 167 CompletionCallback callback_; | 226 CompletionCallback io_callback_; |
| 168 scoped_ptr<ClientSocketHandle> transport_socket_handle_; | 227 scoped_ptr<ClientSocketHandle> transport_socket_handle_; |
| 169 scoped_ptr<SSLClientSocket> ssl_socket_; | 228 scoped_ptr<SSLClientSocket> ssl_socket_; |
| 170 | 229 |
| 230 SSLConnectJobMessenger* messenger_; | |
| 171 HttpResponseInfo error_response_info_; | 231 HttpResponseInfo error_response_info_; |
| 172 | 232 |
| 233 base::WeakPtrFactory<SSLConnectJob> weak_factory_; | |
| 234 | |
| 173 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); | 235 DISALLOW_COPY_AND_ASSIGN(SSLConnectJob); |
| 174 }; | 236 }; |
| 175 | 237 |
| 176 class NET_EXPORT_PRIVATE SSLClientSocketPool | 238 class NET_EXPORT_PRIVATE SSLClientSocketPool |
| 177 : public ClientSocketPool, | 239 : public ClientSocketPool, |
| 178 public HigherLayeredPool, | 240 public HigherLayeredPool, |
| 179 public SSLConfigService::Observer { | 241 public SSLConfigService::Observer { |
| 180 public: | 242 public: |
| 181 typedef SSLSocketParams SocketParams; | 243 typedef SSLSocketParams SocketParams; |
| 182 | 244 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 // LowerLayeredPool implementation. | 308 // LowerLayeredPool implementation. |
| 247 virtual bool IsStalled() const OVERRIDE; | 309 virtual bool IsStalled() const OVERRIDE; |
| 248 | 310 |
| 249 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; | 311 virtual void AddHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; |
| 250 | 312 |
| 251 virtual void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; | 313 virtual void RemoveHigherLayeredPool(HigherLayeredPool* higher_pool) OVERRIDE; |
| 252 | 314 |
| 253 // HigherLayeredPool implementation. | 315 // HigherLayeredPool implementation. |
| 254 virtual bool CloseOneIdleConnection() OVERRIDE; | 316 virtual bool CloseOneIdleConnection() OVERRIDE; |
| 255 | 317 |
| 318 // Enable SSLConnectJob waiting if |enable| is true. | |
| 319 static NET_EXPORT void EnableConnectJobWaiting(bool enable); | |
| 320 | |
| 321 static NET_EXPORT bool GetEnableConnectJobWaiting(); | |
|
wtc
2014/07/11 00:48:55
These setter and getter methods should be named in
mshelley
2014/07/11 23:26:27
Done.
| |
| 322 | |
| 256 private: | 323 private: |
| 257 typedef ClientSocketPoolBase<SSLSocketParams> PoolBase; | 324 typedef ClientSocketPoolBase<SSLSocketParams> PoolBase; |
| 258 | 325 |
| 259 // SSLConfigService::Observer implementation. | 326 // SSLConfigService::Observer implementation. |
| 260 | 327 |
| 261 // When the user changes the SSL config, we flush all idle sockets so they | 328 // When the user changes the SSL config, we flush all idle sockets so they |
| 262 // won't get re-used. | 329 // won't get re-used. |
| 263 virtual void OnSSLConfigChanged() OVERRIDE; | 330 virtual void OnSSLConfigChanged() OVERRIDE; |
| 264 | 331 |
| 265 class SSLConnectJobFactory : public PoolBase::ConnectJobFactory { | 332 class SSLConnectJobFactory : public PoolBase::ConnectJobFactory { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 277 | 344 |
| 278 // ClientSocketPoolBase::ConnectJobFactory methods. | 345 // ClientSocketPoolBase::ConnectJobFactory methods. |
| 279 virtual scoped_ptr<ConnectJob> NewConnectJob( | 346 virtual scoped_ptr<ConnectJob> NewConnectJob( |
| 280 const std::string& group_name, | 347 const std::string& group_name, |
| 281 const PoolBase::Request& request, | 348 const PoolBase::Request& request, |
| 282 ConnectJob::Delegate* delegate) const OVERRIDE; | 349 ConnectJob::Delegate* delegate) const OVERRIDE; |
| 283 | 350 |
| 284 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; | 351 virtual base::TimeDelta ConnectionTimeout() const OVERRIDE; |
| 285 | 352 |
| 286 private: | 353 private: |
| 354 // Maps SSLConnectJob cache keys to SSLConnectJobMessenger objects. | |
| 355 typedef std::map<std::string, SSLConnectJobMessenger*> MessengerMap; | |
| 356 | |
| 287 TransportClientSocketPool* const transport_pool_; | 357 TransportClientSocketPool* const transport_pool_; |
| 288 SOCKSClientSocketPool* const socks_pool_; | 358 SOCKSClientSocketPool* const socks_pool_; |
| 289 HttpProxyClientSocketPool* const http_proxy_pool_; | 359 HttpProxyClientSocketPool* const http_proxy_pool_; |
| 290 ClientSocketFactory* const client_socket_factory_; | 360 ClientSocketFactory* const client_socket_factory_; |
| 291 HostResolver* const host_resolver_; | 361 HostResolver* const host_resolver_; |
| 292 const SSLClientSocketContext context_; | 362 const SSLClientSocketContext context_; |
| 293 base::TimeDelta timeout_; | 363 base::TimeDelta timeout_; |
| 294 NetLog* net_log_; | 364 NetLog* net_log_; |
| 365 scoped_ptr<MessengerMap> messenger_map_; | |
|
wtc
2014/07/11 00:48:55
This doesn't need to be a scoped_ptr:
Messenger
mshelley
2014/07/11 23:26:27
Here I think it does need to be a pointer because
| |
| 295 | 366 |
| 296 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); | 367 DISALLOW_COPY_AND_ASSIGN(SSLConnectJobFactory); |
| 297 }; | 368 }; |
| 298 | 369 |
| 299 TransportClientSocketPool* const transport_pool_; | 370 TransportClientSocketPool* const transport_pool_; |
| 300 SOCKSClientSocketPool* const socks_pool_; | 371 SOCKSClientSocketPool* const socks_pool_; |
| 301 HttpProxyClientSocketPool* const http_proxy_pool_; | 372 HttpProxyClientSocketPool* const http_proxy_pool_; |
| 302 PoolBase base_; | 373 PoolBase base_; |
| 303 const scoped_refptr<SSLConfigService> ssl_config_service_; | 374 const scoped_refptr<SSLConfigService> ssl_config_service_; |
| 304 | 375 |
| 376 static bool enable_connect_job_waiting_; | |
| 377 | |
| 305 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); | 378 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); |
| 306 }; | 379 }; |
| 307 | 380 |
| 308 } // namespace net | 381 } // namespace net |
| 309 | 382 |
| 310 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ | 383 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ |
| OLD | NEW |