OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "net/socket/ssl_client_socket_pool.h" | 5 #include "net/socket/ssl_client_socket_pool.h" |
6 | 6 |
7 #include "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
8 #include "net/socket/client_socket_factory.h" | 8 #include "net/socket/client_socket_factory.h" |
9 #include "net/socket/client_socket_handle.h" | 9 #include "net/socket/client_socket_handle.h" |
10 | 10 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 case STATE_SSL_CONNECT: | 96 case STATE_SSL_CONNECT: |
97 case STATE_SSL_CONNECT_COMPLETE: | 97 case STATE_SSL_CONNECT_COMPLETE: |
98 return LOAD_STATE_SSL_HANDSHAKE; | 98 return LOAD_STATE_SSL_HANDSHAKE; |
99 default: | 99 default: |
100 NOTREACHED(); | 100 NOTREACHED(); |
101 return LOAD_STATE_IDLE; | 101 return LOAD_STATE_IDLE; |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 int SSLConnectJob::ConnectInternal() { | 105 int SSLConnectJob::ConnectInternal() { |
106 DetermineFirstState(); | |
107 return DoLoop(OK); | |
108 } | |
109 | |
110 void SSLConnectJob::DetermineFirstState() { | |
111 switch (params_->proxy()) { | 106 switch (params_->proxy()) { |
112 case ProxyServer::SCHEME_DIRECT: | 107 case ProxyServer::SCHEME_DIRECT: |
113 next_state_ = STATE_TCP_CONNECT; | 108 next_state_ = STATE_TCP_CONNECT; |
114 break; | 109 break; |
115 case ProxyServer::SCHEME_HTTP: | 110 case ProxyServer::SCHEME_HTTP: |
116 next_state_ = STATE_TUNNEL_CONNECT; | 111 next_state_ = STATE_TUNNEL_CONNECT; |
117 break; | 112 break; |
118 case ProxyServer::SCHEME_SOCKS4: | 113 case ProxyServer::SCHEME_SOCKS4: |
119 case ProxyServer::SCHEME_SOCKS5: | 114 case ProxyServer::SCHEME_SOCKS5: |
120 next_state_ = STATE_SOCKS_CONNECT; | 115 next_state_ = STATE_SOCKS_CONNECT; |
121 break; | 116 break; |
122 default: | 117 default: |
123 NOTREACHED() << "unknown proxy type"; | 118 NOTREACHED() << "unknown proxy type"; |
124 break; | 119 break; |
125 } | 120 } |
| 121 return DoLoop(OK); |
126 } | 122 } |
127 | 123 |
128 void SSLConnectJob::OnIOComplete(int result) { | 124 void SSLConnectJob::OnIOComplete(int result) { |
129 int rv = DoLoop(result); | 125 int rv = DoLoop(result); |
130 if (rv != ERR_IO_PENDING) | 126 if (rv != ERR_IO_PENDING) |
131 NotifyDelegateOfCompletion(rv); // Deletes |this|. | 127 NotifyDelegateOfCompletion(rv); // Deletes |this|. |
132 } | 128 } |
133 | 129 |
134 int SSLConnectJob::DoLoop(int result) { | 130 int SSLConnectJob::DoLoop(int result) { |
135 DCHECK_NE(next_state_, STATE_NONE); | 131 DCHECK_NE(next_state_, STATE_NONE); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 int SSLConnectJob::DoSOCKSConnectComplete(int result) { | 203 int SSLConnectJob::DoSOCKSConnectComplete(int result) { |
208 if (result == OK) | 204 if (result == OK) |
209 next_state_ = STATE_SSL_CONNECT; | 205 next_state_ = STATE_SSL_CONNECT; |
210 | 206 |
211 return result; | 207 return result; |
212 } | 208 } |
213 | 209 |
214 int SSLConnectJob::DoTunnelConnect() { | 210 int SSLConnectJob::DoTunnelConnect() { |
215 DCHECK(http_proxy_pool_.get()); | 211 DCHECK(http_proxy_pool_.get()); |
216 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE; | 212 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE; |
| 213 |
217 transport_socket_handle_.reset(new ClientSocketHandle()); | 214 transport_socket_handle_.reset(new ClientSocketHandle()); |
218 scoped_refptr<HttpProxySocketParams> http_proxy_params = | 215 scoped_refptr<HttpProxySocketParams> http_proxy_params = |
219 params_->http_proxy_params(); | 216 params_->http_proxy_params(); |
220 return transport_socket_handle_->Init( | 217 return transport_socket_handle_->Init( |
221 group_name(), http_proxy_params, | 218 group_name(), http_proxy_params, |
222 http_proxy_params->tcp_params()->destination().priority(), &callback_, | 219 http_proxy_params->tcp_params()->destination().priority(), &callback_, |
223 http_proxy_pool_, net_log()); | 220 http_proxy_pool_, net_log()); |
224 } | 221 } |
225 | 222 |
226 int SSLConnectJob::DoTunnelConnectComplete(int result) { | 223 int SSLConnectJob::DoTunnelConnectComplete(int result) { |
227 ClientSocket* socket = transport_socket_handle_->socket(); | 224 ClientSocket* socket = transport_socket_handle_->socket(); |
228 HttpProxyClientSocket* tunnel_socket = | 225 HttpProxyClientSocket* tunnel_socket = |
229 static_cast<HttpProxyClientSocket*>(socket); | 226 static_cast<HttpProxyClientSocket*>(socket); |
230 | 227 |
231 if (result == ERR_RETRY_CONNECTION) { | |
232 DetermineFirstState(); | |
233 transport_socket_handle_->socket()->Disconnect(); | |
234 return OK; | |
235 } | |
236 | |
237 // Extract the information needed to prompt for the proxy authentication. | 228 // Extract the information needed to prompt for the proxy authentication. |
238 // so that when ClientSocketPoolBaseHelper calls |GetAdditionalErrorState|, | 229 // so that when ClientSocketPoolBaseHelper calls |GetAdditionalErrorState|, |
239 // we can easily set the state. | 230 // we can easily set the state. |
240 if (result == ERR_PROXY_AUTH_REQUESTED) | 231 if (result == ERR_PROXY_AUTH_REQUESTED) |
241 error_response_info_ = *tunnel_socket->GetResponseInfo(); | 232 error_response_info_ = *tunnel_socket->GetResponseInfo(); |
242 | 233 |
243 if (result < 0) | 234 if (result < 0) |
244 return result; | 235 return result; |
245 | 236 |
246 if (tunnel_socket->NeedsRestartWithAuth()) { | 237 DCHECK(tunnel_socket->IsConnected()); |
247 // We must have gotten an 'idle' tunnel socket that is waiting for auth. | |
248 // The HttpAuthController should have new credentials, we just need | |
249 // to retry. | |
250 next_state_ = STATE_TUNNEL_CONNECT_COMPLETE; | |
251 return tunnel_socket->RestartWithAuth(&callback_); | |
252 } | |
253 | |
254 next_state_ = STATE_SSL_CONNECT; | 238 next_state_ = STATE_SSL_CONNECT; |
255 return result; | 239 return result; |
256 } | 240 } |
257 | 241 |
258 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle * handle) { | 242 void SSLConnectJob::GetAdditionalErrorState(ClientSocketHandle * handle) { |
259 handle->set_ssl_error_response_info(error_response_info_); | 243 if (error_response_info_.headers) { |
| 244 handle->set_ssl_error_response_info(error_response_info_); |
| 245 handle->set_pending_http_proxy_connection( |
| 246 transport_socket_handle_.release()); |
| 247 } |
260 if (!ssl_connect_start_time_.is_null()) | 248 if (!ssl_connect_start_time_.is_null()) |
261 handle->set_is_ssl_error(true); | 249 handle->set_is_ssl_error(true); |
262 } | 250 } |
263 | 251 |
264 int SSLConnectJob::DoSSLConnect() { | 252 int SSLConnectJob::DoSSLConnect() { |
265 next_state_ = STATE_SSL_CONNECT_COMPLETE; | 253 next_state_ = STATE_SSL_CONNECT_COMPLETE; |
266 // Reset the timeout to just the time allowed for the SSL handshake. | 254 // Reset the timeout to just the time allowed for the SSL handshake. |
267 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); | 255 ResetTimer(base::TimeDelta::FromSeconds(kSSLHandshakeTimeoutInSeconds)); |
268 ssl_connect_start_time_ = base::TimeTicks::Now(); | 256 ssl_connect_start_time_ = base::TimeTicks::Now(); |
269 | 257 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 const std::string& group_name) const { | 412 const std::string& group_name) const { |
425 return base_.IdleSocketCountInGroup(group_name); | 413 return base_.IdleSocketCountInGroup(group_name); |
426 } | 414 } |
427 | 415 |
428 LoadState SSLClientSocketPool::GetLoadState( | 416 LoadState SSLClientSocketPool::GetLoadState( |
429 const std::string& group_name, const ClientSocketHandle* handle) const { | 417 const std::string& group_name, const ClientSocketHandle* handle) const { |
430 return base_.GetLoadState(group_name, handle); | 418 return base_.GetLoadState(group_name, handle); |
431 } | 419 } |
432 | 420 |
433 } // namespace net | 421 } // namespace net |
OLD | NEW |