Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: net/socket/ssl_client_socket_pool.h

Issue 364943002: Makes waiting SSLConnectJobs use the message loops to resume their connection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved documentation and made some methods private. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 SSLClientSocket* socket; 109 SSLClientSocket* socket;
110 base::Closure callback; 110 base::Closure callback;
111 111
112 SocketAndCallback(SSLClientSocket* ssl_socket, 112 SocketAndCallback(SSLClientSocket* ssl_socket,
113 base::Closure job_resumption_callback) 113 base::Closure job_resumption_callback)
114 : socket(ssl_socket), callback(job_resumption_callback) {} 114 : socket(ssl_socket), callback(job_resumption_callback) {}
115 }; 115 };
116 116
117 typedef std::vector<SocketAndCallback> SSLPendingSocketsAndCallbacks; 117 typedef std::vector<SocketAndCallback> SSLPendingSocketsAndCallbacks;
118 118
119 // Returns true if |ssl_socket|'s Connect() method should be called. 119 SSLConnectJobMessenger();
120
121 // Returns true if the given |ssl_socket| should continue its
122 // SSL connection.
120 bool CanProceed(SSLClientSocket* ssl_socket); 123 bool CanProceed(SSLClientSocket* ssl_socket);
121 124
122 // Configure the SSLConnectJobMessenger to begin monitoring |ssl_socket|'s 125 // Configure the SSLConnectJobMessenger to begin monitoring |ssl_socket|'s
123 // connection status. After a successful connection, or an error, 126 // connection status. After a successful connection, or an error,
124 // the messenger will determine which sockets that have been added 127 // the messenger will determine which sockets that have been added
125 // via AddPendingSocket() to allow to proceed, notifying the associated 128 // via AddPendingSocket() to allow to proceed, notifying the associated
126 // callback asynchronously, so that the caller can call Connect() on them. 129 // callback asynchronously, so that the caller can call Connect() on them.
127 void MonitorConnectionResult(SSLClientSocket* ssl_socket); 130 void MonitorConnectionResult(SSLClientSocket* ssl_socket);
128 131
129 // Adds |socket| to the list of sockets waiting to Connect(). When 132 // Adds |socket| to the list of sockets waiting to Connect(). When
130 // the messenger has determined that it's an appropriate time for |socket| 133 // the messenger has determined that it's an appropriate time for |socket|
131 // to connect, it will asynchronously invoke |callback|. Callers should 134 // to connect, it will asynchronously invoke |callback|. Callers should
132 // then proceed to call Connect() and establish the socket. 135 // then proceed to call Connect() and establish the socket.
133 // 136 //
134 // Note: It is an error to call AddPendingSocket() without having first 137 // Note: It is an error to call AddPendingSocket() without having first
135 // called MonitorConnectionResult() and configuring a socket that WILL 138 // called MonitorConnectionResult() and configuring a socket that WILL
136 // have Connect() called on it. 139 // have Connect() called on it.
137 void AddPendingSocket(SSLClientSocket* socket, const base::Closure& callback); 140 void AddPendingSocket(SSLClientSocket* socket, const base::Closure& callback);
138 141
142 // Posts a task to process pending callbacks when a socket encounters an error
143 // while completing its connection.
144 void OnJobFailed();
145
146 private:
139 // Processes pending callbacks when a socket successfully completes 147 // Processes pending callbacks when a socket successfully completes
140 // its connection. 148 // its connection.
141 void OnJobSucceeded(); 149 void OnJobSucceeded();
142 150
143 // Processes pending callbacks when a socket encounters an error 151 // Determines which pending socket should be the next leading connection,
144 // while completing its connection. 152 // and runs that socket's resumption callback.
145 void OnJobFailed(); 153 void ConnectNewLeader();
146 154
147 private:
148 // Runs all callbacks stored in |pending_sockets_and_callbacks_|. 155 // Runs all callbacks stored in |pending_sockets_and_callbacks_|.
149 void RunAllJobs(std::vector<SocketAndCallback>& pending_socket_and_callbacks); 156 void RunAllJobs(
157 std::vector<SocketAndCallback>& pending_sockets_and_callbacks);
150 158
159 base::WeakPtrFactory<SSLConnectJobMessenger> weak_factory_;
151 SSLPendingSocketsAndCallbacks pending_sockets_and_callbacks_; 160 SSLPendingSocketsAndCallbacks pending_sockets_and_callbacks_;
152 std::vector<SSLClientSocket*> connecting_sockets_; 161 std::vector<SSLClientSocket*> connecting_sockets_;
153 }; 162 };
154 163
155 // SSLConnectJob handles the SSL handshake after setting up the underlying 164 // SSLConnectJob handles the SSL handshake after setting up the underlying
156 // connection as specified in the params. 165 // connection as specified in the params.
157 class SSLConnectJob : public ConnectJob { 166 class SSLConnectJob : public ConnectJob {
158 public: 167 public:
159 // Note: the SSLConnectJob does not own |messenger|. 168 // Note: the SSLConnectJob does not own |messenger|.
160 // so it must outlive the job. 169 // so it must outlive the job.
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 const scoped_refptr<SSLConfigService> ssl_config_service_; 391 const scoped_refptr<SSLConfigService> ssl_config_service_;
383 392
384 static bool enable_connect_job_waiting_; 393 static bool enable_connect_job_waiting_;
385 394
386 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool); 395 DISALLOW_COPY_AND_ASSIGN(SSLClientSocketPool);
387 }; 396 };
388 397
389 } // namespace net 398 } // namespace net
390 399
391 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_ 400 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698