| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 // stream. | 141 // stream. |
| 142 std::unique_ptr<base::Value> NetLogHttpStreamProtoCallback( | 142 std::unique_ptr<base::Value> NetLogHttpStreamProtoCallback( |
| 143 NextProto negotiated_protocol, | 143 NextProto negotiated_protocol, |
| 144 NetLogCaptureMode /* capture_mode */) { | 144 NetLogCaptureMode /* capture_mode */) { |
| 145 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 145 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 146 | 146 |
| 147 dict->SetString("proto", NextProtoToString(negotiated_protocol)); | 147 dict->SetString("proto", NextProtoToString(negotiated_protocol)); |
| 148 return std::move(dict); | 148 return std::move(dict); |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Returns parameters associated with the proxy resolution. | |
| 152 std::unique_ptr<base::Value> NetLogHttpStreamJobProxyServerResolved( | |
| 153 const ProxyServer& proxy_server, | |
| 154 NetLogCaptureMode /* capture_mode */) { | |
| 155 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 156 | |
| 157 dict->SetString("proxy_server", proxy_server.is_valid() | |
| 158 ? proxy_server.ToPacString() | |
| 159 : std::string()); | |
| 160 return std::move(dict); | |
| 161 } | |
| 162 | |
| 163 HttpStreamFactoryImpl::Job::Job(Delegate* delegate, | 151 HttpStreamFactoryImpl::Job::Job(Delegate* delegate, |
| 164 JobType job_type, | 152 JobType job_type, |
| 165 HttpNetworkSession* session, | 153 HttpNetworkSession* session, |
| 166 const HttpRequestInfo& request_info, | 154 const HttpRequestInfo& request_info, |
| 167 RequestPriority priority, | 155 RequestPriority priority, |
| 156 ProxyInfo proxy_info, |
| 168 const SSLConfig& server_ssl_config, | 157 const SSLConfig& server_ssl_config, |
| 169 const SSLConfig& proxy_ssl_config, | 158 const SSLConfig& proxy_ssl_config, |
| 170 HostPortPair destination, | 159 HostPortPair destination, |
| 171 GURL origin_url, | 160 GURL origin_url, |
| 172 bool enable_ip_based_pooling, | 161 bool enable_ip_based_pooling, |
| 173 NetLog* net_log) | 162 NetLog* net_log) |
| 174 : Job(delegate, | 163 : Job(delegate, |
| 175 job_type, | 164 job_type, |
| 176 session, | 165 session, |
| 177 request_info, | 166 request_info, |
| 178 priority, | 167 priority, |
| 168 proxy_info, |
| 179 server_ssl_config, | 169 server_ssl_config, |
| 180 proxy_ssl_config, | 170 proxy_ssl_config, |
| 181 destination, | 171 destination, |
| 182 origin_url, | 172 origin_url, |
| 183 AlternativeService(), | 173 AlternativeService(), |
| 184 ProxyServer(), | 174 ProxyServer(), |
| 185 enable_ip_based_pooling, | 175 enable_ip_based_pooling, |
| 186 net_log) {} | 176 net_log) {} |
| 187 | 177 |
| 188 HttpStreamFactoryImpl::Job::Job(Delegate* delegate, | 178 HttpStreamFactoryImpl::Job::Job(Delegate* delegate, |
| 189 JobType job_type, | 179 JobType job_type, |
| 190 HttpNetworkSession* session, | 180 HttpNetworkSession* session, |
| 191 const HttpRequestInfo& request_info, | 181 const HttpRequestInfo& request_info, |
| 192 RequestPriority priority, | 182 RequestPriority priority, |
| 183 ProxyInfo proxy_info, |
| 193 const SSLConfig& server_ssl_config, | 184 const SSLConfig& server_ssl_config, |
| 194 const SSLConfig& proxy_ssl_config, | 185 const SSLConfig& proxy_ssl_config, |
| 195 HostPortPair destination, | 186 HostPortPair destination, |
| 196 GURL origin_url, | 187 GURL origin_url, |
| 197 AlternativeService alternative_service, | 188 AlternativeService alternative_service, |
| 198 const ProxyServer& alternative_proxy_server, | 189 const ProxyServer& alternative_proxy_server, |
| 199 bool enable_ip_based_pooling, | 190 bool enable_ip_based_pooling, |
| 200 NetLog* net_log) | 191 NetLog* net_log) |
| 201 : request_info_(request_info), | 192 : request_info_(request_info), |
| 202 priority_(priority), | 193 priority_(priority), |
| 194 proxy_info_(proxy_info), |
| 203 server_ssl_config_(server_ssl_config), | 195 server_ssl_config_(server_ssl_config), |
| 204 proxy_ssl_config_(proxy_ssl_config), | 196 proxy_ssl_config_(proxy_ssl_config), |
| 205 net_log_( | 197 net_log_( |
| 206 NetLogWithSource::Make(net_log, NetLogSourceType::HTTP_STREAM_JOB)), | 198 NetLogWithSource::Make(net_log, NetLogSourceType::HTTP_STREAM_JOB)), |
| 207 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), | 199 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), |
| 208 connection_(new ClientSocketHandle), | 200 connection_(new ClientSocketHandle), |
| 209 session_(session), | 201 session_(session), |
| 210 state_(STATE_NONE), | 202 state_(STATE_NONE), |
| 211 next_state_(STATE_NONE), | 203 next_state_(STATE_NONE), |
| 212 pac_request_(NULL), | |
| 213 destination_(destination), | 204 destination_(destination), |
| 214 origin_url_(origin_url), | 205 origin_url_(origin_url), |
| 215 alternative_service_(alternative_service), | 206 alternative_service_(alternative_service), |
| 216 alternative_proxy_server_(alternative_proxy_server), | 207 alternative_proxy_server_(alternative_proxy_server), |
| 217 enable_ip_based_pooling_(enable_ip_based_pooling), | 208 enable_ip_based_pooling_(enable_ip_based_pooling), |
| 218 delegate_(delegate), | 209 delegate_(delegate), |
| 219 job_type_(job_type), | 210 job_type_(job_type), |
| 220 using_ssl_(origin_url_.SchemeIs(url::kHttpsScheme) || | 211 using_ssl_(origin_url_.SchemeIs(url::kHttpsScheme) || |
| 221 origin_url_.SchemeIs(url::kWssScheme)), | 212 origin_url_.SchemeIs(url::kWssScheme)), |
| 222 using_spdy_(false), | 213 using_spdy_(false), |
| 223 using_quic_(false), | 214 using_quic_(false), |
| 224 quic_request_(session_->quic_stream_factory(), | 215 reconsider_proxy_(false), |
| 225 session_->http_server_properties()), | 216 quic_request_(session_->quic_stream_factory()->CreateStreamRequest()), |
| 226 using_existing_quic_session_(false), | 217 using_existing_quic_session_(false), |
| 227 establishing_tunnel_(false), | 218 establishing_tunnel_(false), |
| 228 was_alpn_negotiated_(false), | 219 was_alpn_negotiated_(false), |
| 229 negotiated_protocol_(kProtoUnknown), | 220 negotiated_protocol_(kProtoUnknown), |
| 230 num_streams_(0), | 221 num_streams_(0), |
| 231 spdy_session_direct_(false), | 222 spdy_session_direct_(false), |
| 232 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), | 223 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), |
| 233 ptr_factory_(this) { | 224 ptr_factory_(this) { |
| 234 DCHECK(session); | 225 DCHECK(session); |
| 235 // The job can't have alternative service and alternative proxy server set at | 226 // The job can't have alternative service and alternative proxy server set at |
| (...skipping 27 matching lines...) Expand all Loading... |
| 263 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_JOB); | 254 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_JOB); |
| 264 | 255 |
| 265 // When we're in a partially constructed state, waiting for the user to | 256 // When we're in a partially constructed state, waiting for the user to |
| 266 // provide certificate handling information or authentication, we can't reuse | 257 // provide certificate handling information or authentication, we can't reuse |
| 267 // this stream at all. | 258 // this stream at all. |
| 268 if (next_state_ == STATE_WAITING_USER_ACTION) { | 259 if (next_state_ == STATE_WAITING_USER_ACTION) { |
| 269 connection_->socket()->Disconnect(); | 260 connection_->socket()->Disconnect(); |
| 270 connection_.reset(); | 261 connection_.reset(); |
| 271 } | 262 } |
| 272 | 263 |
| 273 if (pac_request_) | |
| 274 session_->proxy_service()->CancelPacRequest(pac_request_); | |
| 275 | |
| 276 // The stream could be in a partial state. It is not reusable. | 264 // The stream could be in a partial state. It is not reusable. |
| 277 if (stream_.get() && next_state_ != STATE_DONE) | 265 if (stream_.get() && next_state_ != STATE_DONE) |
| 278 stream_->Close(true /* not reusable */); | 266 stream_->Close(true /* not reusable */); |
| 279 } | 267 } |
| 280 | 268 |
| 281 void HttpStreamFactoryImpl::Job::Start( | 269 void HttpStreamFactoryImpl::Job::Start( |
| 282 HttpStreamRequest::StreamType stream_type) { | 270 HttpStreamRequest::StreamType stream_type) { |
| 283 stream_type_ = stream_type; | 271 stream_type_ = stream_type; |
| 284 StartInternal(); | 272 StartInternal(); |
| 285 } | 273 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 310 int HttpStreamFactoryImpl::Job::RestartTunnelWithProxyAuth() { | 298 int HttpStreamFactoryImpl::Job::RestartTunnelWithProxyAuth() { |
| 311 DCHECK(establishing_tunnel_); | 299 DCHECK(establishing_tunnel_); |
| 312 next_state_ = STATE_RESTART_TUNNEL_AUTH; | 300 next_state_ = STATE_RESTART_TUNNEL_AUTH; |
| 313 stream_.reset(); | 301 stream_.reset(); |
| 314 RunLoop(OK); | 302 RunLoop(OK); |
| 315 return ERR_IO_PENDING; | 303 return ERR_IO_PENDING; |
| 316 } | 304 } |
| 317 | 305 |
| 318 LoadState HttpStreamFactoryImpl::Job::GetLoadState() const { | 306 LoadState HttpStreamFactoryImpl::Job::GetLoadState() const { |
| 319 switch (next_state_) { | 307 switch (next_state_) { |
| 320 case STATE_RESOLVE_PROXY_COMPLETE: | |
| 321 return session_->proxy_service()->GetLoadState(pac_request_); | |
| 322 case STATE_INIT_CONNECTION_COMPLETE: | 308 case STATE_INIT_CONNECTION_COMPLETE: |
| 323 case STATE_CREATE_STREAM_COMPLETE: | 309 case STATE_CREATE_STREAM_COMPLETE: |
| 324 return using_quic_ ? LOAD_STATE_CONNECTING : connection_->GetLoadState(); | 310 return using_quic_ ? LOAD_STATE_CONNECTING : connection_->GetLoadState(); |
| 325 default: | 311 default: |
| 326 return LOAD_STATE_IDLE; | 312 return LOAD_STATE_IDLE; |
| 327 } | 313 } |
| 328 } | 314 } |
| 329 | 315 |
| 330 void HttpStreamFactoryImpl::Job::Resume() { | 316 void HttpStreamFactoryImpl::Job::Resume() { |
| 331 DCHECK_EQ(job_type_, MAIN); | 317 DCHECK_EQ(job_type_, MAIN); |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 do { | 666 do { |
| 681 State state = next_state_; | 667 State state = next_state_; |
| 682 // Added to investigate crbug.com/711721. | 668 // Added to investigate crbug.com/711721. |
| 683 state_ = state; | 669 state_ = state; |
| 684 next_state_ = STATE_NONE; | 670 next_state_ = STATE_NONE; |
| 685 switch (state) { | 671 switch (state) { |
| 686 case STATE_START: | 672 case STATE_START: |
| 687 DCHECK_EQ(OK, rv); | 673 DCHECK_EQ(OK, rv); |
| 688 rv = DoStart(); | 674 rv = DoStart(); |
| 689 break; | 675 break; |
| 690 case STATE_RESOLVE_PROXY: | |
| 691 DCHECK_EQ(OK, rv); | |
| 692 rv = DoResolveProxy(); | |
| 693 break; | |
| 694 case STATE_RESOLVE_PROXY_COMPLETE: | |
| 695 rv = DoResolveProxyComplete(rv); | |
| 696 break; | |
| 697 case STATE_WAIT: | 676 case STATE_WAIT: |
| 698 DCHECK_EQ(OK, rv); | 677 DCHECK_EQ(OK, rv); |
| 699 rv = DoWait(); | 678 rv = DoWait(); |
| 700 break; | 679 break; |
| 701 case STATE_WAIT_COMPLETE: | 680 case STATE_WAIT_COMPLETE: |
| 702 rv = DoWaitComplete(rv); | 681 rv = DoWaitComplete(rv); |
| 703 break; | 682 break; |
| 704 case STATE_INIT_CONNECTION: | 683 case STATE_INIT_CONNECTION: |
| 705 DCHECK_EQ(OK, rv); | 684 DCHECK_EQ(OK, rv); |
| 706 rv = DoInitConnection(); | 685 rv = DoInitConnection(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 net_log->AddEvent(NetLogEventType::HTTP_STREAM_REQUEST_STARTED_JOB, | 732 net_log->AddEvent(NetLogEventType::HTTP_STREAM_REQUEST_STARTED_JOB, |
| 754 net_log_.source().ToEventParametersCallback()); | 733 net_log_.source().ToEventParametersCallback()); |
| 755 } | 734 } |
| 756 | 735 |
| 757 // Don't connect to restricted ports. | 736 // Don't connect to restricted ports. |
| 758 if (!IsPortAllowedForScheme(destination_.port(), | 737 if (!IsPortAllowedForScheme(destination_.port(), |
| 759 request_info_.url.scheme())) { | 738 request_info_.url.scheme())) { |
| 760 return ERR_UNSAFE_PORT; | 739 return ERR_UNSAFE_PORT; |
| 761 } | 740 } |
| 762 | 741 |
| 763 next_state_ = STATE_RESOLVE_PROXY; | 742 next_state_ = STATE_WAIT; |
| 764 return OK; | 743 return OK; |
| 765 } | 744 } |
| 766 | 745 |
| 767 int HttpStreamFactoryImpl::Job::DoResolveProxy() { | |
| 768 DCHECK(!pac_request_); | |
| 769 DCHECK(session_); | |
| 770 | |
| 771 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; | |
| 772 | |
| 773 if (request_info_.load_flags & LOAD_BYPASS_PROXY) { | |
| 774 proxy_info_.UseDirect(); | |
| 775 return OK; | |
| 776 } | |
| 777 | |
| 778 // If an alternative proxy server was provided, use that. | |
| 779 if (alternative_proxy_server_.is_valid()) { | |
| 780 proxy_info_.UseProxyServer(alternative_proxy_server_); | |
| 781 return OK; | |
| 782 } | |
| 783 | |
| 784 return session_->proxy_service()->ResolveProxy( | |
| 785 origin_url_, request_info_.method, &proxy_info_, io_callback_, | |
| 786 &pac_request_, session_->params().proxy_delegate, net_log_); | |
| 787 } | |
| 788 | |
| 789 int HttpStreamFactoryImpl::Job::DoResolveProxyComplete(int result) { | |
| 790 pac_request_ = NULL; | |
| 791 | |
| 792 net_log_.AddEvent( | |
| 793 NetLogEventType::HTTP_STREAM_JOB_PROXY_SERVER_RESOLVED, | |
| 794 base::Bind( | |
| 795 &NetLogHttpStreamJobProxyServerResolved, | |
| 796 proxy_info_.is_empty() ? ProxyServer() : proxy_info_.proxy_server())); | |
| 797 | |
| 798 if (result == OK) { | |
| 799 // Remove unsupported proxies from the list. | |
| 800 int supported_proxies = | |
| 801 ProxyServer::SCHEME_DIRECT | ProxyServer::SCHEME_HTTP | | |
| 802 ProxyServer::SCHEME_HTTPS | ProxyServer::SCHEME_SOCKS4 | | |
| 803 ProxyServer::SCHEME_SOCKS5; | |
| 804 | |
| 805 if (session_->IsQuicEnabled()) | |
| 806 supported_proxies |= ProxyServer::SCHEME_QUIC; | |
| 807 | |
| 808 proxy_info_.RemoveProxiesWithoutScheme(supported_proxies); | |
| 809 | |
| 810 if (proxy_info_.is_empty()) { | |
| 811 // No proxies/direct to choose from. This happens when we don't support | |
| 812 // any of the proxies in the returned list. | |
| 813 result = ERR_NO_SUPPORTED_PROXIES; | |
| 814 } else if (using_quic_ && | |
| 815 (!proxy_info_.is_quic() && !proxy_info_.is_direct())) { | |
| 816 // QUIC can not be spoken to non-QUIC proxies. This error should not be | |
| 817 // user visible, because the non-alternative Job should be resumed. | |
| 818 result = ERR_NO_SUPPORTED_PROXIES; | |
| 819 } | |
| 820 } | |
| 821 | |
| 822 if (result != OK) { | |
| 823 return result; | |
| 824 } | |
| 825 | |
| 826 next_state_ = STATE_WAIT; | |
| 827 | |
| 828 delegate_->OnResolveProxyComplete(this, request_info_, priority_, | |
| 829 server_ssl_config_, proxy_ssl_config_, | |
| 830 stream_type_); | |
| 831 | |
| 832 return OK; | |
| 833 } | |
| 834 | |
| 835 bool HttpStreamFactoryImpl::Job::ShouldForceQuic() const { | 746 bool HttpStreamFactoryImpl::Job::ShouldForceQuic() const { |
| 836 return session_->IsQuicEnabled() && | 747 return session_->IsQuicEnabled() && |
| 837 (base::ContainsKey(session_->params().origins_to_force_quic_on, | 748 (base::ContainsKey(session_->params().origins_to_force_quic_on, |
| 838 HostPortPair()) || | 749 HostPortPair()) || |
| 839 base::ContainsKey(session_->params().origins_to_force_quic_on, | 750 base::ContainsKey(session_->params().origins_to_force_quic_on, |
| 840 destination_)) && | 751 destination_)) && |
| 841 proxy_info_.is_direct() && origin_url_.SchemeIs(url::kHttpsScheme); | 752 proxy_info_.is_direct() && origin_url_.SchemeIs(url::kHttpsScheme); |
| 842 } | 753 } |
| 843 | 754 |
| 844 int HttpStreamFactoryImpl::Job::DoWait() { | 755 int HttpStreamFactoryImpl::Job::DoWait() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 867 | 778 |
| 868 return result; | 779 return result; |
| 869 } | 780 } |
| 870 | 781 |
| 871 int HttpStreamFactoryImpl::Job::DoInitConnectionImpl() { | 782 int HttpStreamFactoryImpl::Job::DoInitConnectionImpl() { |
| 872 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462812 is fixed. | 783 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462812 is fixed. |
| 873 tracked_objects::ScopedTracker tracking_profile( | 784 tracked_objects::ScopedTracker tracking_profile( |
| 874 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 785 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 875 "462812 HttpStreamFactoryImpl::Job::DoInitConnection")); | 786 "462812 HttpStreamFactoryImpl::Job::DoInitConnection")); |
| 876 DCHECK(!connection_->is_initialized()); | 787 DCHECK(!connection_->is_initialized()); |
| 788 |
| 789 if (proxy_info_.is_empty()) { |
| 790 // No proxies/direct to choose from. This happens when we don't support |
| 791 // any of the proxies in the returned list. |
| 792 return ERR_NO_SUPPORTED_PROXIES; |
| 793 } else if (using_quic_ && |
| 794 (!proxy_info_.is_quic() && !proxy_info_.is_direct())) { |
| 795 // QUIC can not be spoken to non-QUIC proxies. This error should not be |
| 796 // user visible, because the non-alternative Job should be resumed. |
| 797 return ERR_NO_SUPPORTED_PROXIES; |
| 798 } |
| 799 |
| 877 DCHECK(proxy_info_.proxy_server().is_valid()); | 800 DCHECK(proxy_info_.proxy_server().is_valid()); |
| 878 next_state_ = STATE_INIT_CONNECTION_COMPLETE; | 801 next_state_ = STATE_INIT_CONNECTION_COMPLETE; |
| 879 | 802 |
| 880 if (delegate_->OnInitConnection(proxy_info_)) { | 803 if (delegate_->OnInitConnection(proxy_info_)) { |
| 881 // Return since the connection initialization can be skipped. | 804 // Return since the connection initialization can be skipped. |
| 882 return OK; | 805 return OK; |
| 883 } | 806 } |
| 884 | 807 |
| 885 using_spdy_ = false; | 808 using_spdy_ = false; |
| 886 | 809 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 url = url.ReplaceComponents(replacements); | 854 url = url.ReplaceComponents(replacements); |
| 932 } else { | 855 } else { |
| 933 DCHECK(using_ssl_); | 856 DCHECK(using_ssl_); |
| 934 // The certificate of a QUIC alternative server is expected to be valid | 857 // The certificate of a QUIC alternative server is expected to be valid |
| 935 // for the origin of the request (in addition to being valid for the | 858 // for the origin of the request (in addition to being valid for the |
| 936 // server itself). | 859 // server itself). |
| 937 destination = destination_; | 860 destination = destination_; |
| 938 ssl_config = &server_ssl_config_; | 861 ssl_config = &server_ssl_config_; |
| 939 } | 862 } |
| 940 int rv = | 863 int rv = |
| 941 quic_request_.Request(destination, request_info_.privacy_mode, | 864 quic_request_->Request(destination, request_info_.privacy_mode, |
| 942 ssl_config->GetCertVerifyFlags(), url, | 865 ssl_config->GetCertVerifyFlags(), url, |
| 943 request_info_.method, net_log_, io_callback_); | 866 request_info_.method, net_log_, io_callback_); |
| 944 if (rv == OK) { | 867 if (rv == OK) { |
| 945 using_existing_quic_session_ = true; | 868 using_existing_quic_session_ = true; |
| 946 } else { | 869 } else { |
| 947 // There's no available QUIC session. Inform the delegate how long to | 870 // There's no available QUIC session. Inform the delegate how long to |
| 948 // delay the main job. | 871 // delay the main job. |
| 949 if (rv == ERR_IO_PENDING) { | 872 if (rv == ERR_IO_PENDING) { |
| 950 delegate_->MaybeSetWaitTimeForMainJob( | 873 delegate_->MaybeSetWaitTimeForMainJob( |
| 951 quic_request_.GetTimeDelayForWaitingJob()); | 874 quic_request_->GetTimeDelayForWaitingJob()); |
| 952 } | 875 } |
| 953 } | 876 } |
| 954 return rv; | 877 return rv; |
| 955 } | 878 } |
| 956 | 879 |
| 957 SpdySessionKey spdy_session_key = GetSpdySessionKey(); | 880 SpdySessionKey spdy_session_key = GetSpdySessionKey(); |
| 958 | 881 |
| 959 // Check first if we have a spdy session for this group. If so, then go | 882 // Check first if we have a spdy session for this group. If so, then go |
| 960 // straight to using that. | 883 // straight to using that. |
| 961 if (CanUseExistingSpdySession()) { | 884 if (CanUseExistingSpdySession()) { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 if (!ssl_started && result < 0 && | 1044 if (!ssl_started && result < 0 && |
| 1122 (IsSpdyAlternative() || IsQuicAlternative())) | 1045 (IsSpdyAlternative() || IsQuicAlternative())) |
| 1123 return result; | 1046 return result; |
| 1124 | 1047 |
| 1125 if (using_quic_) { | 1048 if (using_quic_) { |
| 1126 if (result < 0) | 1049 if (result < 0) |
| 1127 return result; | 1050 return result; |
| 1128 | 1051 |
| 1129 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { | 1052 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { |
| 1130 bidirectional_stream_impl_ = | 1053 bidirectional_stream_impl_ = |
| 1131 quic_request_.CreateBidirectionalStreamImpl(); | 1054 quic_request_->CreateBidirectionalStreamImpl(); |
| 1132 if (!bidirectional_stream_impl_) { | 1055 if (!bidirectional_stream_impl_) { |
| 1133 // Quic session is closed before stream can be created. | 1056 // Quic session is closed before stream can be created. |
| 1134 return ERR_CONNECTION_CLOSED; | 1057 return ERR_CONNECTION_CLOSED; |
| 1135 } | 1058 } |
| 1136 } else { | 1059 } else { |
| 1137 stream_ = quic_request_.CreateStream(); | 1060 stream_ = quic_request_->CreateStream(); |
| 1138 if (!stream_) { | 1061 if (!stream_) { |
| 1139 // Quic session is closed before stream can be created. | 1062 // Quic session is closed before stream can be created. |
| 1140 return ERR_CONNECTION_CLOSED; | 1063 return ERR_CONNECTION_CLOSED; |
| 1141 } | 1064 } |
| 1142 } | 1065 } |
| 1143 next_state_ = STATE_NONE; | 1066 next_state_ = STATE_NONE; |
| 1144 return OK; | 1067 return OK; |
| 1145 } | 1068 } |
| 1146 | 1069 |
| 1147 if (result < 0 && !ssl_started) | 1070 if (result < 0 && !ssl_started) |
| 1148 return ReconsiderProxyAfterError(result); | 1071 return ReconsiderProxyAfterError(result); |
| 1072 |
| 1149 establishing_tunnel_ = false; | 1073 establishing_tunnel_ = false; |
| 1150 | 1074 |
| 1151 // Handle SSL errors below. | 1075 // Handle SSL errors below. |
| 1152 if (using_ssl_) { | 1076 if (using_ssl_) { |
| 1153 DCHECK(ssl_started); | 1077 DCHECK(ssl_started); |
| 1154 if (IsCertificateError(result)) { | 1078 if (IsCertificateError(result)) { |
| 1155 result = HandleCertificateError(result); | 1079 result = HandleCertificateError(result); |
| 1156 if (result == OK && !connection_->socket()->IsConnectedAndIdle()) { | 1080 if (result == OK && !connection_->socket()->IsConnectedAndIdle()) { |
| 1157 ReturnToStateInitConnection(true /* close connection */); | 1081 ReturnToStateInitConnection(true /* close connection */); |
| 1158 return result; | 1082 return result; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1405 } | 1329 } |
| 1406 | 1330 |
| 1407 if (request_info_.load_flags & LOAD_VERIFY_EV_CERT) | 1331 if (request_info_.load_flags & LOAD_VERIFY_EV_CERT) |
| 1408 ssl_config->verify_ev_cert = true; | 1332 ssl_config->verify_ev_cert = true; |
| 1409 | 1333 |
| 1410 // Disable Channel ID if privacy mode is enabled. | 1334 // Disable Channel ID if privacy mode is enabled. |
| 1411 if (request_info_.privacy_mode == PRIVACY_MODE_ENABLED) | 1335 if (request_info_.privacy_mode == PRIVACY_MODE_ENABLED) |
| 1412 ssl_config->channel_id_enabled = false; | 1336 ssl_config->channel_id_enabled = false; |
| 1413 } | 1337 } |
| 1414 | 1338 |
| 1415 | |
| 1416 int HttpStreamFactoryImpl::Job::ReconsiderProxyAfterError(int error) { | 1339 int HttpStreamFactoryImpl::Job::ReconsiderProxyAfterError(int error) { |
| 1417 DCHECK(!pac_request_); | |
| 1418 DCHECK(session_); | |
| 1419 | |
| 1420 // A failure to resolve the hostname or any error related to establishing a | |
| 1421 // TCP connection could be grounds for trying a new proxy configuration. | |
| 1422 // | |
| 1423 // Why do this when a hostname cannot be resolved? Some URLs only make sense | |
| 1424 // to proxy servers. The hostname in those URLs might fail to resolve if we | |
| 1425 // are still using a non-proxy config. We need to check if a proxy config | |
| 1426 // now exists that corresponds to a proxy server that could load the URL. | |
| 1427 // | |
| 1428 switch (error) { | 1340 switch (error) { |
| 1429 case ERR_PROXY_CONNECTION_FAILED: | 1341 case ERR_PROXY_CONNECTION_FAILED: |
| 1430 case ERR_NAME_NOT_RESOLVED: | 1342 case ERR_NAME_NOT_RESOLVED: |
| 1431 case ERR_INTERNET_DISCONNECTED: | 1343 case ERR_INTERNET_DISCONNECTED: |
| 1432 case ERR_ADDRESS_UNREACHABLE: | 1344 case ERR_ADDRESS_UNREACHABLE: |
| 1433 case ERR_CONNECTION_CLOSED: | 1345 case ERR_CONNECTION_CLOSED: |
| 1434 case ERR_CONNECTION_TIMED_OUT: | 1346 case ERR_CONNECTION_TIMED_OUT: |
| 1435 case ERR_CONNECTION_RESET: | 1347 case ERR_CONNECTION_RESET: |
| 1436 case ERR_CONNECTION_REFUSED: | 1348 case ERR_CONNECTION_REFUSED: |
| 1437 case ERR_CONNECTION_ABORTED: | 1349 case ERR_CONNECTION_ABORTED: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1456 // | 1368 // |
| 1457 // Note that if the host resolving was done by the SOCKS5 proxy, we can't | 1369 // Note that if the host resolving was done by the SOCKS5 proxy, we can't |
| 1458 // differentiate between a proxy-side "host not found" versus a proxy-side | 1370 // differentiate between a proxy-side "host not found" versus a proxy-side |
| 1459 // "address unreachable" error, and will report both of these failures as | 1371 // "address unreachable" error, and will report both of these failures as |
| 1460 // ERR_ADDRESS_UNREACHABLE. | 1372 // ERR_ADDRESS_UNREACHABLE. |
| 1461 return ERR_ADDRESS_UNREACHABLE; | 1373 return ERR_ADDRESS_UNREACHABLE; |
| 1462 default: | 1374 default: |
| 1463 return error; | 1375 return error; |
| 1464 } | 1376 } |
| 1465 | 1377 |
| 1466 // Do not bypass non-QUIC proxy on ERR_MSG_TOO_BIG. | |
| 1467 if (!proxy_info_.is_quic() && error == ERR_MSG_TOO_BIG) | |
| 1468 return error; | |
| 1469 | |
| 1470 if (request_info_.load_flags & LOAD_BYPASS_PROXY) | |
| 1471 return error; | |
| 1472 | |
| 1473 // Alternative proxy server job should not use fallback proxies, and instead | 1378 // Alternative proxy server job should not use fallback proxies, and instead |
| 1474 // return. This would resume the main job (if possible) which may try the | 1379 // return. This would resume the main job (if possible) which may try the |
| 1475 // fallback proxies. | 1380 // fallback proxies. |
| 1476 if (alternative_proxy_server_.is_valid()) { | 1381 if (job_type() == ALTERNATIVE && alternative_proxy_server().is_valid()) { |
| 1477 DCHECK_EQ(STATE_NONE, next_state_); | 1382 DCHECK_EQ(STATE_NONE, next_state_); |
| 1478 return error; | 1383 return error; |
| 1479 } | 1384 } |
| 1480 | 1385 |
| 1481 if (proxy_info_.is_https() && proxy_ssl_config_.send_client_cert) { | 1386 reconsider_proxy_ = true; |
| 1482 session_->ssl_client_auth_cache()->Remove( | 1387 return error; |
| 1483 proxy_info_.proxy_server().host_port_pair()); | |
| 1484 } | |
| 1485 | |
| 1486 int rv = session_->proxy_service()->ReconsiderProxyAfterError( | |
| 1487 request_info_.url, request_info_.method, error, &proxy_info_, | |
| 1488 io_callback_, &pac_request_, session_->params().proxy_delegate, net_log_); | |
| 1489 if (rv == OK || rv == ERR_IO_PENDING) { | |
| 1490 // If the error was during connection setup, there is no socket to | |
| 1491 // disconnect. | |
| 1492 if (connection_->socket()) | |
| 1493 connection_->socket()->Disconnect(); | |
| 1494 connection_->Reset(); | |
| 1495 delegate_->RemoveRequestFromSpdySessionRequestMapForJob(this); | |
| 1496 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; | |
| 1497 } else { | |
| 1498 // If ReconsiderProxyAfterError() failed synchronously, it means | |
| 1499 // there was nothing left to fall-back to, so fail the transaction | |
| 1500 // with the last connection error we got. | |
| 1501 // TODO(eroman): This is a confusing contract, make it more obvious. | |
| 1502 rv = error; | |
| 1503 } | |
| 1504 | |
| 1505 return rv; | |
| 1506 } | 1388 } |
| 1507 | 1389 |
| 1508 int HttpStreamFactoryImpl::Job::HandleCertificateError(int error) { | 1390 int HttpStreamFactoryImpl::Job::HandleCertificateError(int error) { |
| 1509 DCHECK(using_ssl_); | 1391 DCHECK(using_ssl_); |
| 1510 DCHECK(IsCertificateError(error)); | 1392 DCHECK(IsCertificateError(error)); |
| 1511 | 1393 |
| 1512 SSLClientSocket* ssl_socket = | 1394 SSLClientSocket* ssl_socket = |
| 1513 static_cast<SSLClientSocket*>(connection_->socket()); | 1395 static_cast<SSLClientSocket*>(connection_->socket()); |
| 1514 ssl_socket->GetSSLInfo(&ssl_info_); | 1396 ssl_socket->GetSSLInfo(&ssl_info_); |
| 1515 | 1397 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1557 return; | 1439 return; |
| 1558 | 1440 |
| 1559 ConnectionAttempts socket_attempts = connection_->connection_attempts(); | 1441 ConnectionAttempts socket_attempts = connection_->connection_attempts(); |
| 1560 if (connection_->socket()) { | 1442 if (connection_->socket()) { |
| 1561 connection_->socket()->GetConnectionAttempts(&socket_attempts); | 1443 connection_->socket()->GetConnectionAttempts(&socket_attempts); |
| 1562 } | 1444 } |
| 1563 | 1445 |
| 1564 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts); | 1446 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts); |
| 1565 } | 1447 } |
| 1566 | 1448 |
| 1449 HttpStreamFactoryImpl::JobFactory::JobFactory() {} |
| 1450 |
| 1451 HttpStreamFactoryImpl::JobFactory::~JobFactory() {} |
| 1452 |
| 1453 HttpStreamFactoryImpl::Job* HttpStreamFactoryImpl::JobFactory::CreateJob( |
| 1454 HttpStreamFactoryImpl::Job::Delegate* delegate, |
| 1455 HttpStreamFactoryImpl::JobType job_type, |
| 1456 HttpNetworkSession* session, |
| 1457 const HttpRequestInfo& request_info, |
| 1458 RequestPriority priority, |
| 1459 ProxyInfo proxy_info, |
| 1460 const SSLConfig& server_ssl_config, |
| 1461 const SSLConfig& proxy_ssl_config, |
| 1462 HostPortPair destination, |
| 1463 GURL origin_url, |
| 1464 bool enable_ip_based_pooling, |
| 1465 NetLog* net_log) { |
| 1466 return new HttpStreamFactoryImpl::Job( |
| 1467 delegate, job_type, session, request_info, priority, proxy_info, |
| 1468 server_ssl_config, proxy_ssl_config, destination, origin_url, |
| 1469 enable_ip_based_pooling, net_log); |
| 1470 } |
| 1471 |
| 1472 HttpStreamFactoryImpl::Job* HttpStreamFactoryImpl::JobFactory::CreateJob( |
| 1473 HttpStreamFactoryImpl::Job::Delegate* delegate, |
| 1474 HttpStreamFactoryImpl::JobType job_type, |
| 1475 HttpNetworkSession* session, |
| 1476 const HttpRequestInfo& request_info, |
| 1477 RequestPriority priority, |
| 1478 ProxyInfo proxy_info, |
| 1479 const SSLConfig& server_ssl_config, |
| 1480 const SSLConfig& proxy_ssl_config, |
| 1481 HostPortPair destination, |
| 1482 GURL origin_url, |
| 1483 AlternativeService alternative_service, |
| 1484 bool enable_ip_based_pooling, |
| 1485 NetLog* net_log) { |
| 1486 return new HttpStreamFactoryImpl::Job( |
| 1487 delegate, job_type, session, request_info, priority, proxy_info, |
| 1488 server_ssl_config, proxy_ssl_config, destination, origin_url, |
| 1489 alternative_service, ProxyServer(), enable_ip_based_pooling, net_log); |
| 1490 } |
| 1491 |
| 1492 HttpStreamFactoryImpl::Job* HttpStreamFactoryImpl::JobFactory::CreateJob( |
| 1493 HttpStreamFactoryImpl::Job::Delegate* delegate, |
| 1494 HttpStreamFactoryImpl::JobType job_type, |
| 1495 HttpNetworkSession* session, |
| 1496 const HttpRequestInfo& request_info, |
| 1497 RequestPriority priority, |
| 1498 ProxyInfo proxy_info, |
| 1499 const SSLConfig& server_ssl_config, |
| 1500 const SSLConfig& proxy_ssl_config, |
| 1501 HostPortPair destination, |
| 1502 GURL origin_url, |
| 1503 const ProxyServer& alternative_proxy_server, |
| 1504 bool enable_ip_based_pooling, |
| 1505 NetLog* net_log) { |
| 1506 return new HttpStreamFactoryImpl::Job( |
| 1507 delegate, job_type, session, request_info, priority, proxy_info, |
| 1508 server_ssl_config, proxy_ssl_config, destination, origin_url, |
| 1509 AlternativeService(), alternative_proxy_server, enable_ip_based_pooling, |
| 1510 net_log); |
| 1511 } |
| 1512 |
| 1567 } // namespace net | 1513 } // namespace net |
| OLD | NEW |