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

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

Issue 2932503005: Change AlternativeServiceInfo to a class (Closed)
Patch Set: Created 3 years, 6 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) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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_controller.h" 5 #include "net/http/http_stream_factory_impl_job_controller.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 int HttpStreamFactoryImpl::JobController::DoCreateJobs() { 775 int HttpStreamFactoryImpl::JobController::DoCreateJobs() {
776 DCHECK(!main_job_); 776 DCHECK(!main_job_);
777 DCHECK(!alternative_job_); 777 DCHECK(!alternative_job_);
778 778
779 HostPortPair destination(HostPortPair::FromURL(request_info_.url)); 779 HostPortPair destination(HostPortPair::FromURL(request_info_.url));
780 GURL origin_url = ApplyHostMappingRules(request_info_.url, &destination); 780 GURL origin_url = ApplyHostMappingRules(request_info_.url, &destination);
781 781
782 // Create an alternative job if alternative service is set up for this domain. 782 // Create an alternative job if alternative service is set up for this domain.
783 const AlternativeService alternative_service = 783 const AlternativeService alternative_service =
784 GetAlternativeServiceInfoFor(request_info_, delegate_, stream_type_) 784 GetAlternativeServiceInfoFor(request_info_, delegate_, stream_type_)
785 .alternative_service; 785 .alternative_service();
786 786
787 if (is_preconnect_) { 787 if (is_preconnect_) {
788 // Due to how the socket pools handle priorities and idle sockets, only IDLE 788 // Due to how the socket pools handle priorities and idle sockets, only IDLE
789 // priority currently makes sense for preconnects. The priority for 789 // priority currently makes sense for preconnects. The priority for
790 // preconnects is currently ignored (see RequestSocketsForPool()), but could 790 // preconnects is currently ignored (see RequestSocketsForPool()), but could
791 // be used at some point for proxy resolution or something. 791 // be used at some point for proxy resolution or something.
792 if (alternative_service.protocol != kProtoUnknown) { 792 if (alternative_service.protocol != kProtoUnknown) {
793 HostPortPair alternative_destination( 793 HostPortPair alternative_destination(
794 alternative_service.host_port_pair()); 794 alternative_service.host_port_pair());
795 ignore_result( 795 ignore_result(
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 HttpStreamFactoryImpl::JobController::GetAlternativeServiceInfoFor( 1035 HttpStreamFactoryImpl::JobController::GetAlternativeServiceInfoFor(
1036 const HttpRequestInfo& request_info, 1036 const HttpRequestInfo& request_info,
1037 HttpStreamRequest::Delegate* delegate, 1037 HttpStreamRequest::Delegate* delegate,
1038 HttpStreamRequest::StreamType stream_type) { 1038 HttpStreamRequest::StreamType stream_type) {
1039 if (!enable_alternative_services_) 1039 if (!enable_alternative_services_)
1040 return AlternativeServiceInfo(); 1040 return AlternativeServiceInfo();
1041 1041
1042 AlternativeServiceInfo alternative_service_info = 1042 AlternativeServiceInfo alternative_service_info =
1043 GetAlternativeServiceInfoInternal(request_info, delegate, stream_type); 1043 GetAlternativeServiceInfoInternal(request_info, delegate, stream_type);
1044 AlternativeServiceType type; 1044 AlternativeServiceType type;
1045 if (alternative_service_info.alternative_service.protocol == kProtoUnknown) { 1045 if (alternative_service_info.alternative_service().protocol ==
1046 kProtoUnknown) {
1046 type = NO_ALTERNATIVE_SERVICE; 1047 type = NO_ALTERNATIVE_SERVICE;
1047 } else if (alternative_service_info.alternative_service.protocol == 1048 } else if (alternative_service_info.alternative_service().protocol ==
1048 kProtoQUIC) { 1049 kProtoQUIC) {
1049 if (request_info.url.host_piece() == 1050 if (request_info.url.host_piece() ==
1050 alternative_service_info.alternative_service.host) { 1051 alternative_service_info.alternative_service().host) {
1051 type = QUIC_SAME_DESTINATION; 1052 type = QUIC_SAME_DESTINATION;
1052 } else { 1053 } else {
1053 type = QUIC_DIFFERENT_DESTINATION; 1054 type = QUIC_DIFFERENT_DESTINATION;
1054 } 1055 }
1055 } else { 1056 } else {
1056 if (request_info.url.host_piece() == 1057 if (request_info.url.host_piece() ==
1057 alternative_service_info.alternative_service.host) { 1058 alternative_service_info.alternative_service().host) {
1058 type = NOT_QUIC_SAME_DESTINATION; 1059 type = NOT_QUIC_SAME_DESTINATION;
1059 } else { 1060 } else {
1060 type = NOT_QUIC_DIFFERENT_DESTINATION; 1061 type = NOT_QUIC_DIFFERENT_DESTINATION;
1061 } 1062 }
1062 } 1063 }
1063 UMA_HISTOGRAM_ENUMERATION("Net.AlternativeServiceTypeForRequest", type, 1064 UMA_HISTOGRAM_ENUMERATION("Net.AlternativeServiceTypeForRequest", type,
1064 MAX_ALTERNATIVE_SERVICE_TYPE); 1065 MAX_ALTERNATIVE_SERVICE_TYPE);
1065 return alternative_service_info; 1066 return alternative_service_info;
1066 } 1067 }
1067 1068
(...skipping 17 matching lines...) Expand all
1085 1086
1086 bool quic_advertised = false; 1087 bool quic_advertised = false;
1087 bool quic_all_broken = true; 1088 bool quic_all_broken = true;
1088 1089
1089 // First alternative service that is not marked as broken. 1090 // First alternative service that is not marked as broken.
1090 AlternativeServiceInfo first_alternative_service_info; 1091 AlternativeServiceInfo first_alternative_service_info;
1091 1092
1092 for (const AlternativeServiceInfo& alternative_service_info : 1093 for (const AlternativeServiceInfo& alternative_service_info :
1093 alternative_service_info_vector) { 1094 alternative_service_info_vector) {
1094 DCHECK(IsAlternateProtocolValid( 1095 DCHECK(IsAlternateProtocolValid(
1095 alternative_service_info.alternative_service.protocol)); 1096 alternative_service_info.alternative_service().protocol));
1096 if (!quic_advertised && 1097 if (!quic_advertised &&
1097 alternative_service_info.alternative_service.protocol == kProtoQUIC) 1098 alternative_service_info.alternative_service().protocol == kProtoQUIC)
1098 quic_advertised = true; 1099 quic_advertised = true;
1099 if (http_server_properties.IsAlternativeServiceBroken( 1100 if (http_server_properties.IsAlternativeServiceBroken(
1100 alternative_service_info.alternative_service)) { 1101 alternative_service_info.alternative_service())) {
1101 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN, false); 1102 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN, false);
1102 continue; 1103 continue;
1103 } 1104 }
1104 1105
1105 // Some shared unix systems may have user home directories (like 1106 // Some shared unix systems may have user home directories (like
1106 // http://foo.com/~mike) which allow users to emit headers. This is a bad 1107 // http://foo.com/~mike) which allow users to emit headers. This is a bad
1107 // idea already, but with Alternate-Protocol, it provides the ability for a 1108 // idea already, but with Alternate-Protocol, it provides the ability for a
1108 // single user on a multi-user system to hijack the alternate protocol. 1109 // single user on a multi-user system to hijack the alternate protocol.
1109 // These systems also enforce ports <1024 as restricted ports. So don't 1110 // These systems also enforce ports <1024 as restricted ports. So don't
1110 // allow protocol upgrades to user-controllable ports. 1111 // allow protocol upgrades to user-controllable ports.
1111 const int kUnrestrictedPort = 1024; 1112 const int kUnrestrictedPort = 1024;
1112 if (!session_->params().enable_user_alternate_protocol_ports && 1113 if (!session_->params().enable_user_alternate_protocol_ports &&
1113 (alternative_service_info.alternative_service.port >= 1114 (alternative_service_info.alternative_service().port >=
1114 kUnrestrictedPort && 1115 kUnrestrictedPort &&
1115 origin.port() < kUnrestrictedPort)) 1116 origin.port() < kUnrestrictedPort))
1116 continue; 1117 continue;
1117 1118
1118 if (alternative_service_info.alternative_service.protocol == kProtoHTTP2) { 1119 if (alternative_service_info.alternative_service().protocol ==
1120 kProtoHTTP2) {
1119 if (!session_->params().enable_http2_alternative_service) 1121 if (!session_->params().enable_http2_alternative_service)
1120 continue; 1122 continue;
1121 1123
1122 // Cache this entry if we don't have a non-broken Alt-Svc yet. 1124 // Cache this entry if we don't have a non-broken Alt-Svc yet.
1123 if (first_alternative_service_info.alternative_service.protocol == 1125 if (first_alternative_service_info.alternative_service().protocol ==
1124 kProtoUnknown) 1126 kProtoUnknown)
1125 first_alternative_service_info = alternative_service_info; 1127 first_alternative_service_info = alternative_service_info;
1126 continue; 1128 continue;
1127 } 1129 }
1128 1130
1129 DCHECK_EQ(kProtoQUIC, 1131 DCHECK_EQ(kProtoQUIC,
1130 alternative_service_info.alternative_service.protocol); 1132 alternative_service_info.alternative_service().protocol);
1131 quic_all_broken = false; 1133 quic_all_broken = false;
1132 if (!session_->IsQuicEnabled()) 1134 if (!session_->IsQuicEnabled())
1133 continue; 1135 continue;
1134 1136
1135 if (stream_type == HttpStreamRequest::BIDIRECTIONAL_STREAM && 1137 if (stream_type == HttpStreamRequest::BIDIRECTIONAL_STREAM &&
1136 session_->params().quic_disable_bidirectional_streams) { 1138 session_->params().quic_disable_bidirectional_streams) {
1137 continue; 1139 continue;
1138 } 1140 }
1139 1141
1140 if (!original_url.SchemeIs(url::kHttpsScheme)) 1142 if (!original_url.SchemeIs(url::kHttpsScheme))
1141 continue; 1143 continue;
1142 1144
1143 // Check whether there is an existing QUIC session to use for this origin. 1145 // Check whether there is an existing QUIC session to use for this origin.
1144 HostPortPair mapped_origin(origin.host(), origin.port()); 1146 HostPortPair mapped_origin(origin.host(), origin.port());
1145 ignore_result(ApplyHostMappingRules(original_url, &mapped_origin)); 1147 ignore_result(ApplyHostMappingRules(original_url, &mapped_origin));
1146 QuicServerId server_id(mapped_origin, request_info.privacy_mode); 1148 QuicServerId server_id(mapped_origin, request_info.privacy_mode);
1147 1149
1148 HostPortPair destination( 1150 HostPortPair destination(
1149 alternative_service_info.alternative_service.host_port_pair()); 1151 alternative_service_info.alternative_service().host_port_pair());
1150 ignore_result(ApplyHostMappingRules(original_url, &destination)); 1152 ignore_result(ApplyHostMappingRules(original_url, &destination));
1151 1153
1152 if (session_->quic_stream_factory()->CanUseExistingSession(server_id, 1154 if (session_->quic_stream_factory()->CanUseExistingSession(server_id,
1153 destination)) { 1155 destination)) {
1154 return alternative_service_info; 1156 return alternative_service_info;
1155 } 1157 }
1156 1158
1157 // Cache this entry if we don't have a non-broken Alt-Svc yet. 1159 // Cache this entry if we don't have a non-broken Alt-Svc yet.
1158 if (first_alternative_service_info.alternative_service.protocol == 1160 if (first_alternative_service_info.alternative_service().protocol ==
1159 kProtoUnknown) 1161 kProtoUnknown)
1160 first_alternative_service_info = alternative_service_info; 1162 first_alternative_service_info = alternative_service_info;
1161 } 1163 }
1162 1164
1163 // Ask delegate to mark QUIC as broken for the origin. 1165 // Ask delegate to mark QUIC as broken for the origin.
1164 if (quic_advertised && quic_all_broken && delegate != nullptr) 1166 if (quic_advertised && quic_all_broken && delegate != nullptr)
1165 delegate->OnQuicBroken(); 1167 delegate->OnQuicBroken();
1166 1168
1167 return first_alternative_service_info; 1169 return first_alternative_service_info;
1168 } 1170 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 // If ReconsiderProxyAfterError() failed synchronously, it means 1296 // If ReconsiderProxyAfterError() failed synchronously, it means
1295 // there was nothing left to fall-back to, so fail the transaction 1297 // there was nothing left to fall-back to, so fail the transaction
1296 // with the last connection error we got. 1298 // with the last connection error we got.
1297 // TODO(eroman): This is a confusing contract, make it more obvious. 1299 // TODO(eroman): This is a confusing contract, make it more obvious.
1298 rv = error; 1300 rv = error;
1299 } 1301 }
1300 return rv; 1302 return rv;
1301 } 1303 }
1302 1304
1303 } // namespace net 1305 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_manager_unittest.cc ('k') | net/http/http_stream_factory_impl_job_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698