OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/http/http_stream_factory_impl_job.h" | 5 #include "net/http/http_stream_factory_impl_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 session_->http_server_properties(); | 174 session_->http_server_properties(); |
175 if (http_server_properties && | 175 if (http_server_properties && |
176 http_server_properties->SupportsSpdy(origin_server)) { | 176 http_server_properties->SupportsSpdy(origin_server)) { |
177 num_streams_ = 1; | 177 num_streams_ = 1; |
178 } else { | 178 } else { |
179 num_streams_ = num_streams; | 179 num_streams_ = num_streams; |
180 } | 180 } |
181 return StartInternal(); | 181 return StartInternal(); |
182 } | 182 } |
183 | 183 |
184 int HttpStreamFactoryImpl::Job::RestartTunnelWithProxyAuth( | 184 int HttpStreamFactoryImpl::Job::RestartTunnelWithProxyAuth() { |
185 const AuthCredentials& credentials) { | 185 // We run this asynchronously to ensure that we don't invoke |
186 DCHECK(establishing_tunnel_); | 186 // the callback (which might cause the caller to be deleted) |
187 next_state_ = STATE_RESTART_TUNNEL_AUTH; | 187 // while the caller is waiting for this method to return. |
188 stream_.reset(); | 188 MessageLoop::current()->PostTask( |
189 return RunLoop(OK); | 189 FROM_HERE, |
| 190 base::Bind(&HttpStreamFactoryImpl::Job::DoRestartTunnelWithProxyAuth, |
| 191 ptr_factory_.GetWeakPtr())); |
| 192 return ERR_IO_PENDING; |
| 193 } |
| 194 |
| 195 void HttpStreamFactoryImpl::Job::DoRestartTunnelWithProxyAuth() { |
| 196 tunnel_auth_handled_callback_.Run(OK); |
| 197 tunnel_auth_handled_callback_.Reset(); |
190 } | 198 } |
191 | 199 |
192 LoadState HttpStreamFactoryImpl::Job::GetLoadState() const { | 200 LoadState HttpStreamFactoryImpl::Job::GetLoadState() const { |
193 switch (next_state_) { | 201 switch (next_state_) { |
194 case STATE_RESOLVE_PROXY_COMPLETE: | 202 case STATE_RESOLVE_PROXY_COMPLETE: |
195 return session_->proxy_service()->GetLoadState(pac_request_); | 203 return session_->proxy_service()->GetLoadState(pac_request_); |
196 case STATE_CREATE_STREAM_COMPLETE: | 204 case STATE_CREATE_STREAM_COMPLETE: |
197 return connection_->GetLoadState(); | 205 return connection_->GetLoadState(); |
198 case STATE_INIT_CONNECTION_COMPLETE: | 206 case STATE_INIT_CONNECTION_COMPLETE: |
199 return LOAD_STATE_SENDING_REQUEST; | 207 return LOAD_STATE_SENDING_REQUEST; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 HttpAuthController* auth_controller) { | 343 HttpAuthController* auth_controller) { |
336 DCHECK(!IsPreconnecting()); | 344 DCHECK(!IsPreconnecting()); |
337 if (IsOrphaned()) | 345 if (IsOrphaned()) |
338 stream_factory_->OnOrphanedJobComplete(this); | 346 stream_factory_->OnOrphanedJobComplete(this); |
339 else | 347 else |
340 request_->OnNeedsProxyAuth( | 348 request_->OnNeedsProxyAuth( |
341 this, response, server_ssl_config_, proxy_info_, auth_controller); | 349 this, response, server_ssl_config_, proxy_info_, auth_controller); |
342 // |this| may be deleted after this call. | 350 // |this| may be deleted after this call. |
343 } | 351 } |
344 | 352 |
| 353 void HttpStreamFactoryImpl::Job::OnNeedsProxyTunnelAuthCallback( |
| 354 const HttpResponseInfo& response_info, |
| 355 HttpAuthController* auth_controller, |
| 356 CompletionCallback callback) { |
| 357 DCHECK(!callback.is_null()); |
| 358 DCHECK(tunnel_auth_handled_callback_.is_null()); |
| 359 tunnel_auth_handled_callback_ = callback; |
| 360 request_->OnNeedsProxyAuth( |
| 361 this, response_info, server_ssl_config_, proxy_info_, auth_controller); |
| 362 // |this| may be deleted after this call. |
| 363 } |
| 364 |
345 void HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback( | 365 void HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback( |
346 SSLCertRequestInfo* cert_info) { | 366 SSLCertRequestInfo* cert_info) { |
347 DCHECK(!IsPreconnecting()); | 367 DCHECK(!IsPreconnecting()); |
348 if (IsOrphaned()) | 368 if (IsOrphaned()) |
349 stream_factory_->OnOrphanedJobComplete(this); | 369 stream_factory_->OnOrphanedJobComplete(this); |
350 else | 370 else |
351 request_->OnNeedsClientAuth(this, server_ssl_config_, cert_info); | 371 request_->OnNeedsClientAuth(this, server_ssl_config_, cert_info); |
352 // |this| may be deleted after this call. | 372 // |this| may be deleted after this call. |
353 } | 373 } |
354 | 374 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 return ERR_IO_PENDING; | 429 return ERR_IO_PENDING; |
410 } | 430 } |
411 | 431 |
412 switch (result) { | 432 switch (result) { |
413 case ERR_PROXY_AUTH_REQUESTED: | 433 case ERR_PROXY_AUTH_REQUESTED: |
414 { | 434 { |
415 DCHECK(connection_.get()); | 435 DCHECK(connection_.get()); |
416 DCHECK(connection_->socket()); | 436 DCHECK(connection_->socket()); |
417 DCHECK(establishing_tunnel_); | 437 DCHECK(establishing_tunnel_); |
418 | 438 |
419 HttpProxyClientSocket* http_proxy_socket = | 439 ProxyClientSocket* proxy_socket = |
420 static_cast<HttpProxyClientSocket*>(connection_->socket()); | 440 static_cast<ProxyClientSocket*>(connection_->socket()); |
421 const HttpResponseInfo* tunnel_auth_response = | 441 const HttpResponseInfo* tunnel_auth_response = |
422 http_proxy_socket->GetConnectResponseInfo(); | 442 proxy_socket->GetConnectResponseInfo(); |
423 | 443 |
424 next_state_ = STATE_WAITING_USER_ACTION; | 444 next_state_ = STATE_WAITING_USER_ACTION; |
425 MessageLoop::current()->PostTask( | 445 MessageLoop::current()->PostTask( |
426 FROM_HERE, | 446 FROM_HERE, |
427 base::Bind( | 447 base::Bind( |
428 &HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback, | 448 &HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback, |
429 ptr_factory_.GetWeakPtr(), | 449 ptr_factory_.GetWeakPtr(), |
430 *tunnel_auth_response, | 450 *tunnel_auth_response, |
431 http_proxy_socket->auth_controller())); | 451 proxy_socket->GetAuthController())); |
432 } | 452 } |
433 return ERR_IO_PENDING; | 453 return ERR_IO_PENDING; |
434 | 454 |
435 case ERR_SSL_CLIENT_AUTH_CERT_NEEDED: | 455 case ERR_SSL_CLIENT_AUTH_CERT_NEEDED: |
436 MessageLoop::current()->PostTask( | 456 MessageLoop::current()->PostTask( |
437 FROM_HERE, | 457 FROM_HERE, |
438 base::Bind( | 458 base::Bind( |
439 &HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback, | 459 &HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback, |
440 ptr_factory_.GetWeakPtr(), | 460 ptr_factory_.GetWeakPtr(), |
441 connection_->ssl_error_response_info().cert_request_info)); | 461 connection_->ssl_error_response_info().cert_request_info)); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 request_info_.extra_headers, | 734 request_info_.extra_headers, |
715 request_info_.load_flags, | 735 request_info_.load_flags, |
716 request_info_.priority, | 736 request_info_.priority, |
717 session_, | 737 session_, |
718 proxy_info_, | 738 proxy_info_, |
719 ShouldForceSpdySSL(), | 739 ShouldForceSpdySSL(), |
720 want_spdy_over_npn, | 740 want_spdy_over_npn, |
721 server_ssl_config_, | 741 server_ssl_config_, |
722 proxy_ssl_config_, | 742 proxy_ssl_config_, |
723 net_log_, | 743 net_log_, |
724 num_streams_); | 744 num_streams_, |
| 745 base::Bind(&HttpStreamFactoryImpl::Job::OnNeedsProxyTunnelAuthCallback, |
| 746 ptr_factory_.GetWeakPtr())); |
725 } else { | 747 } else { |
726 return InitSocketHandleForHttpRequest( | 748 return InitSocketHandleForHttpRequest( |
727 origin_url_, request_info_.extra_headers, request_info_.load_flags, | 749 origin_url_, request_info_.extra_headers, request_info_.load_flags, |
728 request_info_.priority, session_, proxy_info_, ShouldForceSpdySSL(), | 750 request_info_.priority, session_, proxy_info_, ShouldForceSpdySSL(), |
729 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, net_log_, | 751 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, net_log_, |
730 connection_.get(), io_callback_); | 752 connection_.get(), |
| 753 base::Bind(&HttpStreamFactoryImpl::Job::OnNeedsProxyTunnelAuthCallback, |
| 754 ptr_factory_.GetWeakPtr()), |
| 755 io_callback_); |
731 } | 756 } |
732 } | 757 } |
733 | 758 |
734 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { | 759 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { |
735 if (IsPreconnecting()) { | 760 if (IsPreconnecting()) { |
736 DCHECK_EQ(OK, result); | 761 DCHECK_EQ(OK, result); |
737 return OK; | 762 return OK; |
738 } | 763 } |
739 | 764 |
740 // TODO(willchan): Make this a bit more exact. Maybe there are recoverable | 765 // TODO(willchan): Make this a bit more exact. Maybe there are recoverable |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 return false; | 1233 return false; |
1209 } | 1234 } |
1210 if (request_info_.method != "GET" && request_info_.method != "HEAD") { | 1235 if (request_info_.method != "GET" && request_info_.method != "HEAD") { |
1211 return false; | 1236 return false; |
1212 } | 1237 } |
1213 return stream_factory_->http_pipelined_host_pool_.IsHostEligibleForPipelining( | 1238 return stream_factory_->http_pipelined_host_pool_.IsHostEligibleForPipelining( |
1214 origin_); | 1239 origin_); |
1215 } | 1240 } |
1216 | 1241 |
1217 } // namespace net | 1242 } // namespace net |
OLD | NEW |