| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 dict->SetString("proto", *proto); | 72 dict->SetString("proto", *proto); |
| 73 return dict.Pass(); | 73 return dict.Pass(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 HttpStreamFactoryImpl::Job::Job(HttpStreamFactoryImpl* stream_factory, | 76 HttpStreamFactoryImpl::Job::Job(HttpStreamFactoryImpl* stream_factory, |
| 77 HttpNetworkSession* session, | 77 HttpNetworkSession* session, |
| 78 const HttpRequestInfo& request_info, | 78 const HttpRequestInfo& request_info, |
| 79 RequestPriority priority, | 79 RequestPriority priority, |
| 80 const SSLConfig& server_ssl_config, | 80 const SSLConfig& server_ssl_config, |
| 81 const SSLConfig& proxy_ssl_config, | 81 const SSLConfig& proxy_ssl_config, |
| 82 AlternativeService alternative_service, |
| 82 NetLog* net_log) | 83 NetLog* net_log) |
| 83 : request_(NULL), | 84 : request_(NULL), |
| 84 request_info_(request_info), | 85 request_info_(request_info), |
| 85 priority_(priority), | 86 priority_(priority), |
| 86 server_ssl_config_(server_ssl_config), | 87 server_ssl_config_(server_ssl_config), |
| 87 proxy_ssl_config_(proxy_ssl_config), | 88 proxy_ssl_config_(proxy_ssl_config), |
| 88 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_HTTP_STREAM_JOB)), | 89 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_HTTP_STREAM_JOB)), |
| 89 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), | 90 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), |
| 90 connection_(new ClientSocketHandle), | 91 connection_(new ClientSocketHandle), |
| 91 session_(session), | 92 session_(session), |
| 92 stream_factory_(stream_factory), | 93 stream_factory_(stream_factory), |
| 93 next_state_(STATE_NONE), | 94 next_state_(STATE_NONE), |
| 94 pac_request_(NULL), | 95 pac_request_(NULL), |
| 96 alternative_service_(alternative_service), |
| 97 is_spdy_alternative_( |
| 98 alternative_service_.protocol >= NPN_SPDY_MINIMUM_VERSION && |
| 99 alternative_service_.protocol <= NPN_SPDY_MAXIMUM_VERSION), |
| 100 is_quic_alternative_(alternative_service_.protocol == QUIC), |
| 95 blocking_job_(NULL), | 101 blocking_job_(NULL), |
| 96 waiting_job_(NULL), | 102 waiting_job_(NULL), |
| 97 using_ssl_(false), | 103 using_ssl_(false), |
| 98 using_spdy_(false), | 104 using_spdy_(false), |
| 99 using_quic_(false), | 105 using_quic_(is_quic_alternative_), |
| 100 quic_request_(session_->quic_stream_factory()), | 106 quic_request_(session_->quic_stream_factory()), |
| 101 using_existing_quic_session_(false), | 107 using_existing_quic_session_(false), |
| 102 spdy_certificate_error_(OK), | 108 spdy_certificate_error_(OK), |
| 103 establishing_tunnel_(false), | 109 establishing_tunnel_(false), |
| 104 was_npn_negotiated_(false), | 110 was_npn_negotiated_(false), |
| 105 protocol_negotiated_(kProtoUnknown), | 111 protocol_negotiated_(kProtoUnknown), |
| 106 num_streams_(0), | 112 num_streams_(0), |
| 107 spdy_session_direct_(false), | 113 spdy_session_direct_(false), |
| 108 job_status_(STATUS_RUNNING), | 114 job_status_(STATUS_RUNNING), |
| 109 other_job_status_(STATUS_RUNNING), | 115 other_job_status_(STATUS_RUNNING), |
| 110 ptr_factory_(this) { | 116 ptr_factory_(this) { |
| 111 DCHECK(stream_factory); | 117 DCHECK(stream_factory); |
| 112 DCHECK(session); | 118 DCHECK(session); |
| 119 if (is_quic_alternative_) |
| 120 DCHECK(session_->params().enable_quic); |
| 113 } | 121 } |
| 114 | 122 |
| 115 HttpStreamFactoryImpl::Job::~Job() { | 123 HttpStreamFactoryImpl::Job::~Job() { |
| 116 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_JOB); | 124 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_JOB); |
| 117 | 125 |
| 118 // When we're in a partially constructed state, waiting for the user to | 126 // When we're in a partially constructed state, waiting for the user to |
| 119 // provide certificate handling information or authentication, we can't reuse | 127 // provide certificate handling information or authentication, we can't reuse |
| 120 // this stream at all. | 128 // this stream at all. |
| 121 if (next_state_ == STATE_WAITING_USER_ACTION) { | 129 if (next_state_ == STATE_WAITING_USER_ACTION) { |
| 122 connection_->socket()->Disconnect(); | 130 connection_->socket()->Disconnect(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 case STATE_RESOLVE_PROXY_COMPLETE: | 172 case STATE_RESOLVE_PROXY_COMPLETE: |
| 165 return session_->proxy_service()->GetLoadState(pac_request_); | 173 return session_->proxy_service()->GetLoadState(pac_request_); |
| 166 case STATE_INIT_CONNECTION_COMPLETE: | 174 case STATE_INIT_CONNECTION_COMPLETE: |
| 167 case STATE_CREATE_STREAM_COMPLETE: | 175 case STATE_CREATE_STREAM_COMPLETE: |
| 168 return using_quic_ ? LOAD_STATE_CONNECTING : connection_->GetLoadState(); | 176 return using_quic_ ? LOAD_STATE_CONNECTING : connection_->GetLoadState(); |
| 169 default: | 177 default: |
| 170 return LOAD_STATE_IDLE; | 178 return LOAD_STATE_IDLE; |
| 171 } | 179 } |
| 172 } | 180 } |
| 173 | 181 |
| 174 void HttpStreamFactoryImpl::Job::MarkAsAlternate( | |
| 175 AlternativeService alternative_service) { | |
| 176 DCHECK(!IsAlternate()); | |
| 177 alternative_service_ = alternative_service; | |
| 178 if (alternative_service.protocol == QUIC) { | |
| 179 DCHECK(session_->params().enable_quic); | |
| 180 using_quic_ = true; | |
| 181 } | |
| 182 } | |
| 183 | |
| 184 void HttpStreamFactoryImpl::Job::WaitFor(Job* job) { | 182 void HttpStreamFactoryImpl::Job::WaitFor(Job* job) { |
| 185 DCHECK_EQ(STATE_NONE, next_state_); | 183 DCHECK_EQ(STATE_NONE, next_state_); |
| 186 DCHECK_EQ(STATE_NONE, job->next_state_); | 184 DCHECK_EQ(STATE_NONE, job->next_state_); |
| 187 DCHECK(!blocking_job_); | 185 DCHECK(!blocking_job_); |
| 188 DCHECK(!job->waiting_job_); | 186 DCHECK(!job->waiting_job_); |
| 189 blocking_job_ = job; | 187 blocking_job_ = job; |
| 190 job->waiting_job_ = this; | 188 job->waiting_job_ = this; |
| 191 } | 189 } |
| 192 | 190 |
| 193 void HttpStreamFactoryImpl::Job::Resume(Job* job) { | 191 void HttpStreamFactoryImpl::Job::Resume(Job* job) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 280 |
| 283 bool HttpStreamFactoryImpl::Job::CanUseExistingSpdySession() const { | 281 bool HttpStreamFactoryImpl::Job::CanUseExistingSpdySession() const { |
| 284 // We need to make sure that if a spdy session was created for | 282 // We need to make sure that if a spdy session was created for |
| 285 // https://somehost/ that we don't use that session for http://somehost:443/. | 283 // https://somehost/ that we don't use that session for http://somehost:443/. |
| 286 // The only time we can use an existing session is if the request URL is | 284 // The only time we can use an existing session is if the request URL is |
| 287 // https (the normal case) or if we're connection to a SPDY proxy. | 285 // https (the normal case) or if we're connection to a SPDY proxy. |
| 288 // https://crbug.com/133176 | 286 // https://crbug.com/133176 |
| 289 // TODO(ricea): Add "wss" back to this list when SPDY WebSocket support is | 287 // TODO(ricea): Add "wss" back to this list when SPDY WebSocket support is |
| 290 // working. | 288 // working. |
| 291 return origin_url_.SchemeIs("https") || | 289 return origin_url_.SchemeIs("https") || |
| 292 proxy_info_.proxy_server().is_https() || IsSpdyAlternate(); | 290 proxy_info_.proxy_server().is_https() || is_spdy_alternative_; |
| 293 } | 291 } |
| 294 | 292 |
| 295 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { | 293 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { |
| 296 DCHECK(stream_.get()); | 294 DCHECK(stream_.get()); |
| 297 DCHECK(!IsPreconnecting()); | 295 DCHECK(!IsPreconnecting()); |
| 298 DCHECK(!stream_factory_->for_websockets_); | 296 DCHECK(!stream_factory_->for_websockets_); |
| 299 | 297 |
| 300 MaybeCopyConnectionAttemptsFromSocketOrHandle(); | 298 MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
| 301 | 299 |
| 302 if (IsOrphaned()) { | 300 if (IsOrphaned()) { |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 } else { | 546 } else { |
| 549 DCHECK(stream_.get()); | 547 DCHECK(stream_.get()); |
| 550 base::MessageLoop::current()->PostTask( | 548 base::MessageLoop::current()->PostTask( |
| 551 FROM_HERE, | 549 FROM_HERE, |
| 552 base::Bind(&Job::OnStreamReadyCallback, ptr_factory_.GetWeakPtr())); | 550 base::Bind(&Job::OnStreamReadyCallback, ptr_factory_.GetWeakPtr())); |
| 553 } | 551 } |
| 554 return ERR_IO_PENDING; | 552 return ERR_IO_PENDING; |
| 555 | 553 |
| 556 default: | 554 default: |
| 557 DCHECK(result != ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN || | 555 DCHECK(result != ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN || |
| 558 IsAlternate()); | 556 is_spdy_alternative_ || is_quic_alternative_); |
| 559 if (job_status_ != STATUS_BROKEN) { | 557 if (job_status_ != STATUS_BROKEN) { |
| 560 DCHECK_EQ(STATUS_RUNNING, job_status_); | 558 DCHECK_EQ(STATUS_RUNNING, job_status_); |
| 561 job_status_ = STATUS_FAILED; | 559 job_status_ = STATUS_FAILED; |
| 562 // TODO(bnc): If (result == ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN), | 560 // TODO(bnc): If (result == ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN), |
| 563 // then instead of marking alternative service broken, mark (origin, | 561 // then instead of marking alternative service broken, mark (origin, |
| 564 // alternative service) couple as invalid. | 562 // alternative service) couple as invalid. |
| 565 MaybeMarkAlternativeServiceBroken(); | 563 MaybeMarkAlternativeServiceBroken(); |
| 566 } | 564 } |
| 567 base::MessageLoop::current()->PostTask( | 565 base::MessageLoop::current()->PostTask( |
| 568 FROM_HERE, | 566 FROM_HERE, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 | 630 |
| 633 int HttpStreamFactoryImpl::Job::StartInternal() { | 631 int HttpStreamFactoryImpl::Job::StartInternal() { |
| 634 CHECK_EQ(STATE_NONE, next_state_); | 632 CHECK_EQ(STATE_NONE, next_state_); |
| 635 next_state_ = STATE_START; | 633 next_state_ = STATE_START; |
| 636 int rv = RunLoop(OK); | 634 int rv = RunLoop(OK); |
| 637 DCHECK_EQ(ERR_IO_PENDING, rv); | 635 DCHECK_EQ(ERR_IO_PENDING, rv); |
| 638 return rv; | 636 return rv; |
| 639 } | 637 } |
| 640 | 638 |
| 641 int HttpStreamFactoryImpl::Job::DoStart() { | 639 int HttpStreamFactoryImpl::Job::DoStart() { |
| 642 if (IsAlternate()) { | 640 if (is_spdy_alternative_ || is_quic_alternative_) { |
| 643 server_ = alternative_service_.host_port_pair(); | 641 server_ = alternative_service_.host_port_pair(); |
| 644 } else { | 642 } else { |
| 645 server_ = HostPortPair::FromURL(request_info_.url); | 643 server_ = HostPortPair::FromURL(request_info_.url); |
| 646 } | 644 } |
| 647 origin_url_ = | 645 origin_url_ = |
| 648 stream_factory_->ApplyHostMappingRules(request_info_.url, &server_); | 646 stream_factory_->ApplyHostMappingRules(request_info_.url, &server_); |
| 649 valid_spdy_session_pool_.reset(new ValidSpdySessionPool( | 647 valid_spdy_session_pool_.reset(new ValidSpdySessionPool( |
| 650 session_->spdy_session_pool(), origin_url_, IsSpdyAlternate())); | 648 session_->spdy_session_pool(), origin_url_, is_spdy_alternative_)); |
| 651 | 649 |
| 652 net_log_.BeginEvent( | 650 net_log_.BeginEvent( |
| 653 NetLog::TYPE_HTTP_STREAM_JOB, | 651 NetLog::TYPE_HTTP_STREAM_JOB, |
| 654 base::Bind(&NetLogHttpStreamJobCallback, &request_info_.url, &origin_url_, | 652 base::Bind(&NetLogHttpStreamJobCallback, &request_info_.url, &origin_url_, |
| 655 &alternative_service_, priority_)); | 653 &alternative_service_, priority_)); |
| 656 | 654 |
| 657 // Don't connect to restricted ports. | 655 // Don't connect to restricted ports. |
| 658 bool is_port_allowed = IsPortAllowedByDefault(server_.port()); | 656 bool is_port_allowed = IsPortAllowedByDefault(server_.port()); |
| 659 if (request_info_.url.SchemeIs("ftp")) { | 657 if (request_info_.url.SchemeIs("ftp")) { |
| 660 // Never share connection with other jobs for FTP requests. | 658 // Never share connection with other jobs for FTP requests. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 684 proxy_info_.UseDirect(); | 682 proxy_info_.UseDirect(); |
| 685 return OK; | 683 return OK; |
| 686 } | 684 } |
| 687 | 685 |
| 688 // TODO(rch): remove this code since Alt-Svc seems to prohibit it. | 686 // TODO(rch): remove this code since Alt-Svc seems to prohibit it. |
| 689 GURL url_for_proxy = origin_url_; | 687 GURL url_for_proxy = origin_url_; |
| 690 // For SPDY via Alt-Svc, set |alternative_service_url_| to | 688 // For SPDY via Alt-Svc, set |alternative_service_url_| to |
| 691 // https://<alternative host>:<alternative port>/... | 689 // https://<alternative host>:<alternative port>/... |
| 692 // so the proxy resolution works with the actual destination, and so | 690 // so the proxy resolution works with the actual destination, and so |
| 693 // that the correct socket pool is used. | 691 // that the correct socket pool is used. |
| 694 if (IsSpdyAlternate()) { | 692 if (is_spdy_alternative_) { |
| 695 // TODO(rch): Figure out how to make QUIC iteract with PAC | 693 // TODO(rch): Figure out how to make QUIC iteract with PAC |
| 696 // scripts. By not re-writing the URL, we will query the PAC script | 694 // scripts. By not re-writing the URL, we will query the PAC script |
| 697 // for the proxy to use to reach the original URL via TCP. But | 695 // for the proxy to use to reach the original URL via TCP. But |
| 698 // the alternate request will be going via UDP to a different port. | 696 // the alternate request will be going via UDP to a different port. |
| 699 GURL::Replacements replacements; | 697 GURL::Replacements replacements; |
| 700 // new_port needs to be in scope here because GURL::Replacements references | 698 // new_port needs to be in scope here because GURL::Replacements references |
| 701 // the memory contained by it directly. | 699 // the memory contained by it directly. |
| 702 const std::string new_port = base::IntToString(alternative_service_.port); | 700 const std::string new_port = base::IntToString(alternative_service_.port); |
| 703 replacements.SetSchemeStr("https"); | 701 replacements.SetSchemeStr("https"); |
| 704 replacements.SetPortStr(new_port); | 702 replacements.SetPortStr(new_port); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 725 | 723 |
| 726 proxy_info_.RemoveProxiesWithoutScheme(supported_proxies); | 724 proxy_info_.RemoveProxiesWithoutScheme(supported_proxies); |
| 727 | 725 |
| 728 if (proxy_info_.is_empty()) { | 726 if (proxy_info_.is_empty()) { |
| 729 // No proxies/direct to choose from. This happens when we don't support | 727 // No proxies/direct to choose from. This happens when we don't support |
| 730 // any of the proxies in the returned list. | 728 // any of the proxies in the returned list. |
| 731 result = ERR_NO_SUPPORTED_PROXIES; | 729 result = ERR_NO_SUPPORTED_PROXIES; |
| 732 } else if (using_quic_ && | 730 } else if (using_quic_ && |
| 733 (!proxy_info_.is_quic() && !proxy_info_.is_direct())) { | 731 (!proxy_info_.is_quic() && !proxy_info_.is_direct())) { |
| 734 // QUIC can not be spoken to non-QUIC proxies. This error should not be | 732 // QUIC can not be spoken to non-QUIC proxies. This error should not be |
| 735 // user visible, because the non-alternate job should be resumed. | 733 // user visible, because the non-alternative Job should be resumed. |
| 736 result = ERR_NO_SUPPORTED_PROXIES; | 734 result = ERR_NO_SUPPORTED_PROXIES; |
| 737 } | 735 } |
| 738 } | 736 } |
| 739 | 737 |
| 740 if (result != OK) { | 738 if (result != OK) { |
| 741 if (waiting_job_) { | 739 if (waiting_job_) { |
| 742 waiting_job_->Resume(this); | 740 waiting_job_->Resume(this); |
| 743 waiting_job_ = NULL; | 741 waiting_job_ = NULL; |
| 744 } | 742 } |
| 745 return result; | 743 return result; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 775 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462812 is fixed. | 773 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462812 is fixed. |
| 776 tracked_objects::ScopedTracker tracking_profile( | 774 tracked_objects::ScopedTracker tracking_profile( |
| 777 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 775 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 778 "462812 HttpStreamFactoryImpl::Job::DoInitConnection")); | 776 "462812 HttpStreamFactoryImpl::Job::DoInitConnection")); |
| 779 DCHECK(!blocking_job_); | 777 DCHECK(!blocking_job_); |
| 780 DCHECK(!connection_->is_initialized()); | 778 DCHECK(!connection_->is_initialized()); |
| 781 DCHECK(proxy_info_.proxy_server().is_valid()); | 779 DCHECK(proxy_info_.proxy_server().is_valid()); |
| 782 next_state_ = STATE_INIT_CONNECTION_COMPLETE; | 780 next_state_ = STATE_INIT_CONNECTION_COMPLETE; |
| 783 | 781 |
| 784 using_ssl_ = origin_url_.SchemeIs("https") || origin_url_.SchemeIs("wss") || | 782 using_ssl_ = origin_url_.SchemeIs("https") || origin_url_.SchemeIs("wss") || |
| 785 IsSpdyAlternate(); | 783 is_spdy_alternative_; |
| 786 using_spdy_ = false; | 784 using_spdy_ = false; |
| 787 | 785 |
| 788 if (ShouldForceQuic()) | 786 if (ShouldForceQuic()) |
| 789 using_quic_ = true; | 787 using_quic_ = true; |
| 790 | 788 |
| 791 DCHECK(!using_quic_ || session_->params().enable_quic); | 789 DCHECK(!using_quic_ || session_->params().enable_quic); |
| 792 | 790 |
| 793 if (proxy_info_.is_quic()) { | 791 if (proxy_info_.is_quic()) { |
| 794 using_quic_ = true; | 792 using_quic_ = true; |
| 795 DCHECK(session_->params().enable_quic_for_proxies); | 793 DCHECK(session_->params().enable_quic_for_proxies); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 // OK, there's no available SPDY session. Let |waiting_job_| resume if it's | 848 // OK, there's no available SPDY session. Let |waiting_job_| resume if it's |
| 851 // paused. | 849 // paused. |
| 852 if (waiting_job_) { | 850 if (waiting_job_) { |
| 853 waiting_job_->Resume(this); | 851 waiting_job_->Resume(this); |
| 854 waiting_job_ = NULL; | 852 waiting_job_ = NULL; |
| 855 } | 853 } |
| 856 | 854 |
| 857 if (proxy_info_.is_http() || proxy_info_.is_https()) | 855 if (proxy_info_.is_http() || proxy_info_.is_https()) |
| 858 establishing_tunnel_ = using_ssl_; | 856 establishing_tunnel_ = using_ssl_; |
| 859 | 857 |
| 860 // TODO(bnc): s/want_spdy_over_npn/expect_spdy_over_npn/ | |
| 861 bool want_spdy_over_npn = IsAlternate(); | |
| 862 | |
| 863 if (proxy_info_.is_https()) { | 858 if (proxy_info_.is_https()) { |
| 864 InitSSLConfig(proxy_info_.proxy_server().host_port_pair(), | 859 InitSSLConfig(proxy_info_.proxy_server().host_port_pair(), |
| 865 &proxy_ssl_config_, | 860 &proxy_ssl_config_, |
| 866 true /* is a proxy server */); | 861 true /* is a proxy server */); |
| 867 // Disable revocation checking for HTTPS proxies since the revocation | 862 // Disable revocation checking for HTTPS proxies since the revocation |
| 868 // requests are probably going to need to go through the proxy too. | 863 // requests are probably going to need to go through the proxy too. |
| 869 proxy_ssl_config_.rev_checking_enabled = false; | 864 proxy_ssl_config_.rev_checking_enabled = false; |
| 870 } | 865 } |
| 871 if (using_ssl_) { | 866 if (using_ssl_) { |
| 872 InitSSLConfig(server_, &server_ssl_config_, false /* not a proxy server */); | 867 InitSSLConfig(server_, &server_ssl_config_, false /* not a proxy server */); |
| 873 } | 868 } |
| 874 | 869 |
| 875 base::WeakPtr<HttpServerProperties> http_server_properties = | 870 base::WeakPtr<HttpServerProperties> http_server_properties = |
| 876 session_->http_server_properties(); | 871 session_->http_server_properties(); |
| 877 if (http_server_properties) { | 872 if (http_server_properties) { |
| 878 http_server_properties->MaybeForceHTTP11(server_, &server_ssl_config_); | 873 http_server_properties->MaybeForceHTTP11(server_, &server_ssl_config_); |
| 879 if (proxy_info_.is_http() || proxy_info_.is_https()) { | 874 if (proxy_info_.is_http() || proxy_info_.is_https()) { |
| 880 http_server_properties->MaybeForceHTTP11( | 875 http_server_properties->MaybeForceHTTP11( |
| 881 proxy_info_.proxy_server().host_port_pair(), &proxy_ssl_config_); | 876 proxy_info_.proxy_server().host_port_pair(), &proxy_ssl_config_); |
| 882 } | 877 } |
| 883 } | 878 } |
| 884 | 879 |
| 885 if (IsPreconnecting()) { | 880 if (IsPreconnecting()) { |
| 886 DCHECK(!stream_factory_->for_websockets_); | 881 DCHECK(!stream_factory_->for_websockets_); |
| 887 return PreconnectSocketsForHttpRequest( | 882 return PreconnectSocketsForHttpRequest( |
| 888 GetSocketGroup(), server_, request_info_.extra_headers, | 883 GetSocketGroup(), server_, request_info_.extra_headers, |
| 889 request_info_.load_flags, priority_, session_, proxy_info_, | 884 request_info_.load_flags, priority_, session_, proxy_info_, |
| 890 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, | 885 /*want_spdy_over_npn=*/is_spdy_alternative_, server_ssl_config_, |
| 891 request_info_.privacy_mode, net_log_, num_streams_); | 886 proxy_ssl_config_, request_info_.privacy_mode, net_log_, num_streams_); |
| 892 } | 887 } |
| 893 | 888 |
| 894 // If we can't use a SPDY session, don't bother checking for one after | 889 // If we can't use a SPDY session, don't bother checking for one after |
| 895 // the hostname is resolved. | 890 // the hostname is resolved. |
| 896 OnHostResolutionCallback resolution_callback = | 891 OnHostResolutionCallback resolution_callback = |
| 897 CanUseExistingSpdySession() | 892 CanUseExistingSpdySession() |
| 898 ? base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), | 893 ? base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), |
| 899 spdy_session_key) | 894 spdy_session_key) |
| 900 : OnHostResolutionCallback(); | 895 : OnHostResolutionCallback(); |
| 901 if (stream_factory_->for_websockets_) { | 896 if (stream_factory_->for_websockets_) { |
| 902 // TODO(ricea): Re-enable NPN when WebSockets over SPDY is supported. | 897 // TODO(ricea): Re-enable NPN when WebSockets over SPDY is supported. |
| 903 SSLConfig websocket_server_ssl_config = server_ssl_config_; | 898 SSLConfig websocket_server_ssl_config = server_ssl_config_; |
| 904 websocket_server_ssl_config.next_protos.clear(); | 899 websocket_server_ssl_config.next_protos.clear(); |
| 905 return InitSocketHandleForWebSocketRequest( | 900 return InitSocketHandleForWebSocketRequest( |
| 906 GetSocketGroup(), server_, request_info_.extra_headers, | 901 GetSocketGroup(), server_, request_info_.extra_headers, |
| 907 request_info_.load_flags, priority_, session_, proxy_info_, | 902 request_info_.load_flags, priority_, session_, proxy_info_, |
| 908 want_spdy_over_npn, websocket_server_ssl_config, proxy_ssl_config_, | 903 /*want_spdy_over_npn=*/is_spdy_alternative_, |
| 904 websocket_server_ssl_config, proxy_ssl_config_, |
| 909 request_info_.privacy_mode, net_log_, connection_.get(), | 905 request_info_.privacy_mode, net_log_, connection_.get(), |
| 910 resolution_callback, io_callback_); | 906 resolution_callback, io_callback_); |
| 911 } | 907 } |
| 912 | 908 |
| 913 return InitSocketHandleForHttpRequest( | 909 return InitSocketHandleForHttpRequest( |
| 914 GetSocketGroup(), server_, request_info_.extra_headers, | 910 GetSocketGroup(), server_, request_info_.extra_headers, |
| 915 request_info_.load_flags, priority_, session_, proxy_info_, | 911 request_info_.load_flags, priority_, session_, proxy_info_, |
| 916 want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, | 912 /*want_spdy_over_npn=*/is_spdy_alternative_, server_ssl_config_, |
| 917 request_info_.privacy_mode, net_log_, connection_.get(), | 913 proxy_ssl_config_, request_info_.privacy_mode, net_log_, |
| 918 resolution_callback, io_callback_); | 914 connection_.get(), resolution_callback, io_callback_); |
| 919 } | 915 } |
| 920 | 916 |
| 921 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { | 917 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { |
| 922 if (IsPreconnecting()) { | 918 if (IsPreconnecting()) { |
| 923 if (using_quic_) | 919 if (using_quic_) |
| 924 return result; | 920 return result; |
| 925 DCHECK_EQ(OK, result); | 921 DCHECK_EQ(OK, result); |
| 926 return OK; | 922 return OK; |
| 927 } | 923 } |
| 928 | 924 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 // Other state (i.e. |using_ssl_|) suggests that |connection_| will have an | 1003 // Other state (i.e. |using_ssl_|) suggests that |connection_| will have an |
| 1008 // SSL socket, but there was an error before that could happen. This | 1004 // SSL socket, but there was an error before that could happen. This |
| 1009 // puts the in progress HttpProxy socket into |connection_| in order to | 1005 // puts the in progress HttpProxy socket into |connection_| in order to |
| 1010 // complete the auth (or read the response body). The tunnel restart code | 1006 // complete the auth (or read the response body). The tunnel restart code |
| 1011 // is careful to remove it before returning control to the rest of this | 1007 // is careful to remove it before returning control to the rest of this |
| 1012 // class. | 1008 // class. |
| 1013 connection_.reset(connection_->release_pending_http_proxy_connection()); | 1009 connection_.reset(connection_->release_pending_http_proxy_connection()); |
| 1014 return result; | 1010 return result; |
| 1015 } | 1011 } |
| 1016 | 1012 |
| 1017 if (IsSpdyAlternate() && !using_spdy_) { | 1013 if (is_spdy_alternative_ && !using_spdy_) { |
| 1018 job_status_ = STATUS_BROKEN; | 1014 job_status_ = STATUS_BROKEN; |
| 1019 MaybeMarkAlternativeServiceBroken(); | 1015 MaybeMarkAlternativeServiceBroken(); |
| 1020 return ERR_NPN_NEGOTIATION_FAILED; | 1016 return ERR_NPN_NEGOTIATION_FAILED; |
| 1021 } | 1017 } |
| 1022 | 1018 |
| 1023 if (!ssl_started && result < 0 && IsAlternate()) { | 1019 if (!ssl_started && result < 0 && |
| 1020 (is_spdy_alternative_ || is_quic_alternative_)) { |
| 1024 job_status_ = STATUS_BROKEN; | 1021 job_status_ = STATUS_BROKEN; |
| 1025 // TODO(bnc): if (result == ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN), then | 1022 // TODO(bnc): if (result == ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN), then |
| 1026 // instead of marking alternative service broken, mark (origin, alternative | 1023 // instead of marking alternative service broken, mark (origin, alternative |
| 1027 // service) couple as invalid. | 1024 // service) couple as invalid. |
| 1028 MaybeMarkAlternativeServiceBroken(); | 1025 MaybeMarkAlternativeServiceBroken(); |
| 1029 return result; | 1026 return result; |
| 1030 } | 1027 } |
| 1031 | 1028 |
| 1032 if (using_quic_) { | 1029 if (using_quic_) { |
| 1033 if (result < 0) { | 1030 if (result < 0) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1049 if (!connection_->is_reused()) { | 1046 if (!connection_->is_reused()) { |
| 1050 ConnectionType type = using_spdy_ ? CONNECTION_SPDY : CONNECTION_HTTP; | 1047 ConnectionType type = using_spdy_ ? CONNECTION_SPDY : CONNECTION_HTTP; |
| 1051 UpdateConnectionTypeHistograms(type); | 1048 UpdateConnectionTypeHistograms(type); |
| 1052 } | 1049 } |
| 1053 } | 1050 } |
| 1054 | 1051 |
| 1055 // Handle SSL errors below. | 1052 // Handle SSL errors below. |
| 1056 if (using_ssl_) { | 1053 if (using_ssl_) { |
| 1057 DCHECK(ssl_started); | 1054 DCHECK(ssl_started); |
| 1058 if (IsCertificateError(result)) { | 1055 if (IsCertificateError(result)) { |
| 1059 if (using_spdy_ && IsAlternate() && origin_url_.SchemeIs("http")) { | 1056 if (is_spdy_alternative_ && origin_url_.SchemeIs("http")) { |
| 1060 // We ignore certificate errors for http over spdy. | 1057 // We ignore certificate errors for http over spdy. |
| 1061 spdy_certificate_error_ = result; | 1058 spdy_certificate_error_ = result; |
| 1062 result = OK; | 1059 result = OK; |
| 1063 } else { | 1060 } else { |
| 1064 result = HandleCertificateError(result); | 1061 result = HandleCertificateError(result); |
| 1065 if (result == OK && !connection_->socket()->IsConnectedAndIdle()) { | 1062 if (result == OK && !connection_->socket()->IsConnectedAndIdle()) { |
| 1066 ReturnToStateInitConnection(true /* close connection */); | 1063 ReturnToStateInitConnection(true /* close connection */); |
| 1067 return result; | 1064 return result; |
| 1068 } | 1065 } |
| 1069 } | 1066 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1100 stream_.reset(new SpdyHttpStream(session, use_relative_url)); | 1097 stream_.reset(new SpdyHttpStream(session, use_relative_url)); |
| 1101 return OK; | 1098 return OK; |
| 1102 } | 1099 } |
| 1103 | 1100 |
| 1104 int HttpStreamFactoryImpl::Job::DoCreateStream() { | 1101 int HttpStreamFactoryImpl::Job::DoCreateStream() { |
| 1105 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462811 is fixed. | 1102 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462811 is fixed. |
| 1106 tracked_objects::ScopedTracker tracking_profile( | 1103 tracked_objects::ScopedTracker tracking_profile( |
| 1107 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1104 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1108 "462811 HttpStreamFactoryImpl::Job::DoCreateStream")); | 1105 "462811 HttpStreamFactoryImpl::Job::DoCreateStream")); |
| 1109 DCHECK(connection_->socket() || existing_spdy_session_.get() || using_quic_); | 1106 DCHECK(connection_->socket() || existing_spdy_session_.get() || using_quic_); |
| 1110 if (IsAlternate()) | 1107 DCHECK(!is_quic_alternative_); |
| 1111 DCHECK(IsSpdyAlternate()); | |
| 1112 | 1108 |
| 1113 next_state_ = STATE_CREATE_STREAM_COMPLETE; | 1109 next_state_ = STATE_CREATE_STREAM_COMPLETE; |
| 1114 | 1110 |
| 1115 // We only set the socket motivation if we're the first to use | 1111 // We only set the socket motivation if we're the first to use |
| 1116 // this socket. Is there a race for two SPDY requests? We really | 1112 // this socket. Is there a race for two SPDY requests? We really |
| 1117 // need to plumb this through to the connect level. | 1113 // need to plumb this through to the connect level. |
| 1118 if (connection_->socket() && !connection_->is_reused()) | 1114 if (connection_->socket() && !connection_->is_reused()) |
| 1119 SetSocketMotivation(); | 1115 SetSocketMotivation(); |
| 1120 | 1116 |
| 1121 if (!using_spdy_) { | 1117 if (!using_spdy_) { |
| 1122 DCHECK(!IsSpdyAlternate()); | 1118 DCHECK(!is_spdy_alternative_); |
| 1123 // We may get ftp scheme when fetching ftp resources through proxy. | 1119 // We may get ftp scheme when fetching ftp resources through proxy. |
| 1124 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && | 1120 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && |
| 1125 (request_info_.url.SchemeIs("http") || | 1121 (request_info_.url.SchemeIs("http") || |
| 1126 request_info_.url.SchemeIs("ftp")); | 1122 request_info_.url.SchemeIs("ftp")); |
| 1127 if (stream_factory_->for_websockets_) { | 1123 if (stream_factory_->for_websockets_) { |
| 1128 DCHECK(request_); | 1124 DCHECK(request_); |
| 1129 DCHECK(request_->websocket_handshake_stream_create_helper()); | 1125 DCHECK(request_->websocket_handshake_stream_create_helper()); |
| 1130 websocket_stream_.reset( | 1126 websocket_stream_.reset( |
| 1131 request_->websocket_handshake_stream_create_helper() | 1127 request_->websocket_handshake_stream_create_helper() |
| 1132 ->CreateBasicStream(connection_.Pass(), using_proxy)); | 1128 ->CreateBasicStream(connection_.Pass(), using_proxy)); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 if (request_info_.motivation == HttpRequestInfo::PRECONNECT_MOTIVATED) | 1238 if (request_info_.motivation == HttpRequestInfo::PRECONNECT_MOTIVATED) |
| 1243 connection_->socket()->SetSubresourceSpeculation(); | 1239 connection_->socket()->SetSubresourceSpeculation(); |
| 1244 else if (request_info_.motivation == HttpRequestInfo::OMNIBOX_MOTIVATED) | 1240 else if (request_info_.motivation == HttpRequestInfo::OMNIBOX_MOTIVATED) |
| 1245 connection_->socket()->SetOmniboxSpeculation(); | 1241 connection_->socket()->SetOmniboxSpeculation(); |
| 1246 // TODO(mbelshe): Add other motivations (like EARLY_LOAD_MOTIVATED). | 1242 // TODO(mbelshe): Add other motivations (like EARLY_LOAD_MOTIVATED). |
| 1247 } | 1243 } |
| 1248 | 1244 |
| 1249 bool HttpStreamFactoryImpl::Job::IsHttpsProxyAndHttpUrl() const { | 1245 bool HttpStreamFactoryImpl::Job::IsHttpsProxyAndHttpUrl() const { |
| 1250 if (!proxy_info_.is_https()) | 1246 if (!proxy_info_.is_https()) |
| 1251 return false; | 1247 return false; |
| 1252 if (IsAlternate()) { | 1248 if (is_spdy_alternative_ || is_quic_alternative_) { |
| 1253 // We currently only support Alternate-Protocol where the original scheme | 1249 // We currently only support Alternate-Protocol where the original scheme |
| 1254 // is http. | 1250 // is http. |
| 1255 DCHECK(origin_url_.SchemeIs("http")); | 1251 DCHECK(origin_url_.SchemeIs("http")); |
| 1256 return origin_url_.SchemeIs("http"); | 1252 return origin_url_.SchemeIs("http"); |
| 1257 } | 1253 } |
| 1258 return request_info_.url.SchemeIs("http"); | 1254 return request_info_.url.SchemeIs("http"); |
| 1259 } | 1255 } |
| 1260 | 1256 |
| 1261 bool HttpStreamFactoryImpl::Job::IsAlternate() const { | |
| 1262 return alternative_service_.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL; | |
| 1263 } | |
| 1264 | |
| 1265 bool HttpStreamFactoryImpl::Job::IsSpdyAlternate() const { | |
| 1266 return alternative_service_.protocol >= NPN_SPDY_MINIMUM_VERSION && | |
| 1267 alternative_service_.protocol <= NPN_SPDY_MAXIMUM_VERSION; | |
| 1268 } | |
| 1269 | |
| 1270 void HttpStreamFactoryImpl::Job::InitSSLConfig(const HostPortPair& server, | 1257 void HttpStreamFactoryImpl::Job::InitSSLConfig(const HostPortPair& server, |
| 1271 SSLConfig* ssl_config, | 1258 SSLConfig* ssl_config, |
| 1272 bool is_proxy) const { | 1259 bool is_proxy) const { |
| 1273 if (!is_proxy) { | 1260 if (!is_proxy) { |
| 1274 // Prior to HTTP/2 and SPDY, some servers use TLS renegotiation to request | 1261 // Prior to HTTP/2 and SPDY, some servers use TLS renegotiation to request |
| 1275 // TLS client authentication after the HTTP request was sent. Allow | 1262 // TLS client authentication after the HTTP request was sent. Allow |
| 1276 // renegotiation for only those connections. | 1263 // renegotiation for only those connections. |
| 1277 // | 1264 // |
| 1278 // Note that this does NOT implement the provision in | 1265 // Note that this does NOT implement the provision in |
| 1279 // https://http2.github.io/http2-spec/#rfc.section.9.2.1 which allows the | 1266 // https://http2.github.io/http2-spec/#rfc.section.9.2.1 which allows the |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1430 | 1417 |
| 1431 bool HttpStreamFactoryImpl::Job::IsOrphaned() const { | 1418 bool HttpStreamFactoryImpl::Job::IsOrphaned() const { |
| 1432 return !IsPreconnecting() && !request_; | 1419 return !IsPreconnecting() && !request_; |
| 1433 } | 1420 } |
| 1434 | 1421 |
| 1435 void HttpStreamFactoryImpl::Job::ReportJobSucceededForRequest() { | 1422 void HttpStreamFactoryImpl::Job::ReportJobSucceededForRequest() { |
| 1436 if (using_existing_quic_session_) { | 1423 if (using_existing_quic_session_) { |
| 1437 // If an existing session was used, then no TCP connection was | 1424 // If an existing session was used, then no TCP connection was |
| 1438 // started. | 1425 // started. |
| 1439 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE); | 1426 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE); |
| 1440 } else if (IsAlternate()) { | 1427 } else if (is_spdy_alternative_ || is_quic_alternative_) { |
| 1441 // This job was the alternate protocol job, and hence won the race. | 1428 // This Job was the alternative Job, and hence won the race. |
| 1442 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE); | 1429 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE); |
| 1443 } else { | 1430 } else { |
| 1444 // This job was the normal job, and hence the alternate protocol job lost | 1431 // This Job was the normal Job, and hence the alternative Job lost the race. |
| 1445 // the race. | |
| 1446 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_LOST_RACE); | 1432 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_LOST_RACE); |
| 1447 } | 1433 } |
| 1448 } | 1434 } |
| 1449 | 1435 |
| 1450 void HttpStreamFactoryImpl::Job::MarkOtherJobComplete(const Job& job) { | 1436 void HttpStreamFactoryImpl::Job::MarkOtherJobComplete(const Job& job) { |
| 1451 DCHECK_EQ(STATUS_RUNNING, other_job_status_); | 1437 DCHECK_EQ(STATUS_RUNNING, other_job_status_); |
| 1452 other_job_status_ = job.job_status_; | 1438 other_job_status_ = job.job_status_; |
| 1453 other_job_alternative_service_ = job.alternative_service_; | 1439 other_job_alternative_service_ = job.alternative_service_; |
| 1454 MaybeMarkAlternativeServiceBroken(); | 1440 MaybeMarkAlternativeServiceBroken(); |
| 1455 } | 1441 } |
| 1456 | 1442 |
| 1457 void HttpStreamFactoryImpl::Job::MaybeMarkAlternativeServiceBroken() { | 1443 void HttpStreamFactoryImpl::Job::MaybeMarkAlternativeServiceBroken() { |
| 1458 if (job_status_ == STATUS_RUNNING || other_job_status_ == STATUS_RUNNING) | 1444 if (job_status_ == STATUS_RUNNING || other_job_status_ == STATUS_RUNNING) |
| 1459 return; | 1445 return; |
| 1460 | 1446 |
| 1461 if (IsAlternate()) { | 1447 if (is_spdy_alternative_ || is_quic_alternative_) { |
| 1462 if (job_status_ == STATUS_BROKEN && other_job_status_ == STATUS_SUCCEEDED) { | 1448 if (job_status_ == STATUS_BROKEN && other_job_status_ == STATUS_SUCCEEDED) { |
| 1463 HistogramBrokenAlternateProtocolLocation( | 1449 HistogramBrokenAlternateProtocolLocation( |
| 1464 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_ALT); | 1450 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_ALT); |
| 1465 session_->http_server_properties()->MarkAlternativeServiceBroken( | 1451 session_->http_server_properties()->MarkAlternativeServiceBroken( |
| 1466 alternative_service_); | 1452 alternative_service_); |
| 1467 } | 1453 } |
| 1468 return; | 1454 return; |
| 1469 } | 1455 } |
| 1470 | 1456 |
| 1471 if (job_status_ == STATUS_SUCCEEDED && other_job_status_ == STATUS_BROKEN) { | 1457 if (job_status_ == STATUS_SUCCEEDED && other_job_status_ == STATUS_BROKEN) { |
| 1472 HistogramBrokenAlternateProtocolLocation( | 1458 HistogramBrokenAlternateProtocolLocation( |
| 1473 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_MAIN); | 1459 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_MAIN); |
| 1474 session_->http_server_properties()->MarkAlternativeServiceBroken( | 1460 session_->http_server_properties()->MarkAlternativeServiceBroken( |
| 1475 other_job_alternative_service_); | 1461 other_job_alternative_service_); |
| 1476 } | 1462 } |
| 1477 } | 1463 } |
| 1478 | 1464 |
| 1479 HttpStreamFactoryImpl::Job::ValidSpdySessionPool::ValidSpdySessionPool( | 1465 HttpStreamFactoryImpl::Job::ValidSpdySessionPool::ValidSpdySessionPool( |
| 1480 SpdySessionPool* spdy_session_pool, | 1466 SpdySessionPool* spdy_session_pool, |
| 1481 GURL& origin_url, | 1467 GURL& origin_url, |
| 1482 bool is_spdy_alternate) | 1468 bool is_spdy_alternative) |
| 1483 : spdy_session_pool_(spdy_session_pool), | 1469 : spdy_session_pool_(spdy_session_pool), |
| 1484 origin_url_(origin_url), | 1470 origin_url_(origin_url), |
| 1485 is_spdy_alternate_(is_spdy_alternate) { | 1471 is_spdy_alternative_(is_spdy_alternative) { |
| 1486 } | 1472 } |
| 1487 | 1473 |
| 1488 int HttpStreamFactoryImpl::Job::ValidSpdySessionPool::FindAvailableSession( | 1474 int HttpStreamFactoryImpl::Job::ValidSpdySessionPool::FindAvailableSession( |
| 1489 const SpdySessionKey& key, | 1475 const SpdySessionKey& key, |
| 1490 const BoundNetLog& net_log, | 1476 const BoundNetLog& net_log, |
| 1491 base::WeakPtr<SpdySession>* spdy_session) { | 1477 base::WeakPtr<SpdySession>* spdy_session) { |
| 1492 *spdy_session = spdy_session_pool_->FindAvailableSession(key, net_log); | 1478 *spdy_session = spdy_session_pool_->FindAvailableSession(key, net_log); |
| 1493 return CheckAlternativeServiceValidityForOrigin(*spdy_session); | 1479 return CheckAlternativeServiceValidityForOrigin(*spdy_session); |
| 1494 } | 1480 } |
| 1495 | 1481 |
| 1496 int HttpStreamFactoryImpl::Job::ValidSpdySessionPool:: | 1482 int HttpStreamFactoryImpl::Job::ValidSpdySessionPool:: |
| 1497 CreateAvailableSessionFromSocket(const SpdySessionKey& key, | 1483 CreateAvailableSessionFromSocket(const SpdySessionKey& key, |
| 1498 scoped_ptr<ClientSocketHandle> connection, | 1484 scoped_ptr<ClientSocketHandle> connection, |
| 1499 const BoundNetLog& net_log, | 1485 const BoundNetLog& net_log, |
| 1500 int certificate_error_code, | 1486 int certificate_error_code, |
| 1501 bool is_secure, | 1487 bool is_secure, |
| 1502 base::WeakPtr<SpdySession>* spdy_session) { | 1488 base::WeakPtr<SpdySession>* spdy_session) { |
| 1503 *spdy_session = spdy_session_pool_->CreateAvailableSessionFromSocket( | 1489 *spdy_session = spdy_session_pool_->CreateAvailableSessionFromSocket( |
| 1504 key, connection.Pass(), net_log, certificate_error_code, is_secure); | 1490 key, connection.Pass(), net_log, certificate_error_code, is_secure); |
| 1505 return CheckAlternativeServiceValidityForOrigin(*spdy_session); | 1491 return CheckAlternativeServiceValidityForOrigin(*spdy_session); |
| 1506 } | 1492 } |
| 1507 | 1493 |
| 1508 int HttpStreamFactoryImpl::Job::ValidSpdySessionPool:: | 1494 int HttpStreamFactoryImpl::Job::ValidSpdySessionPool:: |
| 1509 CheckAlternativeServiceValidityForOrigin( | 1495 CheckAlternativeServiceValidityForOrigin( |
| 1510 base::WeakPtr<SpdySession> spdy_session) { | 1496 base::WeakPtr<SpdySession> spdy_session) { |
| 1511 // For a SPDY alternate Job, server_.host() might be different than | 1497 // For an alternative Job, server_.host() might be different than |
| 1512 // origin_url_.host(), therefore it needs to be verified that the former | 1498 // origin_url_.host(), therefore it needs to be verified that the former |
| 1513 // provides a certificate that is valid for the latter. | 1499 // provides a certificate that is valid for the latter. |
| 1514 if (!is_spdy_alternate_ || !spdy_session || | 1500 if (!is_spdy_alternative_ || !spdy_session || |
| 1515 spdy_session->VerifyDomainAuthentication(origin_url_.host())) { | 1501 spdy_session->VerifyDomainAuthentication(origin_url_.host())) { |
| 1516 return OK; | 1502 return OK; |
| 1517 } | 1503 } |
| 1518 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; | 1504 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; |
| 1519 } | 1505 } |
| 1520 | 1506 |
| 1521 ClientSocketPoolManager::SocketGroupType | 1507 ClientSocketPoolManager::SocketGroupType |
| 1522 HttpStreamFactoryImpl::Job::GetSocketGroup() const { | 1508 HttpStreamFactoryImpl::Job::GetSocketGroup() const { |
| 1523 std::string scheme = origin_url_.scheme(); | 1509 std::string scheme = origin_url_.scheme(); |
| 1524 if (scheme == "https" || scheme == "wss" || IsSpdyAlternate()) | 1510 if (scheme == "https" || scheme == "wss" || is_spdy_alternative_) |
| 1525 return ClientSocketPoolManager::SSL_GROUP; | 1511 return ClientSocketPoolManager::SSL_GROUP; |
| 1526 | 1512 |
| 1527 if (scheme == "ftp") | 1513 if (scheme == "ftp") |
| 1528 return ClientSocketPoolManager::FTP_GROUP; | 1514 return ClientSocketPoolManager::FTP_GROUP; |
| 1529 | 1515 |
| 1530 return ClientSocketPoolManager::NORMAL_GROUP; | 1516 return ClientSocketPoolManager::NORMAL_GROUP; |
| 1531 } | 1517 } |
| 1532 | 1518 |
| 1533 // If the connection succeeds, failed connection attempts leading up to the | 1519 // If the connection succeeds, failed connection attempts leading up to the |
| 1534 // success will be returned via the successfully connected socket. If the | 1520 // success will be returned via the successfully connected socket. If the |
| 1535 // connection fails, failed connection attempts will be returned via the | 1521 // connection fails, failed connection attempts will be returned via the |
| 1536 // ClientSocketHandle. Check whether a socket was returned and copy the | 1522 // ClientSocketHandle. Check whether a socket was returned and copy the |
| 1537 // connection attempts from the proper place. | 1523 // connection attempts from the proper place. |
| 1538 void HttpStreamFactoryImpl::Job:: | 1524 void HttpStreamFactoryImpl::Job:: |
| 1539 MaybeCopyConnectionAttemptsFromSocketOrHandle() { | 1525 MaybeCopyConnectionAttemptsFromSocketOrHandle() { |
| 1540 if (IsOrphaned() || !connection_) | 1526 if (IsOrphaned() || !connection_) |
| 1541 return; | 1527 return; |
| 1542 | 1528 |
| 1543 if (connection_->socket()) { | 1529 if (connection_->socket()) { |
| 1544 ConnectionAttempts socket_attempts; | 1530 ConnectionAttempts socket_attempts; |
| 1545 connection_->socket()->GetConnectionAttempts(&socket_attempts); | 1531 connection_->socket()->GetConnectionAttempts(&socket_attempts); |
| 1546 request_->AddConnectionAttempts(socket_attempts); | 1532 request_->AddConnectionAttempts(socket_attempts); |
| 1547 } else { | 1533 } else { |
| 1548 request_->AddConnectionAttempts(connection_->connection_attempts()); | 1534 request_->AddConnectionAttempts(connection_->connection_attempts()); |
| 1549 } | 1535 } |
| 1550 } | 1536 } |
| 1551 | 1537 |
| 1552 } // namespace net | 1538 } // namespace net |
| OLD | NEW |