Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: net/http/http_stream_factory_impl_job.cc

Issue 2359153003: Minor cleanups in HttpStreamFactoryImpl and member classes. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <utility>
10 9
11 #include "base/bind.h" 10 #include "base/bind.h"
12 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
13 #include "base/location.h" 12 #include "base/location.h"
14 #include "base/logging.h" 13 #include "base/logging.h"
15 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
16 #include "base/metrics/sparse_histogram.h" 15 #include "base/metrics/sparse_histogram.h"
17 #include "base/profiler/scoped_tracker.h" 16 #include "base/profiler/scoped_tracker.h"
18 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
19 #include "base/stl_util.h" 18 #include "base/stl_util.h"
(...skipping 27 matching lines...) Expand all
47 #include "net/socket/ssl_client_socket.h" 46 #include "net/socket/ssl_client_socket.h"
48 #include "net/socket/ssl_client_socket_pool.h" 47 #include "net/socket/ssl_client_socket_pool.h"
49 #include "net/spdy/bidirectional_stream_spdy_impl.h" 48 #include "net/spdy/bidirectional_stream_spdy_impl.h"
50 #include "net/spdy/spdy_http_stream.h" 49 #include "net/spdy/spdy_http_stream.h"
51 #include "net/spdy/spdy_protocol.h" 50 #include "net/spdy/spdy_protocol.h"
52 #include "net/spdy/spdy_session.h" 51 #include "net/spdy/spdy_session.h"
53 #include "net/spdy/spdy_session_pool.h" 52 #include "net/spdy/spdy_session_pool.h"
54 #include "net/ssl/channel_id_service.h" 53 #include "net/ssl/channel_id_service.h"
55 #include "net/ssl/ssl_cert_request_info.h" 54 #include "net/ssl/ssl_cert_request_info.h"
56 #include "net/ssl/ssl_connection_status_flags.h" 55 #include "net/ssl/ssl_connection_status_flags.h"
56 #include "url/url_constants.h"
57 57
58 namespace net { 58 namespace net {
59 59
60 namespace { 60 namespace {
61 61
62 void DoNothingAsyncCallback(int result){}; 62 void DoNothingAsyncCallback(int result) {}
63 void RecordChannelIDKeyMatch(SSLClientSocket* ssl_socket, 63 void RecordChannelIDKeyMatch(SSLClientSocket* ssl_socket,
64 ChannelIDService* channel_id_service, 64 ChannelIDService* channel_id_service,
65 std::string host) { 65 std::string host) {
66 SSLInfo ssl_info; 66 SSLInfo ssl_info;
67 ssl_socket->GetSSLInfo(&ssl_info); 67 ssl_socket->GetSSLInfo(&ssl_info);
68 if (!ssl_info.channel_id_sent) 68 if (!ssl_info.channel_id_sent)
69 return; 69 return;
70 std::unique_ptr<crypto::ECPrivateKey> request_key; 70 std::unique_ptr<crypto::ECPrivateKey> request_key;
71 ChannelIDService::Request request; 71 ChannelIDService::Request request;
72 int result = channel_id_service->GetOrCreateChannelID( 72 int result = channel_id_service->GetOrCreateChannelID(
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 // alternative proxy server is valid, then the job type must be set to 222 // alternative proxy server is valid, then the job type must be set to
223 // either ALTERNATIVE or PRECONNECT. 223 // either ALTERNATIVE or PRECONNECT.
224 DCHECK((alternative_service_.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL && 224 DCHECK((alternative_service_.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL &&
225 !alternative_proxy_server_.is_valid()) || 225 !alternative_proxy_server_.is_valid()) ||
226 (job_type_ == ALTERNATIVE || job_type_ == PRECONNECT)); 226 (job_type_ == ALTERNATIVE || job_type_ == PRECONNECT));
227 // If the alternative proxy server is valid, then the job type must be 227 // If the alternative proxy server is valid, then the job type must be
228 // set to ALTERNATIVE. 228 // set to ALTERNATIVE.
229 DCHECK(!alternative_proxy_server_.is_valid() || job_type_ == ALTERNATIVE); 229 DCHECK(!alternative_proxy_server_.is_valid() || job_type_ == ALTERNATIVE);
230 230
231 if (IsSpdyAlternative()) { 231 if (IsSpdyAlternative()) {
232 DCHECK(origin_url_.SchemeIs("https")); 232 DCHECK(origin_url_.SchemeIs(url::kHttpsScheme));
233 } 233 }
234 if (IsQuicAlternative()) { 234 if (IsQuicAlternative()) {
235 DCHECK(session_->params().enable_quic); 235 DCHECK(session_->params().enable_quic);
236 using_quic_ = true; 236 using_quic_ = true;
237 } 237 }
238 } 238 }
239 239
240 HttpStreamFactoryImpl::Job::~Job() { 240 HttpStreamFactoryImpl::Job::~Job() {
241 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_JOB); 241 net_log_.EndEvent(NetLogEventType::HTTP_STREAM_JOB);
242 242
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 } 369 }
370 370
371 bool HttpStreamFactoryImpl::Job::CanUseExistingSpdySession() const { 371 bool HttpStreamFactoryImpl::Job::CanUseExistingSpdySession() const {
372 // We need to make sure that if a spdy session was created for 372 // We need to make sure that if a spdy session was created for
373 // https://somehost/ that we don't use that session for http://somehost:443/. 373 // https://somehost/ that we don't use that session for http://somehost:443/.
374 // The only time we can use an existing session is if the request URL is 374 // The only time we can use an existing session is if the request URL is
375 // https (the normal case) or if we're connection to a SPDY proxy. 375 // https (the normal case) or if we're connection to a SPDY proxy.
376 // https://crbug.com/133176 376 // https://crbug.com/133176
377 // TODO(ricea): Add "wss" back to this list when SPDY WebSocket support is 377 // TODO(ricea): Add "wss" back to this list when SPDY WebSocket support is
378 // working. 378 // working.
379 return origin_url_.SchemeIs("https") || 379 return origin_url_.SchemeIs(url::kHttpsScheme) ||
380 proxy_info_.proxy_server().is_https() || IsSpdyAlternative(); 380 proxy_info_.proxy_server().is_https();
Bence 2016/09/22 19:30:32 See DCHECK in line 232.
381 } 381 }
382 382
383 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { 383 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() {
384 DCHECK(stream_.get()); 384 DCHECK(stream_.get());
385 DCHECK_NE(job_type_, PRECONNECT); 385 DCHECK_NE(job_type_, PRECONNECT);
386 DCHECK(!delegate_->for_websockets()); 386 DCHECK(!delegate_->for_websockets());
387 387
388 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 388 MaybeCopyConnectionAttemptsFromSocketOrHandle();
389 389
390 delegate_->OnStreamReady(this, server_ssl_config_, proxy_info_); 390 delegate_->OnStreamReady(this, server_ssl_config_, proxy_info_);
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 767
768 return OK; 768 return OK;
769 } 769 }
770 770
771 bool HttpStreamFactoryImpl::Job::ShouldForceQuic() const { 771 bool HttpStreamFactoryImpl::Job::ShouldForceQuic() const {
772 return session_->params().enable_quic && 772 return session_->params().enable_quic &&
773 (base::ContainsKey(session_->params().origins_to_force_quic_on, 773 (base::ContainsKey(session_->params().origins_to_force_quic_on,
774 HostPortPair()) || 774 HostPortPair()) ||
775 base::ContainsKey(session_->params().origins_to_force_quic_on, 775 base::ContainsKey(session_->params().origins_to_force_quic_on,
776 destination_)) && 776 destination_)) &&
777 proxy_info_.is_direct() && origin_url_.SchemeIs("https"); 777 proxy_info_.is_direct() && origin_url_.SchemeIs(url::kHttpsScheme);
778 } 778 }
779 779
780 int HttpStreamFactoryImpl::Job::DoWait() { 780 int HttpStreamFactoryImpl::Job::DoWait() {
781 next_state_ = STATE_WAIT_COMPLETE; 781 next_state_ = STATE_WAIT_COMPLETE;
782 if (delegate_->ShouldWait(this)) 782 if (delegate_->ShouldWait(this))
783 return ERR_IO_PENDING; 783 return ERR_IO_PENDING;
784 784
785 return OK; 785 return OK;
786 } 786 }
787 787
(...skipping 13 matching lines...) Expand all
801 801
802 int HttpStreamFactoryImpl::Job::DoInitConnectionImpl() { 802 int HttpStreamFactoryImpl::Job::DoInitConnectionImpl() {
803 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462812 is fixed. 803 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462812 is fixed.
804 tracked_objects::ScopedTracker tracking_profile( 804 tracked_objects::ScopedTracker tracking_profile(
805 FROM_HERE_WITH_EXPLICIT_FUNCTION( 805 FROM_HERE_WITH_EXPLICIT_FUNCTION(
806 "462812 HttpStreamFactoryImpl::Job::DoInitConnection")); 806 "462812 HttpStreamFactoryImpl::Job::DoInitConnection"));
807 DCHECK(!connection_->is_initialized()); 807 DCHECK(!connection_->is_initialized());
808 DCHECK(proxy_info_.proxy_server().is_valid()); 808 DCHECK(proxy_info_.proxy_server().is_valid());
809 next_state_ = STATE_INIT_CONNECTION_COMPLETE; 809 next_state_ = STATE_INIT_CONNECTION_COMPLETE;
810 810
811 using_ssl_ = origin_url_.SchemeIs("https") || origin_url_.SchemeIs("wss") || 811 using_ssl_ = origin_url_.SchemeIs(url::kHttpsScheme) ||
812 IsSpdyAlternative(); 812 origin_url_.SchemeIs(url::kWssScheme);
813 using_spdy_ = false; 813 using_spdy_ = false;
814 814
815 if (ShouldForceQuic()) 815 if (ShouldForceQuic())
816 using_quic_ = true; 816 using_quic_ = true;
817 817
818 DCHECK(!using_quic_ || session_->params().enable_quic); 818 DCHECK(!using_quic_ || session_->params().enable_quic);
819 819
820 if (proxy_info_.is_quic()) { 820 if (proxy_info_.is_quic()) {
821 using_quic_ = true; 821 using_quic_ = true;
822 DCHECK(session_->params().enable_quic); 822 DCHECK(session_->params().enable_quic);
823 } 823 }
824 824
825 if (proxy_info_.is_https() || proxy_info_.is_quic()) { 825 if (proxy_info_.is_https() || proxy_info_.is_quic()) {
826 InitSSLConfig(&proxy_ssl_config_, /*is_proxy=*/true); 826 InitSSLConfig(&proxy_ssl_config_, /*is_proxy=*/true);
827 // Disable revocation checking for HTTPS proxies since the revocation 827 // Disable revocation checking for HTTPS proxies since the revocation
828 // requests are probably going to need to go through the proxy too. 828 // requests are probably going to need to go through the proxy too.
829 proxy_ssl_config_.rev_checking_enabled = false; 829 proxy_ssl_config_.rev_checking_enabled = false;
830 } 830 }
831 if (using_ssl_) { 831 if (using_ssl_) {
832 InitSSLConfig(&server_ssl_config_, /*is_proxy=*/false); 832 InitSSLConfig(&server_ssl_config_, /*is_proxy=*/false);
833 } 833 }
834 834
835 if (using_quic_) { 835 if (using_quic_) {
836 if (proxy_info_.is_quic() && !request_info_.url.SchemeIs("http")) { 836 if (proxy_info_.is_quic() &&
837 !request_info_.url.SchemeIs(url::kHttpScheme)) {
837 NOTREACHED(); 838 NOTREACHED();
838 // TODO(rch): support QUIC proxies for HTTPS urls. 839 // TODO(rch): support QUIC proxies for HTTPS urls.
839 return ERR_NOT_IMPLEMENTED; 840 return ERR_NOT_IMPLEMENTED;
840 } 841 }
841 HostPortPair destination; 842 HostPortPair destination;
842 SSLConfig* ssl_config; 843 SSLConfig* ssl_config;
843 GURL url(request_info_.url); 844 GURL url(request_info_.url);
844 if (proxy_info_.is_quic()) { 845 if (proxy_info_.is_quic()) {
845 // A proxy's certificate is expected to be valid for the proxy hostname. 846 // A proxy's certificate is expected to be valid for the proxy hostname.
846 destination = proxy_info_.proxy_server().host_port_pair(); 847 destination = proxy_info_.proxy_server().host_port_pair();
847 ssl_config = &proxy_ssl_config_; 848 ssl_config = &proxy_ssl_config_;
848 GURL::Replacements replacements; 849 GURL::Replacements replacements;
849 replacements.SetSchemeStr("https"); 850 replacements.SetSchemeStr(url::kHttpsScheme);
850 replacements.SetHostStr(destination.host()); 851 replacements.SetHostStr(destination.host());
851 const std::string new_port = base::UintToString(destination.port()); 852 const std::string new_port = base::UintToString(destination.port());
852 replacements.SetPortStr(new_port); 853 replacements.SetPortStr(new_port);
853 replacements.ClearUsername(); 854 replacements.ClearUsername();
854 replacements.ClearPassword(); 855 replacements.ClearPassword();
855 replacements.ClearPath(); 856 replacements.ClearPath();
856 replacements.ClearQuery(); 857 replacements.ClearQuery();
857 replacements.ClearRef(); 858 replacements.ClearRef();
858 url = url.ReplaceComponents(replacements); 859 url = url.ReplaceComponents(replacements);
859 860
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 if (existing_spdy_session_) { 978 if (existing_spdy_session_) {
978 using_spdy_ = true; 979 using_spdy_ = true;
979 next_state_ = STATE_CREATE_STREAM; 980 next_state_ = STATE_CREATE_STREAM;
980 } else { 981 } else {
981 // It is possible that the spdy session no longer exists. 982 // It is possible that the spdy session no longer exists.
982 ReturnToStateInitConnection(true /* close connection */); 983 ReturnToStateInitConnection(true /* close connection */);
983 } 984 }
984 return OK; 985 return OK;
985 } 986 }
986 987
987 if (proxy_info_.is_quic() && using_quic_) { 988 if (proxy_info_.is_quic()) {
989 DCHECK(using_quic_);
Bence 2016/09/22 19:30:32 See assignment in line 821.
988 // Mark QUIC proxy as bad if QUIC got disabled. 990 // Mark QUIC proxy as bad if QUIC got disabled.
989 // Underlying QUIC layer would have closed the connection. 991 // Underlying QUIC layer would have closed the connection.
990 HostPortPair destination = proxy_info_.proxy_server().host_port_pair();
991 if (session_->quic_stream_factory()->IsQuicDisabled()) { 992 if (session_->quic_stream_factory()->IsQuicDisabled()) {
992 using_quic_ = false; 993 using_quic_ = false;
993 return ReconsiderProxyAfterError(ERR_QUIC_PROTOCOL_ERROR); 994 return ReconsiderProxyAfterError(ERR_QUIC_PROTOCOL_ERROR);
994 } 995 }
995 } 996 }
996 997
997 // |result| may be the result of any of the stacked pools. The following 998 // |result| may be the result of any of the stacked pools. The following
998 // logic is used when determining how to interpret an error. 999 // logic is used when determining how to interpret an error.
999 // If |result| < 0: 1000 // If |result| < 0:
1000 // and connection_->socket() != NULL, then the SSL handshake ran and it 1001 // and connection_->socket() != NULL, then the SSL handshake ran and it
(...skipping 11 matching lines...) Expand all
1012 } else { 1013 } else {
1013 SSLClientSocket* ssl_socket = 1014 SSLClientSocket* ssl_socket =
1014 static_cast<SSLClientSocket*>(connection_->socket()); 1015 static_cast<SSLClientSocket*>(connection_->socket());
1015 if (ssl_socket->WasNpnNegotiated()) { 1016 if (ssl_socket->WasNpnNegotiated()) {
1016 was_alpn_negotiated_ = true; 1017 was_alpn_negotiated_ = true;
1017 negotiated_protocol_ = ssl_socket->GetNegotiatedProtocol(); 1018 negotiated_protocol_ = ssl_socket->GetNegotiatedProtocol();
1018 net_log_.AddEvent( 1019 net_log_.AddEvent(
1019 NetLogEventType::HTTP_STREAM_REQUEST_PROTO, 1020 NetLogEventType::HTTP_STREAM_REQUEST_PROTO,
1020 base::Bind(&NetLogHttpStreamProtoCallback, negotiated_protocol_)); 1021 base::Bind(&NetLogHttpStreamProtoCallback, negotiated_protocol_));
1021 if (negotiated_protocol_ == kProtoHTTP2) 1022 if (negotiated_protocol_ == kProtoHTTP2)
1022 SwitchToSpdyMode(); 1023 using_spdy_ = true;
1023 } 1024 }
1024 } 1025 }
1025 } else if (proxy_info_.is_https() && connection_->socket() && 1026 } else if (proxy_info_.is_https() && connection_->socket() &&
1026 result == OK) { 1027 result == OK) {
1027 ProxyClientSocket* proxy_socket = 1028 ProxyClientSocket* proxy_socket =
1028 static_cast<ProxyClientSocket*>(connection_->socket()); 1029 static_cast<ProxyClientSocket*>(connection_->socket());
1029 // http://crbug.com/642354 1030 // http://crbug.com/642354
1030 if (!proxy_socket->IsConnected()) 1031 if (!proxy_socket->IsConnected())
1031 return ERR_CONNECTION_CLOSED; 1032 return ERR_CONNECTION_CLOSED;
1032 if (proxy_socket->IsUsingSpdy()) { 1033 if (proxy_socket->IsUsingSpdy()) {
1033 was_alpn_negotiated_ = true; 1034 was_alpn_negotiated_ = true;
1034 negotiated_protocol_ = proxy_socket->GetProxyNegotiatedProtocol(); 1035 negotiated_protocol_ = proxy_socket->GetProxyNegotiatedProtocol();
1035 SwitchToSpdyMode(); 1036 using_spdy_ = true;
1036 } 1037 }
1037 } 1038 }
1038 1039
1039 if (result == ERR_PROXY_AUTH_REQUESTED || 1040 if (result == ERR_PROXY_AUTH_REQUESTED ||
1040 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) { 1041 result == ERR_HTTPS_PROXY_TUNNEL_RESPONSE) {
1041 DCHECK(!ssl_started); 1042 DCHECK(!ssl_started);
1042 // Other state (i.e. |using_ssl_|) suggests that |connection_| will have an 1043 // Other state (i.e. |using_ssl_|) suggests that |connection_| will have an
1043 // SSL socket, but there was an error before that could happen. This 1044 // SSL socket, but there was an error before that could happen. This
1044 // puts the in progress HttpProxy socket into |connection_| in order to 1045 // puts the in progress HttpProxy socket into |connection_| in order to
1045 // complete the auth (or read the response body). The tunnel restart code 1046 // complete the auth (or read the response body). The tunnel restart code
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 } 1085 }
1085 1086
1086 if (result < 0 && !ssl_started) 1087 if (result < 0 && !ssl_started)
1087 return ReconsiderProxyAfterError(result); 1088 return ReconsiderProxyAfterError(result);
1088 establishing_tunnel_ = false; 1089 establishing_tunnel_ = false;
1089 1090
1090 // Handle SSL errors below. 1091 // Handle SSL errors below.
1091 if (using_ssl_) { 1092 if (using_ssl_) {
1092 DCHECK(ssl_started); 1093 DCHECK(ssl_started);
1093 if (IsCertificateError(result)) { 1094 if (IsCertificateError(result)) {
1094 if (IsSpdyAlternative() && origin_url_.SchemeIs("http")) { 1095 result = HandleCertificateError(result);
Bence 2016/09/22 19:30:32 See DCHECK in line 232.
1095 // We ignore certificate errors for http over spdy. 1096 if (result == OK && !connection_->socket()->IsConnectedAndIdle()) {
1096 spdy_certificate_error_ = result; 1097 ReturnToStateInitConnection(true /* close connection */);
1097 result = OK; 1098 return result;
1098 } else {
1099 result = HandleCertificateError(result);
1100 if (result == OK && !connection_->socket()->IsConnectedAndIdle()) {
1101 ReturnToStateInitConnection(true /* close connection */);
1102 return result;
1103 }
1104 } 1099 }
1105 } 1100 }
1106 if (result < 0) 1101 if (result < 0)
1107 return result; 1102 return result;
1108 } 1103 }
1109 1104
1110 next_state_ = STATE_CREATE_STREAM; 1105 next_state_ = STATE_CREATE_STREAM;
1111 return OK; 1106 return OK;
1112 } 1107 }
1113 1108
(...skipping 15 matching lines...) Expand all
1129 return ERR_NOT_IMPLEMENTED; 1124 return ERR_NOT_IMPLEMENTED;
1130 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { 1125 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) {
1131 bidirectional_stream_impl_.reset(new BidirectionalStreamSpdyImpl(session)); 1126 bidirectional_stream_impl_.reset(new BidirectionalStreamSpdyImpl(session));
1132 return OK; 1127 return OK;
1133 } 1128 }
1134 1129
1135 // TODO(willchan): Delete this code, because eventually, the 1130 // TODO(willchan): Delete this code, because eventually, the
1136 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it 1131 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it
1137 // will know when SpdySessions become available. 1132 // will know when SpdySessions become available.
1138 1133
1139 bool use_relative_url = direct || request_info_.url.SchemeIs("https"); 1134 bool use_relative_url =
1135 direct || request_info_.url.SchemeIs(url::kHttpsScheme);
1140 stream_.reset(new SpdyHttpStream(session, use_relative_url)); 1136 stream_.reset(new SpdyHttpStream(session, use_relative_url));
1141 return OK; 1137 return OK;
1142 } 1138 }
1143 1139
1144 int HttpStreamFactoryImpl::Job::DoCreateStream() { 1140 int HttpStreamFactoryImpl::Job::DoCreateStream() {
1145 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462811 is fixed. 1141 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462811 is fixed.
1146 tracked_objects::ScopedTracker tracking_profile( 1142 tracked_objects::ScopedTracker tracking_profile(
1147 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1143 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1148 "462811 HttpStreamFactoryImpl::Job::DoCreateStream")); 1144 "462811 HttpStreamFactoryImpl::Job::DoCreateStream"));
1149 DCHECK(connection_->socket() || existing_spdy_session_.get() || using_quic_); 1145 DCHECK(connection_->socket() || existing_spdy_session_.get() || using_quic_);
(...skipping 11 matching lines...) Expand all
1161 // We only set the socket motivation if we're the first to use 1157 // We only set the socket motivation if we're the first to use
1162 // this socket. Is there a race for two SPDY requests? We really 1158 // this socket. Is there a race for two SPDY requests? We really
1163 // need to plumb this through to the connect level. 1159 // need to plumb this through to the connect level.
1164 if (connection_->socket() && !connection_->is_reused()) 1160 if (connection_->socket() && !connection_->is_reused())
1165 SetSocketMotivation(); 1161 SetSocketMotivation();
1166 1162
1167 if (!using_spdy_) { 1163 if (!using_spdy_) {
1168 DCHECK(!IsSpdyAlternative()); 1164 DCHECK(!IsSpdyAlternative());
1169 // We may get ftp scheme when fetching ftp resources through proxy. 1165 // We may get ftp scheme when fetching ftp resources through proxy.
1170 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && 1166 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) &&
1171 (request_info_.url.SchemeIs("http") || 1167 (request_info_.url.SchemeIs(url::kHttpScheme) ||
1172 request_info_.url.SchemeIs("ftp")); 1168 request_info_.url.SchemeIs(url::kFtpScheme));
1173 if (delegate_->for_websockets()) { 1169 if (delegate_->for_websockets()) {
1174 DCHECK_NE(job_type_, PRECONNECT); 1170 DCHECK_NE(job_type_, PRECONNECT);
1175 DCHECK(delegate_->websocket_handshake_stream_create_helper()); 1171 DCHECK(delegate_->websocket_handshake_stream_create_helper());
1176 websocket_stream_.reset( 1172 websocket_stream_.reset(
1177 delegate_->websocket_handshake_stream_create_helper() 1173 delegate_->websocket_handshake_stream_create_helper()
1178 ->CreateBasicStream(std::move(connection_), using_proxy)); 1174 ->CreateBasicStream(std::move(connection_), using_proxy));
1179 } else { 1175 } else {
1180 stream_.reset(new HttpBasicStream( 1176 stream_.reset(new HttpBasicStream(
1181 std::move(connection_), using_proxy, 1177 std::move(connection_), using_proxy,
1182 session_->params().http_09_on_non_default_ports_enabled)); 1178 session_->params().http_09_on_non_default_ports_enabled));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 if (spdy_session->GetSSLInfo(&ssl_info)) { 1218 if (spdy_session->GetSSLInfo(&ssl_info)) {
1223 UMA_HISTOGRAM_SPARSE_SLOWLY( 1219 UMA_HISTOGRAM_SPARSE_SLOWLY(
1224 "Net.Http2SSLCipherSuite", 1220 "Net.Http2SSLCipherSuite",
1225 SSLConnectionStatusToCipherSuite(ssl_info.connection_status)); 1221 SSLConnectionStatusToCipherSuite(ssl_info.connection_status));
1226 } 1222 }
1227 1223
1228 new_spdy_session_ = spdy_session; 1224 new_spdy_session_ = spdy_session;
1229 spdy_session_direct_ = direct; 1225 spdy_session_direct_ = direct;
1230 const HostPortPair host_port_pair = spdy_session_key.host_port_pair(); 1226 const HostPortPair host_port_pair = spdy_session_key.host_port_pair();
1231 bool is_https = ssl_info.is_valid(); 1227 bool is_https = ssl_info.is_valid();
1232 url::SchemeHostPort scheme_host_port(is_https ? "https" : "http", 1228 url::SchemeHostPort scheme_host_port(
1233 host_port_pair.host(), 1229 is_https ? url::kHttpsScheme : url::kHttpScheme, host_port_pair.host(),
1234 host_port_pair.port()); 1230 host_port_pair.port());
1235 1231
1236 HttpServerProperties* http_server_properties = 1232 HttpServerProperties* http_server_properties =
1237 session_->http_server_properties(); 1233 session_->http_server_properties();
1238 if (http_server_properties) 1234 if (http_server_properties)
1239 http_server_properties->SetSupportsSpdy(scheme_host_port, true); 1235 http_server_properties->SetSupportsSpdy(scheme_host_port, true);
1240 1236
1241 // Create a SpdyHttpStream or a BidirectionalStreamImpl attached to the 1237 // Create a SpdyHttpStream or a BidirectionalStreamImpl attached to the
1242 // session; OnNewSpdySessionReadyCallback is not called until an event loop 1238 // session; OnNewSpdySessionReadyCallback is not called until an event loop
1243 // iteration later, so if the SpdySession is closed between then, allow 1239 // iteration later, so if the SpdySession is closed between then, allow
1244 // reuse state from the underlying socket, sampled by SpdyHttpStream, 1240 // reuse state from the underlying socket, sampled by SpdyHttpStream,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 if (request_info_.motivation == HttpRequestInfo::PRECONNECT_MOTIVATED) 1294 if (request_info_.motivation == HttpRequestInfo::PRECONNECT_MOTIVATED)
1299 connection_->socket()->SetSubresourceSpeculation(); 1295 connection_->socket()->SetSubresourceSpeculation();
1300 else if (request_info_.motivation == HttpRequestInfo::OMNIBOX_MOTIVATED) 1296 else if (request_info_.motivation == HttpRequestInfo::OMNIBOX_MOTIVATED)
1301 connection_->socket()->SetOmniboxSpeculation(); 1297 connection_->socket()->SetOmniboxSpeculation();
1302 // TODO(mbelshe): Add other motivations (like EARLY_LOAD_MOTIVATED). 1298 // TODO(mbelshe): Add other motivations (like EARLY_LOAD_MOTIVATED).
1303 } 1299 }
1304 1300
1305 bool HttpStreamFactoryImpl::Job::IsHttpsProxyAndHttpUrl() const { 1301 bool HttpStreamFactoryImpl::Job::IsHttpsProxyAndHttpUrl() const {
1306 if (!proxy_info_.is_https()) 1302 if (!proxy_info_.is_https())
1307 return false; 1303 return false;
1308 if (IsSpdyAlternative() || IsQuicAlternative()) { 1304 DCHECK(!IsSpdyAlternative());
Bence 2016/09/22 19:30:32 See DCHECK in line 232 and the one below.
1305 if (IsQuicAlternative()) {
1309 // We currently only support Alternate-Protocol where the original scheme 1306 // We currently only support Alternate-Protocol where the original scheme
Bence 2016/09/22 19:30:32 I think we do not support QUIC Alt-Svc either for
Ryan Hamilton 2016/09/22 21:38:05 I confess, I don't understand this comment at all.
Bence 2016/09/23 13:41:04 I added a TODO here, I'd like to clean this up in
1310 // is http. 1307 // is http.
1311 DCHECK(origin_url_.SchemeIs("http")); 1308 DCHECK(origin_url_.SchemeIs(url::kHttpScheme));
1312 return origin_url_.SchemeIs("http"); 1309 return origin_url_.SchemeIs(url::kHttpScheme);
1313 } 1310 }
1314 return request_info_.url.SchemeIs("http"); 1311 return request_info_.url.SchemeIs(url::kHttpScheme);
1315 } 1312 }
1316 1313
1317 bool HttpStreamFactoryImpl::Job::IsSpdyAlternative() const { 1314 bool HttpStreamFactoryImpl::Job::IsSpdyAlternative() const {
1318 return alternative_service_.protocol >= NPN_SPDY_MINIMUM_VERSION && 1315 return alternative_service_.protocol >= NPN_SPDY_MINIMUM_VERSION &&
1319 alternative_service_.protocol <= NPN_SPDY_MAXIMUM_VERSION; 1316 alternative_service_.protocol <= NPN_SPDY_MAXIMUM_VERSION;
1320 } 1317 }
1321 1318
1322 bool HttpStreamFactoryImpl::Job::IsQuicAlternative() const { 1319 bool HttpStreamFactoryImpl::Job::IsQuicAlternative() const {
1323 return alternative_service_.protocol == QUIC; 1320 return alternative_service_.protocol == QUIC;
1324 } 1321 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 case ERR_INTERNET_DISCONNECTED: 1375 case ERR_INTERNET_DISCONNECTED:
1379 case ERR_ADDRESS_UNREACHABLE: 1376 case ERR_ADDRESS_UNREACHABLE:
1380 case ERR_CONNECTION_CLOSED: 1377 case ERR_CONNECTION_CLOSED:
1381 case ERR_CONNECTION_TIMED_OUT: 1378 case ERR_CONNECTION_TIMED_OUT:
1382 case ERR_CONNECTION_RESET: 1379 case ERR_CONNECTION_RESET:
1383 case ERR_CONNECTION_REFUSED: 1380 case ERR_CONNECTION_REFUSED:
1384 case ERR_CONNECTION_ABORTED: 1381 case ERR_CONNECTION_ABORTED:
1385 case ERR_TIMED_OUT: 1382 case ERR_TIMED_OUT:
1386 case ERR_TUNNEL_CONNECTION_FAILED: 1383 case ERR_TUNNEL_CONNECTION_FAILED:
1387 case ERR_SOCKS_CONNECTION_FAILED: 1384 case ERR_SOCKS_CONNECTION_FAILED:
1388 // This can happen in the case of trying to talk to a proxy using SSL, and 1385 // This can happen in the case of trying to talk to a proxy using SSL, and
Bence 2016/09/22 19:30:32 Does this comment and the next one each refer to t
Ryan Hamilton 2016/09/22 21:38:05 I think the second comment actually applies to:
Bence 2016/09/23 13:41:04 Thanks. I moved and refined the comments.
1389 // ending up talking to a captive portal that supports SSL instead. 1386 // ending up talking to a captive portal that supports SSL instead.
1390 case ERR_PROXY_CERTIFICATE_INVALID: 1387 case ERR_PROXY_CERTIFICATE_INVALID:
1391 // This can happen when trying to talk SSL to a non-SSL server (Like a 1388 // This can happen when trying to talk SSL to a non-SSL server (like a
1392 // captive portal). 1389 // captive portal).
1393 case ERR_QUIC_PROTOCOL_ERROR: 1390 case ERR_QUIC_PROTOCOL_ERROR:
1394 case ERR_QUIC_HANDSHAKE_FAILED: 1391 case ERR_QUIC_HANDSHAKE_FAILED:
1395 case ERR_MSG_TOO_BIG: 1392 case ERR_MSG_TOO_BIG:
1396 case ERR_SSL_PROTOCOL_ERROR: 1393 case ERR_SSL_PROTOCOL_ERROR:
1397 break; 1394 break;
1398 case ERR_SOCKS_CONNECTION_HOST_UNREACHABLE: 1395 case ERR_SOCKS_CONNECTION_HOST_UNREACHABLE:
1399 // Remap the SOCKS-specific "host unreachable" error to a more 1396 // Remap the SOCKS-specific "host unreachable" error to a more
1400 // generic error code (this way consumers like the link doctor 1397 // generic error code (this way consumers like the link doctor
1401 // know to substitute their error page). 1398 // know to substitute their error page).
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1473 ssl_info_.cert_status); 1470 ssl_info_.cert_status);
1474 1471
1475 int load_flags = request_info_.load_flags; 1472 int load_flags = request_info_.load_flags;
1476 if (session_->params().ignore_certificate_errors) 1473 if (session_->params().ignore_certificate_errors)
1477 load_flags |= LOAD_IGNORE_ALL_CERT_ERRORS; 1474 load_flags |= LOAD_IGNORE_ALL_CERT_ERRORS;
1478 if (ssl_socket->IgnoreCertError(error, load_flags)) 1475 if (ssl_socket->IgnoreCertError(error, load_flags))
1479 return OK; 1476 return OK;
1480 return error; 1477 return error;
1481 } 1478 }
1482 1479
1483 void HttpStreamFactoryImpl::Job::SwitchToSpdyMode() {
1484 using_spdy_ = true;
1485 }
1486
1487 void HttpStreamFactoryImpl::Job::ReportJobSucceededForRequest() { 1480 void HttpStreamFactoryImpl::Job::ReportJobSucceededForRequest() {
1488 if (using_existing_quic_session_) { 1481 if (using_existing_quic_session_) {
1489 // If an existing session was used, then no TCP connection was 1482 // If an existing session was used, then no TCP connection was
1490 // started. 1483 // started.
1491 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE); 1484 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE);
1492 } else if (IsSpdyAlternative() || IsQuicAlternative()) { 1485 } else if (IsSpdyAlternative() || IsQuicAlternative()) {
1493 // This Job was the alternative Job, and hence won the race. 1486 // This Job was the alternative Job, and hence won the race.
1494 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE); 1487 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE);
1495 } else { 1488 } else {
1496 // This Job was the normal Job, and hence the alternative Job lost the race. 1489 // This Job was the normal Job, and hence the alternative Job lost the race.
1497 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_LOST_RACE); 1490 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_LOST_RACE);
1498 } 1491 }
1499 } 1492 }
1500 1493
1501 ClientSocketPoolManager::SocketGroupType 1494 ClientSocketPoolManager::SocketGroupType
1502 HttpStreamFactoryImpl::Job::GetSocketGroup() const { 1495 HttpStreamFactoryImpl::Job::GetSocketGroup() const {
1503 std::string scheme = origin_url_.scheme(); 1496 std::string scheme = origin_url_.scheme();
1504 if (scheme == "https" || scheme == "wss" || IsSpdyAlternative()) 1497 if (scheme == url::kHttpsScheme || scheme == url::kWssScheme)
1505 return ClientSocketPoolManager::SSL_GROUP; 1498 return ClientSocketPoolManager::SSL_GROUP;
1506 1499
1507 if (scheme == "ftp") 1500 if (scheme == url::kFtpScheme)
1508 return ClientSocketPoolManager::FTP_GROUP; 1501 return ClientSocketPoolManager::FTP_GROUP;
1509 1502
1510 return ClientSocketPoolManager::NORMAL_GROUP; 1503 return ClientSocketPoolManager::NORMAL_GROUP;
1511 } 1504 }
1512 1505
1513 // If the connection succeeds, failed connection attempts leading up to the 1506 // If the connection succeeds, failed connection attempts leading up to the
1514 // success will be returned via the successfully connected socket. If the 1507 // success will be returned via the successfully connected socket. If the
1515 // connection fails, failed connection attempts will be returned via the 1508 // connection fails, failed connection attempts will be returned via the
1516 // ClientSocketHandle. Check whether a socket was returned and copy the 1509 // ClientSocketHandle. Check whether a socket was returned and copy the
1517 // connection attempts from the proper place. 1510 // connection attempts from the proper place.
1518 void HttpStreamFactoryImpl::Job:: 1511 void HttpStreamFactoryImpl::Job::
1519 MaybeCopyConnectionAttemptsFromSocketOrHandle() { 1512 MaybeCopyConnectionAttemptsFromSocketOrHandle() {
1520 if (!connection_) 1513 if (!connection_)
1521 return; 1514 return;
1522 1515
1523 ConnectionAttempts socket_attempts = connection_->connection_attempts(); 1516 ConnectionAttempts socket_attempts = connection_->connection_attempts();
1524 if (connection_->socket()) { 1517 if (connection_->socket()) {
1525 connection_->socket()->GetConnectionAttempts(&socket_attempts); 1518 connection_->socket()->GetConnectionAttempts(&socket_attempts);
1526 } 1519 }
1527 1520
1528 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts); 1521 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts);
1529 } 1522 }
1530 1523
1531 } // namespace net 1524 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698