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 #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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 session_->http_server_properties(); | 173 session_->http_server_properties(); |
174 if (http_server_properties && | 174 if (http_server_properties && |
175 http_server_properties->SupportsSpdy(origin_server)) { | 175 http_server_properties->SupportsSpdy(origin_server)) { |
176 num_streams_ = 1; | 176 num_streams_ = 1; |
177 } else { | 177 } else { |
178 num_streams_ = num_streams; | 178 num_streams_ = num_streams; |
179 } | 179 } |
180 return StartInternal(); | 180 return StartInternal(); |
181 } | 181 } |
182 | 182 |
183 int HttpStreamFactoryImpl::Job::RestartTunnelWithProxyAuth() { | 183 int HttpStreamFactoryImpl::Job::RestartTunnelWithProxyAuth( |
184 // We run this asynchronously to ensure that we don't invoke | 184 const AuthCredentials& credentials) { |
185 // the callback (which might cause the caller to be deleted) | 185 DCHECK(establishing_tunnel_); |
186 // while the caller is waiting for this method to return. | 186 next_state_ = STATE_RESTART_TUNNEL_AUTH; |
187 MessageLoop::current()->PostTask( | 187 stream_.reset(); |
188 FROM_HERE, | 188 return RunLoop(OK); |
189 base::Bind(&HttpStreamFactoryImpl::Job::DoRestartTunnelWithProxyAuth, | |
190 ptr_factory_.GetWeakPtr())); | |
191 return ERR_IO_PENDING; | |
192 } | |
193 | |
194 void HttpStreamFactoryImpl::Job::DoRestartTunnelWithProxyAuth() { | |
195 tunnel_auth_handled_callback_.Run(OK); | |
196 tunnel_auth_handled_callback_.Reset(); | |
197 } | 189 } |
198 | 190 |
199 LoadState HttpStreamFactoryImpl::Job::GetLoadState() const { | 191 LoadState HttpStreamFactoryImpl::Job::GetLoadState() const { |
200 switch (next_state_) { | 192 switch (next_state_) { |
201 case STATE_RESOLVE_PROXY_COMPLETE: | 193 case STATE_RESOLVE_PROXY_COMPLETE: |
202 return session_->proxy_service()->GetLoadState(pac_request_); | 194 return session_->proxy_service()->GetLoadState(pac_request_); |
203 case STATE_CREATE_STREAM_COMPLETE: | 195 case STATE_CREATE_STREAM_COMPLETE: |
204 return connection_->GetLoadState(); | 196 return connection_->GetLoadState(); |
205 case STATE_INIT_CONNECTION_COMPLETE: | 197 case STATE_INIT_CONNECTION_COMPLETE: |
206 return LOAD_STATE_SENDING_REQUEST; | 198 return LOAD_STATE_SENDING_REQUEST; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 HttpAuthController* auth_controller) { | 334 HttpAuthController* auth_controller) { |
343 DCHECK(!IsPreconnecting()); | 335 DCHECK(!IsPreconnecting()); |
344 if (IsOrphaned()) | 336 if (IsOrphaned()) |
345 stream_factory_->OnOrphanedJobComplete(this); | 337 stream_factory_->OnOrphanedJobComplete(this); |
346 else | 338 else |
347 request_->OnNeedsProxyAuth( | 339 request_->OnNeedsProxyAuth( |
348 this, response, server_ssl_config_, proxy_info_, auth_controller); | 340 this, response, server_ssl_config_, proxy_info_, auth_controller); |
349 // |this| may be deleted after this call. | 341 // |this| may be deleted after this call. |
350 } | 342 } |
351 | 343 |
352 void HttpStreamFactoryImpl::Job::OnNeedsProxyTunnelAuthCallback( | |
353 const HttpResponseInfo& response_info, | |
354 HttpAuthController* auth_controller, | |
355 CompletionCallback callback) { | |
356 DCHECK(!callback.is_null()); | |
357 DCHECK(tunnel_auth_handled_callback_.is_null()); | |
358 tunnel_auth_handled_callback_ = callback; | |
359 request_->OnNeedsProxyAuth( | |
360 this, response_info, server_ssl_config_, proxy_info_, auth_controller); | |
361 // |this| may be deleted after this call. | |
362 } | |
363 | |
364 void HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback( | 344 void HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback( |
365 SSLCertRequestInfo* cert_info) { | 345 SSLCertRequestInfo* cert_info) { |
366 DCHECK(!IsPreconnecting()); | 346 DCHECK(!IsPreconnecting()); |
367 if (IsOrphaned()) | 347 if (IsOrphaned()) |
368 stream_factory_->OnOrphanedJobComplete(this); | 348 stream_factory_->OnOrphanedJobComplete(this); |
369 else | 349 else |
370 request_->OnNeedsClientAuth(this, server_ssl_config_, cert_info); | 350 request_->OnNeedsClientAuth(this, server_ssl_config_, cert_info); |
371 // |this| may be deleted after this call. | 351 // |this| may be deleted after this call. |
372 } | 352 } |
373 | 353 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 return ERR_IO_PENDING; | 412 return ERR_IO_PENDING; |
433 } | 413 } |
434 | 414 |
435 switch (result) { | 415 switch (result) { |
436 case ERR_PROXY_AUTH_REQUESTED: | 416 case ERR_PROXY_AUTH_REQUESTED: |
437 { | 417 { |
438 DCHECK(connection_.get()); | 418 DCHECK(connection_.get()); |
439 DCHECK(connection_->socket()); | 419 DCHECK(connection_->socket()); |
440 DCHECK(establishing_tunnel_); | 420 DCHECK(establishing_tunnel_); |
441 | 421 |
442 ProxyClientSocket* proxy_socket = | 422 HttpProxyClientSocket* http_proxy_socket = |
443 static_cast<ProxyClientSocket*>(connection_->socket()); | 423 static_cast<HttpProxyClientSocket*>(connection_->socket()); |
444 const HttpResponseInfo* tunnel_auth_response = | 424 const HttpResponseInfo* tunnel_auth_response = |
445 proxy_socket->GetConnectResponseInfo(); | 425 http_proxy_socket->GetConnectResponseInfo(); |
446 | 426 |
447 next_state_ = STATE_WAITING_USER_ACTION; | 427 next_state_ = STATE_WAITING_USER_ACTION; |
448 MessageLoop::current()->PostTask( | 428 MessageLoop::current()->PostTask( |
449 FROM_HERE, | 429 FROM_HERE, |
450 base::Bind( | 430 base::Bind( |
451 &HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback, | 431 &HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback, |
452 ptr_factory_.GetWeakPtr(), | 432 ptr_factory_.GetWeakPtr(), |
453 *tunnel_auth_response, | 433 *tunnel_auth_response, |
454 proxy_socket->GetAuthController())); | 434 http_proxy_socket->auth_controller())); |
455 } | 435 } |
456 return ERR_IO_PENDING; | 436 return ERR_IO_PENDING; |
457 | 437 |
458 case ERR_SSL_CLIENT_AUTH_CERT_NEEDED: | 438 case ERR_SSL_CLIENT_AUTH_CERT_NEEDED: |
459 MessageLoop::current()->PostTask( | 439 MessageLoop::current()->PostTask( |
460 FROM_HERE, | 440 FROM_HERE, |
461 base::Bind( | 441 base::Bind( |
462 &HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback, | 442 &HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback, |
463 ptr_factory_.GetWeakPtr(), | 443 ptr_factory_.GetWeakPtr(), |
464 connection_->ssl_error_response_info().cert_request_info)); | 444 connection_->ssl_error_response_info().cert_request_info)); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 request_info_.extra_headers, | 725 request_info_.extra_headers, |
746 request_info_.load_flags, | 726 request_info_.load_flags, |
747 request_info_.priority, | 727 request_info_.priority, |
748 session_, | 728 session_, |
749 proxy_info_, | 729 proxy_info_, |
750 ShouldForceSpdySSL(), | 730 ShouldForceSpdySSL(), |
751 want_spdy_over_npn, | 731 want_spdy_over_npn, |
752 server_ssl_config_, | 732 server_ssl_config_, |
753 proxy_ssl_config_, | 733 proxy_ssl_config_, |
754 net_log_, | 734 net_log_, |
755 num_streams_, | 735 num_streams_); |
756 base::Bind(&HttpStreamFactoryImpl::Job::OnNeedsProxyTunnelAuthCallback, | |
757 ptr_factory_.GetWeakPtr())); | |
758 } else { | 736 } else { |
759 return InitSocketHandleForHttpRequest( | 737 return InitSocketHandleForHttpRequest( |
760 origin_url_, request_info_.extra_headers, request_info_.load_flags, | 738 origin_url_, request_info_.extra_headers, request_info_.load_flags, |
761 request_info_.priority, session_, proxy_info_, ShouldForceSpdySSL(), | 739 request_info_.priority, session_, proxy_info_, ShouldForceSpdySSL(), |
762 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, net_log_, | 740 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, net_log_, |
763 connection_.get(), | 741 connection_.get(), io_callback_); |
764 base::Bind(&HttpStreamFactoryImpl::Job::OnNeedsProxyTunnelAuthCallback, | |
765 ptr_factory_.GetWeakPtr()), | |
766 io_callback_); | |
767 } | 742 } |
768 } | 743 } |
769 | 744 |
770 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { | 745 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { |
771 if (IsPreconnecting()) { | 746 if (IsPreconnecting()) { |
772 DCHECK_EQ(OK, result); | 747 DCHECK_EQ(OK, result); |
773 return OK; | 748 return OK; |
774 } | 749 } |
775 | 750 |
776 // TODO(willchan): Make this a bit more exact. Maybe there are recoverable | 751 // 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... |
1244 return false; | 1219 return false; |
1245 } | 1220 } |
1246 if (request_info_.method != "GET" && request_info_.method != "HEAD") { | 1221 if (request_info_.method != "GET" && request_info_.method != "HEAD") { |
1247 return false; | 1222 return false; |
1248 } | 1223 } |
1249 return stream_factory_->http_pipelined_host_pool_.IsHostEligibleForPipelining( | 1224 return stream_factory_->http_pipelined_host_pool_.IsHostEligibleForPipelining( |
1250 origin_); | 1225 origin_); |
1251 } | 1226 } |
1252 | 1227 |
1253 } // namespace net | 1228 } // namespace net |
OLD | NEW |