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 #include "net/http/http_stream_factory_impl_job.h" | 5 #include "net/http/http_stream_factory_impl_job.h" |
| 6 | 6 |
| 7 #include <string> | |
| 8 | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 13 #include "base/values.h" | 15 #include "base/values.h" |
| 14 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 15 #include "net/base/connection_type_histograms.h" | 17 #include "net/base/connection_type_histograms.h" |
| 16 #include "net/base/net_log.h" | 18 #include "net/base/net_log.h" |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 } | 269 } |
| 268 } | 270 } |
| 269 | 271 |
| 270 bool HttpStreamFactoryImpl::Job::CanUseExistingSpdySession() const { | 272 bool HttpStreamFactoryImpl::Job::CanUseExistingSpdySession() const { |
| 271 // We need to make sure that if a spdy session was created for | 273 // We need to make sure that if a spdy session was created for |
| 272 // https://somehost/ that we don't use that session for http://somehost:443/. | 274 // https://somehost/ that we don't use that session for http://somehost:443/. |
| 273 // The only time we can use an existing session is if the request URL is | 275 // The only time we can use an existing session is if the request URL is |
| 274 // https (the normal case) or if we're connection to a SPDY proxy, or | 276 // https (the normal case) or if we're connection to a SPDY proxy, or |
| 275 // if we're running with force_spdy_always_. crbug.com/133176 | 277 // if we're running with force_spdy_always_. crbug.com/133176 |
| 276 return request_info_.url.SchemeIs("https") || | 278 return request_info_.url.SchemeIs("https") || |
| 279 request_info_.url.SchemeIs("wss") || | |
| 277 proxy_info_.proxy_server().is_https() || | 280 proxy_info_.proxy_server().is_https() || |
| 278 force_spdy_always_; | 281 force_spdy_always_; |
| 279 } | 282 } |
| 280 | 283 |
| 281 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { | 284 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { |
| 282 DCHECK(stream_.get()); | 285 DCHECK(stream_.get()); |
| 283 DCHECK(!IsPreconnecting()); | 286 DCHECK(!IsPreconnecting()); |
| 287 DCHECK(!stream_factory_->for_websockets_); | |
| 284 if (IsOrphaned()) { | 288 if (IsOrphaned()) { |
| 285 stream_factory_->OnOrphanedJobComplete(this); | 289 stream_factory_->OnOrphanedJobComplete(this); |
| 286 } else { | 290 } else { |
| 287 request_->Complete(was_npn_negotiated(), | 291 request_->Complete(was_npn_negotiated(), |
| 288 protocol_negotiated(), | 292 protocol_negotiated(), |
| 289 using_spdy(), | 293 using_spdy(), |
| 290 net_log_); | 294 net_log_); |
| 291 request_->OnStreamReady(this, server_ssl_config_, proxy_info_, | 295 request_->OnStreamReady(this, server_ssl_config_, proxy_info_, |
| 292 stream_.release()); | 296 stream_.release()); |
| 293 } | 297 } |
| 294 // |this| may be deleted after this call. | 298 // |this| may be deleted after this call. |
| 295 } | 299 } |
| 296 | 300 |
| 297 void HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback() { | 301 void HttpStreamFactoryImpl::Job::OnWebSocketStreamReadyCallback() { |
| 302 DCHECK(websocket_stream_); | |
| 303 DCHECK(!IsPreconnecting()); | |
| 304 DCHECK(stream_factory_->for_websockets_); | |
| 305 if (IsOrphaned()) { | |
| 306 stream_factory_->OnOrphanedJobComplete(this); | |
| 307 } else { | |
| 308 request_->Complete(was_npn_negotiated(), | |
| 309 protocol_negotiated(), | |
| 310 using_spdy(), | |
| 311 net_log_); | |
| 312 request_->OnWebSocketStreamReady(this, | |
| 313 server_ssl_config_, | |
| 314 proxy_info_, | |
| 315 websocket_stream_.release()); | |
| 316 } | |
| 317 // |this| may be deleted after this call. | |
| 318 } | |
| 319 | |
| 320 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() { | |
| 298 DCHECK(!stream_.get()); | 321 DCHECK(!stream_.get()); |
| 299 DCHECK(!IsPreconnecting()); | 322 DCHECK(!IsPreconnecting()); |
| 300 DCHECK(using_spdy()); | 323 DCHECK(using_spdy()); |
| 301 DCHECK(new_spdy_session_.get()); | 324 DCHECK(new_spdy_session_.get()); |
| 302 scoped_refptr<SpdySession> spdy_session = new_spdy_session_; | 325 scoped_refptr<SpdySession> spdy_session = new_spdy_session_; |
| 303 new_spdy_session_ = NULL; | 326 new_spdy_session_ = NULL; |
| 304 if (IsOrphaned()) { | 327 if (IsOrphaned()) { |
| 305 stream_factory_->OnSpdySessionReady( | 328 stream_factory_->OnNewSpdySessionReady( |
| 306 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, | 329 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, |
| 307 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); | 330 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); |
| 308 stream_factory_->OnOrphanedJobComplete(this); | 331 stream_factory_->OnOrphanedJobComplete(this); |
| 309 } else { | 332 } else { |
| 310 request_->OnSpdySessionReady(this, spdy_session, spdy_session_direct_); | 333 request_->OnNewSpdySessionReady(this, spdy_session, spdy_session_direct_); |
| 311 } | 334 } |
| 312 // |this| may be deleted after this call. | 335 // |this| may be deleted after this call. |
| 313 } | 336 } |
| 314 | 337 |
| 315 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) { | 338 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) { |
| 316 DCHECK(!IsPreconnecting()); | 339 DCHECK(!IsPreconnecting()); |
| 317 if (IsOrphaned()) | 340 if (IsOrphaned()) |
| 318 stream_factory_->OnOrphanedJobComplete(this); | 341 stream_factory_->OnOrphanedJobComplete(this); |
| 319 else | 342 else |
| 320 request_->OnStreamFailed(this, result, server_ssl_config_); | 343 request_->OnStreamFailed(this, result, server_ssl_config_); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 if (IsOrphaned()) | 383 if (IsOrphaned()) |
| 361 stream_factory_->OnOrphanedJobComplete(this); | 384 stream_factory_->OnOrphanedJobComplete(this); |
| 362 else | 385 else |
| 363 request_->OnHttpsProxyTunnelResponse( | 386 request_->OnHttpsProxyTunnelResponse( |
| 364 this, response_info, server_ssl_config_, proxy_info_, stream); | 387 this, response_info, server_ssl_config_, proxy_info_, stream); |
| 365 // |this| may be deleted after this call. | 388 // |this| may be deleted after this call. |
| 366 } | 389 } |
| 367 | 390 |
| 368 void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() { | 391 void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() { |
| 369 DCHECK(!request_); | 392 DCHECK(!request_); |
| 370 if (new_spdy_session_.get()) { | 393 if (new_spdy_session_) { |
| 371 stream_factory_->OnSpdySessionReady(new_spdy_session_, | 394 stream_factory_->OnNewSpdySessionReady( |
| 372 spdy_session_direct_, | 395 new_spdy_session_, spdy_session_direct_, server_ssl_config_, |
| 373 server_ssl_config_, | 396 proxy_info_, was_npn_negotiated(), protocol_negotiated(), using_spdy(), |
| 374 proxy_info_, | 397 net_log_); |
| 375 was_npn_negotiated(), | |
| 376 protocol_negotiated(), | |
| 377 using_spdy(), | |
| 378 net_log_); | |
| 379 } | 398 } |
| 380 stream_factory_->OnPreconnectsComplete(this); | 399 stream_factory_->OnPreconnectsComplete(this); |
| 381 // |this| may be deleted after this call. | 400 // |this| may be deleted after this call. |
| 382 } | 401 } |
| 383 | 402 |
| 384 // static | 403 // static |
| 385 int HttpStreamFactoryImpl::Job::OnHostResolution( | 404 int HttpStreamFactoryImpl::Job::OnHostResolution( |
| 386 SpdySessionPool* spdy_session_pool, | 405 SpdySessionPool* spdy_session_pool, |
| 387 const SpdySessionKey& spdy_session_key, | 406 const SpdySessionKey& spdy_session_key, |
| 388 const AddressList& addresses, | 407 const AddressList& addresses, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 | 460 |
| 442 ProxyClientSocket* proxy_socket = | 461 ProxyClientSocket* proxy_socket = |
| 443 static_cast<ProxyClientSocket*>(connection_->socket()); | 462 static_cast<ProxyClientSocket*>(connection_->socket()); |
| 444 const HttpResponseInfo* tunnel_auth_response = | 463 const HttpResponseInfo* tunnel_auth_response = |
| 445 proxy_socket->GetConnectResponseInfo(); | 464 proxy_socket->GetConnectResponseInfo(); |
| 446 | 465 |
| 447 next_state_ = STATE_WAITING_USER_ACTION; | 466 next_state_ = STATE_WAITING_USER_ACTION; |
| 448 base::MessageLoop::current()->PostTask( | 467 base::MessageLoop::current()->PostTask( |
| 449 FROM_HERE, | 468 FROM_HERE, |
| 450 base::Bind( | 469 base::Bind( |
| 451 &HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback, | 470 &Job::OnNeedsProxyAuthCallback, |
| 452 ptr_factory_.GetWeakPtr(), | 471 ptr_factory_.GetWeakPtr(), |
| 453 *tunnel_auth_response, | 472 *tunnel_auth_response, |
| 454 proxy_socket->GetAuthController())); | 473 proxy_socket->GetAuthController())); |
| 455 } | 474 } |
| 456 return ERR_IO_PENDING; | 475 return ERR_IO_PENDING; |
| 457 | 476 |
| 458 case ERR_SSL_CLIENT_AUTH_CERT_NEEDED: | 477 case ERR_SSL_CLIENT_AUTH_CERT_NEEDED: |
| 459 base::MessageLoop::current()->PostTask( | 478 base::MessageLoop::current()->PostTask( |
| 460 FROM_HERE, | 479 FROM_HERE, |
| 461 base::Bind( | 480 base::Bind( |
| 462 &HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback, | 481 &Job::OnNeedsClientAuthCallback, |
| 463 ptr_factory_.GetWeakPtr(), | 482 ptr_factory_.GetWeakPtr(), |
| 464 connection_->ssl_error_response_info().cert_request_info)); | 483 connection_->ssl_error_response_info().cert_request_info)); |
| 465 return ERR_IO_PENDING; | 484 return ERR_IO_PENDING; |
| 466 | 485 |
| 467 case ERR_HTTPS_PROXY_TUNNEL_RESPONSE: | 486 case ERR_HTTPS_PROXY_TUNNEL_RESPONSE: |
| 468 { | 487 { |
| 469 DCHECK(connection_.get()); | 488 DCHECK(connection_.get()); |
| 470 DCHECK(connection_->socket()); | 489 DCHECK(connection_->socket()); |
| 471 DCHECK(establishing_tunnel_); | 490 DCHECK(establishing_tunnel_); |
| 472 | 491 |
| 473 ProxyClientSocket* proxy_socket = | 492 ProxyClientSocket* proxy_socket = |
| 474 static_cast<ProxyClientSocket*>(connection_->socket()); | 493 static_cast<ProxyClientSocket*>(connection_->socket()); |
| 475 base::MessageLoop::current()->PostTask( | 494 base::MessageLoop::current()->PostTask( |
| 476 FROM_HERE, | 495 FROM_HERE, |
| 477 base::Bind( | 496 base::Bind( |
| 478 &HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback, | 497 &Job::OnHttpsProxyTunnelResponseCallback, |
| 479 ptr_factory_.GetWeakPtr(), | 498 ptr_factory_.GetWeakPtr(), |
| 480 *proxy_socket->GetConnectResponseInfo(), | 499 *proxy_socket->GetConnectResponseInfo(), |
| 481 proxy_socket->CreateConnectResponseStream())); | 500 proxy_socket->CreateConnectResponseStream())); |
| 482 return ERR_IO_PENDING; | 501 return ERR_IO_PENDING; |
| 483 } | 502 } |
| 484 | 503 |
| 485 case OK: | 504 case OK: |
| 486 next_state_ = STATE_DONE; | 505 next_state_ = STATE_DONE; |
| 487 if (new_spdy_session_.get()) { | 506 if (new_spdy_session_) { |
| 488 base::MessageLoop::current()->PostTask( | |
| 489 FROM_HERE, | |
| 490 base::Bind(&HttpStreamFactoryImpl::Job::OnSpdySessionReadyCallback, | |
| 491 ptr_factory_.GetWeakPtr())); | |
| 492 } else { | |
| 493 base::MessageLoop::current()->PostTask( | 507 base::MessageLoop::current()->PostTask( |
| 494 FROM_HERE, | 508 FROM_HERE, |
| 495 base::Bind( | 509 base::Bind( |
| 496 &HttpStreamFactoryImpl::Job::OnStreamReadyCallback, | 510 &Job::OnNewSpdySessionReadyCallback, |
| 511 ptr_factory_.GetWeakPtr())); | |
| 512 } else if (stream_factory_->for_websockets_) { | |
| 513 DCHECK(websocket_stream_); | |
| 514 base::MessageLoop::current()->PostTask( | |
| 515 FROM_HERE, | |
| 516 base::Bind( | |
| 517 &Job::OnWebSocketStreamReadyCallback, | |
| 518 ptr_factory_.GetWeakPtr())); | |
| 519 } else { | |
| 520 DCHECK(stream_.get()); | |
| 521 base::MessageLoop::current()->PostTask( | |
| 522 FROM_HERE, | |
| 523 base::Bind( | |
| 524 &Job::OnStreamReadyCallback, | |
| 497 ptr_factory_.GetWeakPtr())); | 525 ptr_factory_.GetWeakPtr())); |
| 498 } | 526 } |
| 499 return ERR_IO_PENDING; | 527 return ERR_IO_PENDING; |
| 500 | 528 |
| 501 default: | 529 default: |
| 502 base::MessageLoop::current()->PostTask( | 530 base::MessageLoop::current()->PostTask( |
| 503 FROM_HERE, | 531 FROM_HERE, |
| 504 base::Bind( | 532 base::Bind( |
| 505 &HttpStreamFactoryImpl::Job::OnStreamFailedCallback, | 533 &Job::OnStreamFailedCallback, |
| 506 ptr_factory_.GetWeakPtr(), | 534 ptr_factory_.GetWeakPtr(), |
| 507 result)); | 535 result)); |
| 508 return ERR_IO_PENDING; | 536 return ERR_IO_PENDING; |
| 509 } | 537 } |
| 510 return result; | 538 return result; |
| 511 } | 539 } |
| 512 | 540 |
| 513 int HttpStreamFactoryImpl::Job::DoLoop(int result) { | 541 int HttpStreamFactoryImpl::Job::DoLoop(int result) { |
| 514 DCHECK_NE(next_state_, STATE_NONE); | 542 DCHECK_NE(next_state_, STATE_NONE); |
| 515 int rv = result; | 543 int rv = result; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 next_state_ = STATE_INIT_CONNECTION; | 710 next_state_ = STATE_INIT_CONNECTION; |
| 683 return OK; | 711 return OK; |
| 684 } | 712 } |
| 685 | 713 |
| 686 int HttpStreamFactoryImpl::Job::DoInitConnection() { | 714 int HttpStreamFactoryImpl::Job::DoInitConnection() { |
| 687 DCHECK(!blocking_job_); | 715 DCHECK(!blocking_job_); |
| 688 DCHECK(!connection_->is_initialized()); | 716 DCHECK(!connection_->is_initialized()); |
| 689 DCHECK(proxy_info_.proxy_server().is_valid()); | 717 DCHECK(proxy_info_.proxy_server().is_valid()); |
| 690 next_state_ = STATE_INIT_CONNECTION_COMPLETE; | 718 next_state_ = STATE_INIT_CONNECTION_COMPLETE; |
| 691 | 719 |
| 692 using_ssl_ = request_info_.url.SchemeIs("https") || ShouldForceSpdySSL(); | 720 using_ssl_ = request_info_.url.SchemeIs("https") || |
| 721 request_info_.url.SchemeIs("wss") || ShouldForceSpdySSL(); | |
| 693 using_spdy_ = false; | 722 using_spdy_ = false; |
| 694 | 723 |
| 695 if (ShouldForceQuic()) | 724 if (ShouldForceQuic()) |
| 696 using_quic_ = true; | 725 using_quic_ = true; |
| 697 | 726 |
| 698 if (using_quic_) { | 727 if (using_quic_) { |
| 699 DCHECK(session_->params().enable_quic); | 728 DCHECK(session_->params().enable_quic); |
| 700 if (!proxy_info_.is_direct()) { | 729 if (!proxy_info_.is_direct()) { |
| 701 NOTREACHED(); | 730 NOTREACHED(); |
| 702 // TODO(rch): support QUIC proxies. | 731 // TODO(rch): support QUIC proxies. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 // Disable revocation checking for HTTPS proxies since the revocation | 796 // Disable revocation checking for HTTPS proxies since the revocation |
| 768 // requests are probably going to need to go through the proxy too. | 797 // requests are probably going to need to go through the proxy too. |
| 769 proxy_ssl_config_.rev_checking_enabled = false; | 798 proxy_ssl_config_.rev_checking_enabled = false; |
| 770 } | 799 } |
| 771 if (using_ssl_) { | 800 if (using_ssl_) { |
| 772 InitSSLConfig(origin_, &server_ssl_config_, | 801 InitSSLConfig(origin_, &server_ssl_config_, |
| 773 false /* not a proxy server */); | 802 false /* not a proxy server */); |
| 774 } | 803 } |
| 775 | 804 |
| 776 if (IsPreconnecting()) { | 805 if (IsPreconnecting()) { |
| 806 DCHECK(!stream_factory_->for_websockets_); | |
| 777 return PreconnectSocketsForHttpRequest( | 807 return PreconnectSocketsForHttpRequest( |
| 778 origin_url_, | 808 origin_url_, |
| 779 request_info_.extra_headers, | 809 request_info_.extra_headers, |
| 780 request_info_.load_flags, | 810 request_info_.load_flags, |
| 781 priority_, | 811 priority_, |
| 782 session_, | 812 session_, |
| 783 proxy_info_, | 813 proxy_info_, |
| 784 ShouldForceSpdySSL(), | 814 ShouldForceSpdySSL(), |
| 785 want_spdy_over_npn, | 815 want_spdy_over_npn, |
| 786 server_ssl_config_, | 816 server_ssl_config_, |
| 787 proxy_ssl_config_, | 817 proxy_ssl_config_, |
| 788 request_info_.privacy_mode, | 818 request_info_.privacy_mode, |
| 789 net_log_, | 819 net_log_, |
| 790 num_streams_); | 820 num_streams_); |
| 791 } else { | 821 } else { |
| 792 // If we can't use a SPDY session, don't both checking for one after | 822 // If we can't use a SPDY session, don't both checking for one after |
| 793 // the hostname is resolved. | 823 // the hostname is resolved. |
| 794 OnHostResolutionCallback resolution_callback = CanUseExistingSpdySession() ? | 824 OnHostResolutionCallback resolution_callback = CanUseExistingSpdySession() ? |
| 795 base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), | 825 base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), |
| 796 GetSpdySessionKey()) : | 826 GetSpdySessionKey()) : |
| 797 OnHostResolutionCallback(); | 827 OnHostResolutionCallback(); |
| 828 if (stream_factory_->for_websockets_) { | |
| 829 return InitSocketHandleForWebSocketRequest( | |
| 830 origin_url_, request_info_.extra_headers, request_info_.load_flags, | |
| 831 priority_, session_, proxy_info_, ShouldForceSpdySSL(), | |
| 832 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, | |
| 833 request_info_.privacy_mode, net_log_, | |
| 834 connection_.get(), resolution_callback, io_callback_); | |
| 835 } | |
| 798 return InitSocketHandleForHttpRequest( | 836 return InitSocketHandleForHttpRequest( |
| 799 origin_url_, request_info_.extra_headers, request_info_.load_flags, | 837 origin_url_, request_info_.extra_headers, request_info_.load_flags, |
| 800 priority_, session_, proxy_info_, ShouldForceSpdySSL(), | 838 priority_, session_, proxy_info_, ShouldForceSpdySSL(), |
| 801 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, | 839 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, |
| 802 request_info_.privacy_mode, net_log_, | 840 request_info_.privacy_mode, net_log_, |
| 803 connection_.get(), resolution_callback, io_callback_); | 841 connection_.get(), resolution_callback, io_callback_); |
| 804 } | 842 } |
| 805 } | 843 } |
| 806 | 844 |
| 807 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { | 845 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 857 if (ssl_socket->WasNpnNegotiated()) { | 895 if (ssl_socket->WasNpnNegotiated()) { |
| 858 was_npn_negotiated_ = true; | 896 was_npn_negotiated_ = true; |
| 859 std::string proto; | 897 std::string proto; |
| 860 std::string server_protos; | 898 std::string server_protos; |
| 861 SSLClientSocket::NextProtoStatus status = | 899 SSLClientSocket::NextProtoStatus status = |
| 862 ssl_socket->GetNextProto(&proto, &server_protos); | 900 ssl_socket->GetNextProto(&proto, &server_protos); |
| 863 NextProto protocol_negotiated = | 901 NextProto protocol_negotiated = |
| 864 SSLClientSocket::NextProtoFromString(proto); | 902 SSLClientSocket::NextProtoFromString(proto); |
| 865 protocol_negotiated_ = protocol_negotiated; | 903 protocol_negotiated_ = protocol_negotiated; |
| 866 net_log_.AddEvent( | 904 net_log_.AddEvent( |
| 867 NetLog::TYPE_HTTP_STREAM_REQUEST_PROTO, | 905 NetLog::TYPE_HTTP_STREAM_REQUEST_PROTO, |
| 868 base::Bind(&NetLogHttpStreamProtoCallback, | 906 base::Bind(&NetLogHttpStreamProtoCallback, |
| 869 status, &proto, &server_protos)); | 907 status, &proto, &server_protos)); |
| 870 if (ssl_socket->was_spdy_negotiated()) | 908 if (ssl_socket->was_spdy_negotiated()) |
| 871 SwitchToSpdyMode(); | 909 SwitchToSpdyMode(); |
| 872 } | 910 } |
| 873 if (ShouldForceSpdySSL()) | 911 if (ShouldForceSpdySSL()) |
| 874 SwitchToSpdyMode(); | 912 SwitchToSpdyMode(); |
| 875 } else if (proxy_info_.is_https() && connection_->socket() && | 913 } else if (proxy_info_.is_https() && connection_->socket() && |
| 876 result == OK) { | 914 result == OK) { |
| 877 ProxyClientSocket* proxy_socket = | 915 ProxyClientSocket* proxy_socket = |
| 878 static_cast<ProxyClientSocket*>(connection_->socket()); | 916 static_cast<ProxyClientSocket*>(connection_->socket()); |
| 879 if (proxy_socket->IsUsingSpdy()) { | 917 if (proxy_socket->IsUsingSpdy()) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 975 if (connection_->socket() && !connection_->is_reused()) | 1013 if (connection_->socket() && !connection_->is_reused()) |
| 976 SetSocketMotivation(); | 1014 SetSocketMotivation(); |
| 977 | 1015 |
| 978 if (!using_spdy_) { | 1016 if (!using_spdy_) { |
| 979 // We may get ftp scheme when fetching ftp resources through proxy. | 1017 // We may get ftp scheme when fetching ftp resources through proxy. |
| 980 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && | 1018 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && |
| 981 (request_info_.url.SchemeIs("http") || | 1019 (request_info_.url.SchemeIs("http") || |
| 982 request_info_.url.SchemeIs("ftp")); | 1020 request_info_.url.SchemeIs("ftp")); |
| 983 if (stream_factory_->http_pipelined_host_pool_. | 1021 if (stream_factory_->http_pipelined_host_pool_. |
| 984 IsExistingPipelineAvailableForKey(*http_pipelining_key_.get())) { | 1022 IsExistingPipelineAvailableForKey(*http_pipelining_key_.get())) { |
| 1023 DCHECK(!stream_factory_->for_websockets_); | |
| 985 stream_.reset(stream_factory_->http_pipelined_host_pool_. | 1024 stream_.reset(stream_factory_->http_pipelined_host_pool_. |
| 986 CreateStreamOnExistingPipeline( | 1025 CreateStreamOnExistingPipeline( |
| 987 *http_pipelining_key_.get())); | 1026 *http_pipelining_key_.get())); |
| 988 CHECK(stream_.get()); | 1027 CHECK(stream_.get()); |
| 1028 } else if (stream_factory_->for_websockets_) { | |
| 1029 if (request_ && request_->websocket_stream_factory()) { | |
| 1030 websocket_stream_.reset( | |
| 1031 request_->websocket_stream_factory()->CreateBasicStream( | |
| 1032 connection_.release(), using_proxy)); | |
| 1033 } else { | |
| 1034 // The job is orphaned. | |
| 1035 return ERR_FAILED; | |
|
mmenke
2013/06/13 17:59:56
I think the right thing to do, in order to cancel
yhirano
2013/06/14 04:11:25
Done.
| |
| 1036 } | |
| 989 } else if (!using_proxy && IsRequestEligibleForPipelining()) { | 1037 } else if (!using_proxy && IsRequestEligibleForPipelining()) { |
| 990 // TODO(simonjam): Support proxies. | 1038 // TODO(simonjam): Support proxies. |
| 991 stream_.reset( | 1039 stream_.reset( |
| 992 stream_factory_->http_pipelined_host_pool_.CreateStreamOnNewPipeline( | 1040 stream_factory_->http_pipelined_host_pool_.CreateStreamOnNewPipeline( |
| 993 *http_pipelining_key_.get(), | 1041 *http_pipelining_key_.get(), |
| 994 connection_.release(), | 1042 connection_.release(), |
| 995 server_ssl_config_, | 1043 server_ssl_config_, |
| 996 proxy_info_, | 1044 proxy_info_, |
| 997 net_log_, | 1045 net_log_, |
| 998 was_npn_negotiated_, | 1046 was_npn_negotiated_, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1050 } | 1098 } |
| 1051 } | 1099 } |
| 1052 | 1100 |
| 1053 if (spdy_session->IsClosed()) | 1101 if (spdy_session->IsClosed()) |
| 1054 return ERR_CONNECTION_CLOSED; | 1102 return ERR_CONNECTION_CLOSED; |
| 1055 | 1103 |
| 1056 // TODO(willchan): Delete this code, because eventually, the | 1104 // TODO(willchan): Delete this code, because eventually, the |
| 1057 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it | 1105 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it |
| 1058 // will know when SpdySessions become available. | 1106 // will know when SpdySessions become available. |
| 1059 | 1107 |
| 1060 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); | 1108 if (stream_factory_->for_websockets_) { |
| 1061 stream_.reset(new SpdyHttpStream(spdy_session.get(), use_relative_url)); | 1109 if (request_ && request_->websocket_stream_factory()) { |
| 1110 bool use_relative_url = direct || request_info_.url.SchemeIs("wss"); | |
| 1111 websocket_stream_.reset( | |
| 1112 request_->websocket_stream_factory()->CreateSpdyStream( | |
| 1113 spdy_session, use_relative_url)); | |
| 1114 } else { | |
| 1115 // The job is orphaned. | |
| 1116 return ERR_FAILED; | |
| 1117 } | |
| 1118 } else { | |
| 1119 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); | |
| 1120 stream_.reset(new SpdyHttpStream(spdy_session, use_relative_url)); | |
| 1121 } | |
| 1062 return OK; | 1122 return OK; |
| 1063 } | 1123 } |
| 1064 | 1124 |
| 1065 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) { | 1125 int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) { |
| 1066 if (result < 0) | 1126 if (result < 0) |
| 1067 return result; | 1127 return result; |
| 1068 | 1128 |
| 1069 session_->proxy_service()->ReportSuccess(proxy_info_); | 1129 session_->proxy_service()->ReportSuccess(proxy_info_); |
| 1070 next_state_ = STATE_NONE; | 1130 next_state_ = STATE_NONE; |
| 1071 return OK; | 1131 return OK; |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1352 } | 1412 } |
| 1353 | 1413 |
| 1354 bool HttpStreamFactoryImpl::Job::IsOrphaned() const { | 1414 bool HttpStreamFactoryImpl::Job::IsOrphaned() const { |
| 1355 return !IsPreconnecting() && !request_; | 1415 return !IsPreconnecting() && !request_; |
| 1356 } | 1416 } |
| 1357 | 1417 |
| 1358 bool HttpStreamFactoryImpl::Job::IsRequestEligibleForPipelining() { | 1418 bool HttpStreamFactoryImpl::Job::IsRequestEligibleForPipelining() { |
| 1359 if (IsPreconnecting() || !request_) { | 1419 if (IsPreconnecting() || !request_) { |
| 1360 return false; | 1420 return false; |
| 1361 } | 1421 } |
| 1422 if (stream_factory_->for_websockets_) { | |
| 1423 return false; | |
| 1424 } | |
| 1362 if (session_->force_http_pipelining()) { | 1425 if (session_->force_http_pipelining()) { |
| 1363 return true; | 1426 return true; |
| 1364 } | 1427 } |
| 1365 if (!session_->params().http_pipelining_enabled) { | 1428 if (!session_->params().http_pipelining_enabled) { |
| 1366 return false; | 1429 return false; |
| 1367 } | 1430 } |
| 1368 if (using_ssl_) { | 1431 if (using_ssl_) { |
| 1369 return false; | 1432 return false; |
| 1370 } | 1433 } |
| 1371 if (request_info_.method != "GET" && request_info_.method != "HEAD") { | 1434 if (request_info_.method != "GET" && request_info_.method != "HEAD") { |
| 1372 return false; | 1435 return false; |
| 1373 } | 1436 } |
| 1374 if (request_info_.load_flags & | 1437 if (request_info_.load_flags & |
| 1375 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | | 1438 (net::LOAD_MAIN_FRAME | net::LOAD_SUB_FRAME | net::LOAD_PREFETCH | |
| 1376 net::LOAD_IS_DOWNLOAD)) { | 1439 net::LOAD_IS_DOWNLOAD)) { |
| 1377 // Avoid pipelining resources that may be streamed for a long time. | 1440 // Avoid pipelining resources that may be streamed for a long time. |
| 1378 return false; | 1441 return false; |
| 1379 } | 1442 } |
| 1380 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( | 1443 return stream_factory_->http_pipelined_host_pool_.IsKeyEligibleForPipelining( |
| 1381 *http_pipelining_key_.get()); | 1444 *http_pipelining_key_.get()); |
| 1382 } | 1445 } |
| 1383 | 1446 |
| 1384 } // namespace net | 1447 } // namespace net |
| OLD | NEW |