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

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

Issue 1540463003: Change the interface of GetAlternativeServicesFor, always return the best Alt-Svc entry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chang init of server, original_url from DoStart to Cxtor Created 5 years 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.h" 5 #include "net/http/http_stream_factory_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 const SSLConfig& proxy_ssl_config, 83 const SSLConfig& proxy_ssl_config,
84 HttpStreamRequest::Delegate* delegate, 84 HttpStreamRequest::Delegate* delegate,
85 WebSocketHandshakeStreamBase::CreateHelper* 85 WebSocketHandshakeStreamBase::CreateHelper*
86 websocket_handshake_stream_create_helper, 86 websocket_handshake_stream_create_helper,
87 const BoundNetLog& net_log) { 87 const BoundNetLog& net_log) {
88 Request* request = new Request(request_info.url, 88 Request* request = new Request(request_info.url,
89 this, 89 this,
90 delegate, 90 delegate,
91 websocket_handshake_stream_create_helper, 91 websocket_handshake_stream_create_helper,
92 net_log); 92 net_log);
93 HostPortPair server = HostPortPair::FromURL(request_info.url);
94 GURL original_url = ApplyHostMappingRules(request_info.url, &server);
Ryan Hamilton 2015/12/18 22:56:29 nit: origin_url not original_url
Zhongyi Shi 2015/12/19 01:23:02 Done.
95
93 Job* job = new Job(this, session_, request_info, priority, server_ssl_config, 96 Job* job = new Job(this, session_, request_info, priority, server_ssl_config,
94 proxy_ssl_config, net_log.net_log()); 97 proxy_ssl_config, server, original_url, net_log.net_log());
95 request->AttachJob(job); 98 request->AttachJob(job);
96 99
97 const AlternativeServiceVector alternative_service_vector = 100 const AlternativeService alternative_service =
98 GetAlternativeServicesFor(request_info.url, delegate); 101 GetAlternativeServiceFor(request_info, delegate);
99 102
100 if (!alternative_service_vector.empty()) { 103 if (alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) {
101 // TODO(bnc): Pass on multiple alternative services to Job.
102 const AlternativeService& alternative_service =
103 alternative_service_vector[0];
104 // Never share connection with other jobs for FTP requests. 104 // Never share connection with other jobs for FTP requests.
105 DCHECK(!request_info.url.SchemeIs("ftp")); 105 DCHECK(!request_info.url.SchemeIs("ftp"));
106 HostPortPair server = alternative_service.host_port_pair();
107 GURL original_url = ApplyHostMappingRules(request_info.url, &server);
106 108
107 Job* alternative_job = 109 Job* alternative_job =
108 new Job(this, session_, request_info, priority, server_ssl_config, 110 new Job(this, session_, request_info, priority, server_ssl_config,
109 proxy_ssl_config, alternative_service, net_log.net_log()); 111 proxy_ssl_config, server, original_url, alternative_service,
112 net_log.net_log());
110 request->AttachJob(alternative_job); 113 request->AttachJob(alternative_job);
111 114
112 job->WaitFor(alternative_job); 115 job->WaitFor(alternative_job);
113 // Make sure to wait until we call WaitFor(), before starting 116 // Make sure to wait until we call WaitFor(), before starting
114 // |alternative_job|, otherwise |alternative_job| will not notify |job| 117 // |alternative_job|, otherwise |alternative_job| will not notify |job|
115 // appropriately. 118 // appropriately.
116 alternative_job->Start(request); 119 alternative_job->Start(request);
117 } 120 }
118 121
119 // Even if |alternative_job| has already finished, it will not have notified 122 // Even if |alternative_job| has already finished, it will not have notified
120 // the request yet, since we defer that to the next iteration of the 123 // the request yet, since we defer that to the next iteration of the
121 // MessageLoop, so starting |job| is always safe. 124 // MessageLoop, so starting |job| is always safe.
122 job->Start(request); 125 job->Start(request);
123 return request; 126 return request;
124 } 127 }
125 128
126 void HttpStreamFactoryImpl::PreconnectStreams( 129 void HttpStreamFactoryImpl::PreconnectStreams(
127 int num_streams, 130 int num_streams,
128 const HttpRequestInfo& request_info, 131 const HttpRequestInfo& request_info,
129 const SSLConfig& server_ssl_config, 132 const SSLConfig& server_ssl_config,
130 const SSLConfig& proxy_ssl_config) { 133 const SSLConfig& proxy_ssl_config) {
131 DCHECK(!for_websockets_); 134 DCHECK(!for_websockets_);
132 AlternativeService alternative_service; 135 AlternativeService alternative_service =
133 AlternativeServiceVector alternative_service_vector = 136 GetAlternativeServiceFor(request_info, nullptr);
134 GetAlternativeServicesFor(request_info.url, nullptr); 137 if (alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) {
135 if (!alternative_service_vector.empty()) {
136 // TODO(bnc): Pass on multiple alternative services to Job.
137 alternative_service = alternative_service_vector[0];
138 if (session_->params().quic_disable_preconnect_if_0rtt && 138 if (session_->params().quic_disable_preconnect_if_0rtt &&
139 alternative_service.protocol == QUIC && 139 alternative_service.protocol == QUIC &&
140 session_->quic_stream_factory()->ZeroRTTEnabledFor(QuicServerId( 140 session_->quic_stream_factory()->ZeroRTTEnabledFor(QuicServerId(
141 alternative_service.host_port_pair(), request_info.privacy_mode))) { 141 alternative_service.host_port_pair(), request_info.privacy_mode))) {
142 return; 142 return;
143 } 143 }
144 } 144 }
145 145
146 // Due to how the socket pools handle priorities and idle sockets, only IDLE 146 // Due to how the socket pools handle priorities and idle sockets, only IDLE
147 // priority currently makes sense for preconnects. The priority for 147 // priority currently makes sense for preconnects. The priority for
148 // preconnects is currently ignored (see RequestSocketsForPool()), but could 148 // preconnects is currently ignored (see RequestSocketsForPool()), but could
149 // be used at some point for proxy resolution or something. 149 // be used at some point for proxy resolution or something.
150 Job* job = 150 HostPortPair server = alternative_service.host_port_pair();
151 new Job(this, session_, request_info, IDLE, server_ssl_config, 151 GURL original_url = ApplyHostMappingRules(request_info.url, &server);
152 proxy_ssl_config, alternative_service, session_->net_log()); 152 Job* job = new Job(this, session_, request_info, IDLE, server_ssl_config,
153 proxy_ssl_config, server, original_url,
154 alternative_service, session_->net_log());
153 preconnect_job_set_.insert(job); 155 preconnect_job_set_.insert(job);
154 job->Preconnect(num_streams); 156 job->Preconnect(num_streams);
155 } 157 }
156 158
157 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { 159 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const {
158 return session_->params().host_mapping_rules; 160 return session_->params().host_mapping_rules;
159 } 161 }
160 162
161 AlternativeServiceVector HttpStreamFactoryImpl::GetAlternativeServicesFor( 163 AlternativeService HttpStreamFactoryImpl::GetAlternativeServiceFor(
162 const GURL& original_url, 164 const HttpRequestInfo& request_info,
163 HttpStreamRequest::Delegate* delegate) { 165 HttpStreamRequest::Delegate* delegate) {
166 GURL original_url = request_info.url;
167
164 if (original_url.SchemeIs("ftp")) 168 if (original_url.SchemeIs("ftp"))
165 return AlternativeServiceVector(); 169 return AlternativeService();
166 170
167 HostPortPair origin = HostPortPair::FromURL(original_url); 171 HostPortPair origin = HostPortPair::FromURL(original_url);
168 HttpServerProperties& http_server_properties = 172 HttpServerProperties& http_server_properties =
169 *session_->http_server_properties(); 173 *session_->http_server_properties();
170 const AlternativeServiceVector alternative_service_vector = 174 const AlternativeServiceVector alternative_service_vector =
171 http_server_properties.GetAlternativeServices(origin); 175 http_server_properties.GetAlternativeServices(origin);
172 if (alternative_service_vector.empty()) 176 if (alternative_service_vector.empty())
173 return AlternativeServiceVector(); 177 return AlternativeService();
174 178
175 bool quic_advertised = false; 179 bool quic_advertised = false;
176 bool quic_all_broken = true; 180 bool quic_all_broken = true;
177 181
178 const bool enable_different_host = 182 const bool enable_different_host =
179 session_->params().use_alternative_services; 183 session_->params().use_alternative_services;
180 184
181 AlternativeServiceVector enabled_alternative_service_vector; 185 // First Alt-Svc that is not marked as broken.
186 AlternativeService candidate_alternative_service;
187
182 for (const AlternativeService& alternative_service : 188 for (const AlternativeService& alternative_service :
183 alternative_service_vector) { 189 alternative_service_vector) {
184 DCHECK(IsAlternateProtocolValid(alternative_service.protocol)); 190 DCHECK(IsAlternateProtocolValid(alternative_service.protocol));
185 if (!quic_advertised && alternative_service.protocol == QUIC) 191 if (!quic_advertised && alternative_service.protocol == QUIC)
186 quic_advertised = true; 192 quic_advertised = true;
187 if (http_server_properties.IsAlternativeServiceBroken( 193 if (http_server_properties.IsAlternativeServiceBroken(
188 alternative_service)) { 194 alternative_service)) {
189 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); 195 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN);
190 continue; 196 continue;
191 } 197 }
(...skipping 15 matching lines...) Expand all
207 213
208 origin.set_port(alternative_service.port); 214 origin.set_port(alternative_service.port);
209 if (alternative_service.protocol >= NPN_SPDY_MINIMUM_VERSION && 215 if (alternative_service.protocol >= NPN_SPDY_MINIMUM_VERSION &&
210 alternative_service.protocol <= NPN_SPDY_MAXIMUM_VERSION) { 216 alternative_service.protocol <= NPN_SPDY_MAXIMUM_VERSION) {
211 if (!HttpStreamFactory::spdy_enabled()) 217 if (!HttpStreamFactory::spdy_enabled())
212 continue; 218 continue;
213 219
214 if (session_->HasSpdyExclusion(origin)) 220 if (session_->HasSpdyExclusion(origin))
215 continue; 221 continue;
216 222
217 enabled_alternative_service_vector.push_back(alternative_service); 223 // Cache the first entry.
224 if (candidate_alternative_service.protocol ==
225 UNINITIALIZED_ALTERNATE_PROTOCOL)
226 candidate_alternative_service = alternative_service;
218 continue; 227 continue;
219 } 228 }
220 229
221 DCHECK_EQ(QUIC, alternative_service.protocol); 230 DCHECK_EQ(QUIC, alternative_service.protocol);
222 quic_all_broken = false; 231 quic_all_broken = false;
223 if (!session_->params().enable_quic) 232 if (!session_->params().enable_quic)
224 continue; 233 continue;
225 234
226 if (session_->quic_stream_factory()->IsQuicDisabled(origin.port())) 235 if (session_->quic_stream_factory()->IsQuicDisabled(origin.port()))
227 continue; 236 continue;
228 237
229 if (!original_url.SchemeIs("https")) 238 if (!original_url.SchemeIs("https"))
230 continue; 239 continue;
231 240
232 enabled_alternative_service_vector.push_back(alternative_service); 241 // Check whether there's an active session to pool for this QUIC Alt-Svc.
242 HostPortPair destination = alternative_service.host_port_pair();
243 StringPiece origin_host =
244 ApplyHostMappingRules(request_info.url, &destination).host();
245 QuicServerId server_id(destination, request_info.privacy_mode);
246 if (session_->quic_stream_factory()->CanPool(
247 server_id, request_info.privacy_mode, origin_host))
248 return alternative_service;
249
250 // Cache this entry if the first non-broken Alt-Svc is not there yet.
251 if (candidate_alternative_service.protocol ==
252 UNINITIALIZED_ALTERNATE_PROTOCOL)
253 candidate_alternative_service = alternative_service;
233 } 254 }
255
256 // Ask delegate to mark QUIC as broken for the origin.
234 if (quic_advertised && quic_all_broken && delegate != nullptr) 257 if (quic_advertised && quic_all_broken && delegate != nullptr)
235 delegate->OnQuicBroken(); 258 delegate->OnQuicBroken();
236 return enabled_alternative_service_vector; 259
260 return candidate_alternative_service;
237 } 261 }
238 262
239 void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) { 263 void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) {
240 DCHECK(ContainsKey(request_map_, job)); 264 DCHECK(ContainsKey(request_map_, job));
241 DCHECK_EQ(request_map_[job], request); 265 DCHECK_EQ(request_map_[job], request);
242 DCHECK(!ContainsKey(orphaned_job_set_, job)); 266 DCHECK(!ContainsKey(orphaned_job_set_, job));
243 267
244 request_map_.erase(job); 268 request_map_.erase(job);
245 269
246 orphaned_job_set_.insert(job); 270 orphaned_job_set_.insert(job);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 delete job; 316 delete job;
293 } 317 }
294 318
295 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { 319 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) {
296 preconnect_job_set_.erase(job); 320 preconnect_job_set_.erase(job);
297 delete job; 321 delete job;
298 OnPreconnectsCompleteInternal(); 322 OnPreconnectsCompleteInternal();
299 } 323 }
300 324
301 } // namespace net 325 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698