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

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

Issue 2894303002: Change HttpStreamFactoryImpl::Job to take a AlternativeServiceInfo
Patch Set: Change QuicStreamFactory::CreateSession() to take a QUIC version. Created 3 years, 7 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 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 UMA_HISTOGRAM_ENUMERATION("Net.TokenBinding.KeyMatch", match, KEY_MATCH_MAX); 118 UMA_HISTOGRAM_ENUMERATION("Net.TokenBinding.KeyMatch", match, KEY_MATCH_MAX);
119 } 119 }
120 120
121 } // namespace 121 } // namespace
122 122
123 // Returns parameters associated with the start of a HTTP stream job. 123 // Returns parameters associated with the start of a HTTP stream job.
124 std::unique_ptr<base::Value> NetLogHttpStreamJobCallback( 124 std::unique_ptr<base::Value> NetLogHttpStreamJobCallback(
125 const NetLogSource& source, 125 const NetLogSource& source,
126 const GURL* original_url, 126 const GURL* original_url,
127 const GURL* url, 127 const GURL* url,
128 const AlternativeService* alternative_service, 128 const AlternativeServiceInfo* alternative_service_info,
129 RequestPriority priority, 129 RequestPriority priority,
130 NetLogCaptureMode /* capture_mode */) { 130 NetLogCaptureMode /* capture_mode */) {
131 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 131 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
132 if (source.IsValid()) 132 if (source.IsValid())
133 source.AddToEventParameters(dict.get()); 133 source.AddToEventParameters(dict.get());
134 dict->SetString("original_url", original_url->GetOrigin().spec()); 134 dict->SetString("original_url", original_url->GetOrigin().spec());
135 dict->SetString("url", url->GetOrigin().spec()); 135 dict->SetString("url", url->GetOrigin().spec());
136 dict->SetString("alternative_service", alternative_service->ToString()); 136 dict->SetString("alternative_service",
137 alternative_service_info->alternative_service.ToString());
137 dict->SetString("priority", RequestPriorityToString(priority)); 138 dict->SetString("priority", RequestPriorityToString(priority));
138 return std::move(dict); 139 return std::move(dict);
139 } 140 }
140 141
141 // Returns parameters associated with the Proto (with NPN negotiation) of a HTTP 142 // Returns parameters associated with the Proto (with NPN negotiation) of a HTTP
142 // stream. 143 // stream.
143 std::unique_ptr<base::Value> NetLogHttpStreamProtoCallback( 144 std::unique_ptr<base::Value> NetLogHttpStreamProtoCallback(
144 NextProto negotiated_protocol, 145 NextProto negotiated_protocol,
145 NetLogCaptureMode /* capture_mode */) { 146 NetLogCaptureMode /* capture_mode */) {
146 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 147 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
(...skipping 17 matching lines...) Expand all
164 : Job(delegate, 165 : Job(delegate,
165 job_type, 166 job_type,
166 session, 167 session,
167 request_info, 168 request_info,
168 priority, 169 priority,
169 proxy_info, 170 proxy_info,
170 server_ssl_config, 171 server_ssl_config,
171 proxy_ssl_config, 172 proxy_ssl_config,
172 destination, 173 destination,
173 origin_url, 174 origin_url,
174 AlternativeService(), 175 AlternativeServiceInfo(),
175 ProxyServer(), 176 ProxyServer(),
176 enable_ip_based_pooling, 177 enable_ip_based_pooling,
177 net_log) {} 178 net_log) {}
178 179
179 HttpStreamFactoryImpl::Job::Job(Delegate* delegate, 180 HttpStreamFactoryImpl::Job::Job(
180 JobType job_type, 181 Delegate* delegate,
181 HttpNetworkSession* session, 182 JobType job_type,
182 const HttpRequestInfo& request_info, 183 HttpNetworkSession* session,
183 RequestPriority priority, 184 const HttpRequestInfo& request_info,
184 const ProxyInfo& proxy_info, 185 RequestPriority priority,
185 const SSLConfig& server_ssl_config, 186 const ProxyInfo& proxy_info,
186 const SSLConfig& proxy_ssl_config, 187 const SSLConfig& server_ssl_config,
187 HostPortPair destination, 188 const SSLConfig& proxy_ssl_config,
188 GURL origin_url, 189 HostPortPair destination,
189 AlternativeService alternative_service, 190 GURL origin_url,
190 const ProxyServer& alternative_proxy_server, 191 const AlternativeServiceInfo& alternative_service_info,
191 bool enable_ip_based_pooling, 192 const ProxyServer& alternative_proxy_server,
192 NetLog* net_log) 193 bool enable_ip_based_pooling,
194 NetLog* net_log)
193 : request_info_(request_info), 195 : request_info_(request_info),
194 priority_(priority), 196 priority_(priority),
195 proxy_info_(proxy_info), 197 proxy_info_(proxy_info),
196 server_ssl_config_(server_ssl_config), 198 server_ssl_config_(server_ssl_config),
197 proxy_ssl_config_(proxy_ssl_config), 199 proxy_ssl_config_(proxy_ssl_config),
198 net_log_( 200 net_log_(
199 NetLogWithSource::Make(net_log, NetLogSourceType::HTTP_STREAM_JOB)), 201 NetLogWithSource::Make(net_log, NetLogSourceType::HTTP_STREAM_JOB)),
200 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), 202 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))),
201 connection_(new ClientSocketHandle), 203 connection_(new ClientSocketHandle),
202 session_(session), 204 session_(session),
203 state_(STATE_NONE), 205 state_(STATE_NONE),
204 next_state_(STATE_NONE), 206 next_state_(STATE_NONE),
205 destination_(destination), 207 destination_(destination),
206 origin_url_(origin_url), 208 origin_url_(origin_url),
207 alternative_service_(alternative_service), 209 alternative_service_info_(alternative_service_info),
208 alternative_proxy_server_(alternative_proxy_server), 210 alternative_proxy_server_(alternative_proxy_server),
209 enable_ip_based_pooling_(enable_ip_based_pooling), 211 enable_ip_based_pooling_(enable_ip_based_pooling),
210 delegate_(delegate), 212 delegate_(delegate),
211 job_type_(job_type), 213 job_type_(job_type),
212 using_ssl_(origin_url_.SchemeIs(url::kHttpsScheme) || 214 using_ssl_(origin_url_.SchemeIs(url::kHttpsScheme) ||
213 origin_url_.SchemeIs(url::kWssScheme)), 215 origin_url_.SchemeIs(url::kWssScheme)),
214 using_spdy_(false), 216 using_spdy_(false),
215 using_quic_(false), 217 using_quic_(false),
216 should_reconsider_proxy_(false), 218 should_reconsider_proxy_(false),
217 quic_request_(session_->quic_stream_factory()), 219 quic_request_(session_->quic_stream_factory()),
218 using_existing_quic_session_(false), 220 using_existing_quic_session_(false),
219 establishing_tunnel_(false), 221 establishing_tunnel_(false),
220 was_alpn_negotiated_(false), 222 was_alpn_negotiated_(false),
221 negotiated_protocol_(kProtoUnknown), 223 negotiated_protocol_(kProtoUnknown),
222 num_streams_(0), 224 num_streams_(0),
223 spdy_session_direct_(false), 225 spdy_session_direct_(false),
224 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), 226 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM),
225 ptr_factory_(this) { 227 ptr_factory_(this) {
226 DCHECK(session); 228 DCHECK(session);
227 // The job can't have alternative service and alternative proxy server set at 229 // The job can't have alternative service and alternative proxy server set at
228 // the same time since alternative services are used for requests that are 230 // the same time since alternative services are used for requests that are
229 // fetched directly, while the alternative proxy server is used for requests 231 // fetched directly, while the alternative proxy server is used for requests
230 // that should be fetched using proxy. 232 // that should be fetched using proxy.
231 DCHECK(alternative_service_.protocol == kProtoUnknown || 233 DCHECK(alternative_service_info_.alternative_service.protocol ==
234 kProtoUnknown ||
232 !alternative_proxy_server_.is_valid()); 235 !alternative_proxy_server_.is_valid());
233 DCHECK(!alternative_proxy_server_.is_valid() || 236 DCHECK(!alternative_proxy_server_.is_valid() ||
234 !(IsSpdyAlternative() || IsQuicAlternative())); 237 !(IsSpdyAlternative() || IsQuicAlternative()));
235 // If either the alternative service protocol is specified or if the 238 // If either the alternative service protocol is specified or if the
236 // alternative proxy server is valid, then the job type must be set to 239 // alternative proxy server is valid, then the job type must be set to
237 // either ALTERNATIVE or PRECONNECT. 240 // either ALTERNATIVE or PRECONNECT.
238 DCHECK((alternative_service_.protocol == kProtoUnknown && 241 DCHECK((alternative_service_info_.alternative_service.protocol ==
242 kProtoUnknown &&
239 !alternative_proxy_server_.is_valid()) || 243 !alternative_proxy_server_.is_valid()) ||
240 (job_type_ == ALTERNATIVE || job_type_ == PRECONNECT)); 244 (job_type_ == ALTERNATIVE || job_type_ == PRECONNECT));
241 // If the alternative proxy server is valid, then the job type must be 245 // If the alternative proxy server is valid, then the job type must be
242 // set to ALTERNATIVE. 246 // set to ALTERNATIVE.
243 DCHECK(!alternative_proxy_server_.is_valid() || job_type_ == ALTERNATIVE); 247 DCHECK(!alternative_proxy_server_.is_valid() || job_type_ == ALTERNATIVE);
244 248
245 if (IsSpdyAlternative()) { 249 if (IsSpdyAlternative()) {
246 DCHECK(origin_url_.SchemeIs(url::kHttpsScheme)); 250 DCHECK(origin_url_.SchemeIs(url::kHttpsScheme));
247 } 251 }
248 if (IsQuicAlternative()) { 252 if (IsQuicAlternative()) {
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 return ERR_IO_PENDING; 727 return ERR_IO_PENDING;
724 } 728 }
725 729
726 int HttpStreamFactoryImpl::Job::DoStart() { 730 int HttpStreamFactoryImpl::Job::DoStart() {
727 const NetLogWithSource* net_log = delegate_->GetNetLog(); 731 const NetLogWithSource* net_log = delegate_->GetNetLog();
728 732
729 if (net_log) { 733 if (net_log) {
730 net_log_.BeginEvent( 734 net_log_.BeginEvent(
731 NetLogEventType::HTTP_STREAM_JOB, 735 NetLogEventType::HTTP_STREAM_JOB,
732 base::Bind(&NetLogHttpStreamJobCallback, net_log->source(), 736 base::Bind(&NetLogHttpStreamJobCallback, net_log->source(),
733 &request_info_.url, &origin_url_, &alternative_service_, 737 &request_info_.url, &origin_url_, &alternative_service_info_,
734 priority_)); 738 priority_));
735 net_log->AddEvent(NetLogEventType::HTTP_STREAM_REQUEST_STARTED_JOB, 739 net_log->AddEvent(NetLogEventType::HTTP_STREAM_REQUEST_STARTED_JOB,
736 net_log_.source().ToEventParametersCallback()); 740 net_log_.source().ToEventParametersCallback());
737 } 741 }
738 742
739 // Don't connect to restricted ports. 743 // Don't connect to restricted ports.
740 if (!IsPortAllowedForScheme(destination_.port(), 744 if (!IsPortAllowedForScheme(destination_.port(),
741 request_info_.url.scheme())) { 745 request_info_.url.scheme())) {
742 return ERR_UNSAFE_PORT; 746 return ERR_UNSAFE_PORT;
743 } 747 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 replacements.ClearRef(); 855 replacements.ClearRef();
852 url = url.ReplaceComponents(replacements); 856 url = url.ReplaceComponents(replacements);
853 } else { 857 } else {
854 DCHECK(using_ssl_); 858 DCHECK(using_ssl_);
855 // The certificate of a QUIC alternative server is expected to be valid 859 // The certificate of a QUIC alternative server is expected to be valid
856 // for the origin of the request (in addition to being valid for the 860 // for the origin of the request (in addition to being valid for the
857 // server itself). 861 // server itself).
858 destination = destination_; 862 destination = destination_;
859 ssl_config = &server_ssl_config_; 863 ssl_config = &server_ssl_config_;
860 } 864 }
861 int rv = 865 QuicVersionVector advertised_versions;
862 quic_request_.Request(destination, request_info_.privacy_mode, 866 advertised_versions.push_back(QUIC_VERSION_37);
863 ssl_config->GetCertVerifyFlags(), url, 867 // TODO(zhongyi): change this to
864 request_info_.method, net_log_, io_callback_); 868 // alternative_service_info_.advertised_versions.
869
870 int rv = quic_request_.Request(
871 destination, advertised_versions, request_info_.privacy_mode,
872 ssl_config->GetCertVerifyFlags(), url, request_info_.method, net_log_,
873 io_callback_);
865 if (rv == OK) { 874 if (rv == OK) {
866 using_existing_quic_session_ = true; 875 using_existing_quic_session_ = true;
867 } else { 876 } else {
868 // There's no available QUIC session. Inform the delegate how long to 877 // There's no available QUIC session. Inform the delegate how long to
869 // delay the main job. 878 // delay the main job.
870 if (rv == ERR_IO_PENDING) { 879 if (rv == ERR_IO_PENDING) {
871 delegate_->MaybeSetWaitTimeForMainJob( 880 delegate_->MaybeSetWaitTimeForMainJob(
872 quic_request_.GetTimeDelayForWaitingJob()); 881 quic_request_.GetTimeDelayForWaitingJob());
873 } 882 }
874 } 883 }
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 // We currently only support Alternate-Protocol where the original scheme 1292 // We currently only support Alternate-Protocol where the original scheme
1284 // is http. 1293 // is http.
1285 // TODO(bnc): This comment is probably incorrect. 1294 // TODO(bnc): This comment is probably incorrect.
1286 DCHECK(origin_url_.SchemeIs(url::kHttpScheme)); 1295 DCHECK(origin_url_.SchemeIs(url::kHttpScheme));
1287 return origin_url_.SchemeIs(url::kHttpScheme); 1296 return origin_url_.SchemeIs(url::kHttpScheme);
1288 } 1297 }
1289 return request_info_.url.SchemeIs(url::kHttpScheme); 1298 return request_info_.url.SchemeIs(url::kHttpScheme);
1290 } 1299 }
1291 1300
1292 bool HttpStreamFactoryImpl::Job::IsSpdyAlternative() const { 1301 bool HttpStreamFactoryImpl::Job::IsSpdyAlternative() const {
1293 return alternative_service_.protocol == kProtoHTTP2; 1302 return alternative_service_info_.alternative_service.protocol == kProtoHTTP2;
1294 } 1303 }
1295 1304
1296 bool HttpStreamFactoryImpl::Job::IsQuicAlternative() const { 1305 bool HttpStreamFactoryImpl::Job::IsQuicAlternative() const {
1297 return alternative_service_.protocol == kProtoQUIC; 1306 return alternative_service_info_.alternative_service.protocol == kProtoQUIC;
1298 } 1307 }
1299 1308
1300 void HttpStreamFactoryImpl::Job::InitSSLConfig(SSLConfig* ssl_config, 1309 void HttpStreamFactoryImpl::Job::InitSSLConfig(SSLConfig* ssl_config,
1301 bool is_proxy) const { 1310 bool is_proxy) const {
1302 if (!is_proxy) { 1311 if (!is_proxy) {
1303 // Prior to HTTP/2 and SPDY, some servers use TLS renegotiation to request 1312 // Prior to HTTP/2 and SPDY, some servers use TLS renegotiation to request
1304 // TLS client authentication after the HTTP request was sent. Allow 1313 // TLS client authentication after the HTTP request was sent. Allow
1305 // renegotiation for only those connections. 1314 // renegotiation for only those connections.
1306 // 1315 //
1307 // Note that this does NOT implement the provision in 1316 // Note that this does NOT implement the provision in
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 HttpStreamFactoryImpl::Job::Delegate* delegate, 1481 HttpStreamFactoryImpl::Job::Delegate* delegate,
1473 HttpStreamFactoryImpl::JobType job_type, 1482 HttpStreamFactoryImpl::JobType job_type,
1474 HttpNetworkSession* session, 1483 HttpNetworkSession* session,
1475 const HttpRequestInfo& request_info, 1484 const HttpRequestInfo& request_info,
1476 RequestPriority priority, 1485 RequestPriority priority,
1477 const ProxyInfo& proxy_info, 1486 const ProxyInfo& proxy_info,
1478 const SSLConfig& server_ssl_config, 1487 const SSLConfig& server_ssl_config,
1479 const SSLConfig& proxy_ssl_config, 1488 const SSLConfig& proxy_ssl_config,
1480 HostPortPair destination, 1489 HostPortPair destination,
1481 GURL origin_url, 1490 GURL origin_url,
1482 AlternativeService alternative_service, 1491 const AlternativeServiceInfo& alternative_service_info,
1483 bool enable_ip_based_pooling, 1492 bool enable_ip_based_pooling,
1484 NetLog* net_log) { 1493 NetLog* net_log) {
1485 return base::MakeUnique<HttpStreamFactoryImpl::Job>( 1494 return base::MakeUnique<HttpStreamFactoryImpl::Job>(
1486 delegate, job_type, session, request_info, priority, proxy_info, 1495 delegate, job_type, session, request_info, priority, proxy_info,
1487 server_ssl_config, proxy_ssl_config, destination, origin_url, 1496 server_ssl_config, proxy_ssl_config, destination, origin_url,
1488 alternative_service, ProxyServer(), enable_ip_based_pooling, net_log); 1497 alternative_service_info, ProxyServer(), enable_ip_based_pooling,
1498 net_log);
1489 } 1499 }
1490 1500
1491 std::unique_ptr<HttpStreamFactoryImpl::Job> 1501 std::unique_ptr<HttpStreamFactoryImpl::Job>
1492 HttpStreamFactoryImpl::JobFactory::CreateAltProxyJob( 1502 HttpStreamFactoryImpl::JobFactory::CreateAltProxyJob(
1493 HttpStreamFactoryImpl::Job::Delegate* delegate, 1503 HttpStreamFactoryImpl::Job::Delegate* delegate,
1494 HttpStreamFactoryImpl::JobType job_type, 1504 HttpStreamFactoryImpl::JobType job_type,
1495 HttpNetworkSession* session, 1505 HttpNetworkSession* session,
1496 const HttpRequestInfo& request_info, 1506 const HttpRequestInfo& request_info,
1497 RequestPriority priority, 1507 RequestPriority priority,
1498 const ProxyInfo& proxy_info, 1508 const ProxyInfo& proxy_info,
1499 const SSLConfig& server_ssl_config, 1509 const SSLConfig& server_ssl_config,
1500 const SSLConfig& proxy_ssl_config, 1510 const SSLConfig& proxy_ssl_config,
1501 HostPortPair destination, 1511 HostPortPair destination,
1502 GURL origin_url, 1512 GURL origin_url,
1503 const ProxyServer& alternative_proxy_server, 1513 const ProxyServer& alternative_proxy_server,
1504 bool enable_ip_based_pooling, 1514 bool enable_ip_based_pooling,
1505 NetLog* net_log) { 1515 NetLog* net_log) {
1506 return base::MakeUnique<HttpStreamFactoryImpl::Job>( 1516 return base::MakeUnique<HttpStreamFactoryImpl::Job>(
1507 delegate, job_type, session, request_info, priority, proxy_info, 1517 delegate, job_type, session, request_info, priority, proxy_info,
1508 server_ssl_config, proxy_ssl_config, destination, origin_url, 1518 server_ssl_config, proxy_ssl_config, destination, origin_url,
1509 AlternativeService(), alternative_proxy_server, enable_ip_based_pooling, 1519 AlternativeServiceInfo(), alternative_proxy_server,
1510 net_log); 1520 enable_ip_based_pooling, net_log);
1511 } 1521 }
1512 1522
1513 } // namespace net 1523 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_job.h ('k') | net/http/http_stream_factory_impl_job_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698