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

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

Issue 1216703002: Implement multiple alternative services per origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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) 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 const BoundNetLog& net_log) { 86 const BoundNetLog& net_log) {
87 Request* request = new Request(request_info.url, 87 Request* request = new Request(request_info.url,
88 this, 88 this,
89 delegate, 89 delegate,
90 websocket_handshake_stream_create_helper, 90 websocket_handshake_stream_create_helper,
91 net_log); 91 net_log);
92 Job* job = new Job(this, session_, request_info, priority, server_ssl_config, 92 Job* job = new Job(this, session_, request_info, priority, server_ssl_config,
93 proxy_ssl_config, net_log.net_log()); 93 proxy_ssl_config, net_log.net_log());
94 request->AttachJob(job); 94 request->AttachJob(job);
95 95
96 AlternativeService alternative_service = 96 const AlternativeServiceVector alternative_service_vector =
97 GetAlternativeServiceFor(request_info.url); 97 GetAlternativeServicesFor(request_info.url);
98 if (alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { 98 if (!alternative_service_vector.empty()) {
99 // TODO(bnc): Pass on multiple alternative services to Job.
100 const AlternativeService& alternative_service =
101 alternative_service_vector[0];
99 // Never share connection with other jobs for FTP requests. 102 // Never share connection with other jobs for FTP requests.
100 DCHECK(!request_info.url.SchemeIs("ftp")); 103 DCHECK(!request_info.url.SchemeIs("ftp"));
101 104
102 Job* alternative_job = 105 Job* alternative_job =
103 new Job(this, session_, request_info, priority, server_ssl_config, 106 new Job(this, session_, request_info, priority, server_ssl_config,
104 proxy_ssl_config, alternative_service, net_log.net_log()); 107 proxy_ssl_config, alternative_service, net_log.net_log());
105 request->AttachJob(alternative_job); 108 request->AttachJob(alternative_job);
106 109
107 job->WaitFor(alternative_job); 110 job->WaitFor(alternative_job);
108 // Make sure to wait until we call WaitFor(), before starting 111 // Make sure to wait until we call WaitFor(), before starting
109 // |alternative_job|, otherwise |alternative_job| will not notify |job| 112 // |alternative_job|, otherwise |alternative_job| will not notify |job|
110 // appropriately. 113 // appropriately.
111 alternative_job->Start(request); 114 alternative_job->Start(request);
112 } 115 }
113 116
114 // Even if |alternative_job| has already finished, it will not have notified 117 // Even if |alternative_job| has already finished, it will not have notified
115 // the request yet, since we defer that to the next iteration of the 118 // the request yet, since we defer that to the next iteration of the
116 // MessageLoop, so starting |job| is always safe. 119 // MessageLoop, so starting |job| is always safe.
117 job->Start(request); 120 job->Start(request);
118 return request; 121 return request;
119 } 122 }
120 123
121 void HttpStreamFactoryImpl::PreconnectStreams( 124 void HttpStreamFactoryImpl::PreconnectStreams(
122 int num_streams, 125 int num_streams,
123 const HttpRequestInfo& request_info, 126 const HttpRequestInfo& request_info,
124 RequestPriority priority, 127 RequestPriority priority,
125 const SSLConfig& server_ssl_config, 128 const SSLConfig& server_ssl_config,
126 const SSLConfig& proxy_ssl_config) { 129 const SSLConfig& proxy_ssl_config) {
127 DCHECK(!for_websockets_); 130 DCHECK(!for_websockets_);
128 AlternativeService alternative_service = 131 AlternativeServiceVector alternative_service_vector =
129 GetAlternativeServiceFor(request_info.url); 132 GetAlternativeServicesFor(request_info.url);
130 Job* job = 133 Job* job;
131 new Job(this, session_, request_info, priority, server_ssl_config, 134 if (alternative_service_vector.empty()) {
132 proxy_ssl_config, alternative_service, session_->net_log()); 135 job = new Job(this, session_, request_info, priority, server_ssl_config,
136 proxy_ssl_config, session_->net_log());
137 } else {
138 // TODO(bnc): Pass on multiple alternative services to Job.
139 const AlternativeService& alternative_service =
140 alternative_service_vector[0];
141 job = new Job(this, session_, request_info, priority, server_ssl_config,
142 proxy_ssl_config, alternative_service, session_->net_log());
143 }
Ryan Hamilton 2015/06/29 21:15:53 nit: instead of having an if with two bodies that
Bence 2015/06/30 19:16:14 Done.
133 preconnect_job_set_.insert(job); 144 preconnect_job_set_.insert(job);
134 job->Preconnect(num_streams); 145 job->Preconnect(num_streams);
135 } 146 }
136 147
137 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { 148 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const {
138 return session_->params().host_mapping_rules; 149 return session_->params().host_mapping_rules;
139 } 150 }
140 151
141 AlternativeService HttpStreamFactoryImpl::GetAlternativeServiceFor( 152 AlternativeServiceVector HttpStreamFactoryImpl::GetAlternativeServicesFor(
142 const GURL& original_url) { 153 const GURL& original_url) {
143 const AlternativeService kNoAlternativeService;
144
145 if (!session_->params().use_alternate_protocols) 154 if (!session_->params().use_alternate_protocols)
146 return kNoAlternativeService; 155 return AlternativeServiceVector();
147 156
148 if (original_url.SchemeIs("ftp")) 157 if (original_url.SchemeIs("ftp"))
149 return kNoAlternativeService; 158 return AlternativeServiceVector();
150 159
151 HostPortPair origin = HostPortPair::FromURL(original_url); 160 HostPortPair origin = HostPortPair::FromURL(original_url);
152 HttpServerProperties& http_server_properties = 161 HttpServerProperties& http_server_properties =
153 *session_->http_server_properties(); 162 *session_->http_server_properties();
154 const AlternativeService alternative_service = 163 const AlternativeServiceVector alternative_service_vector =
155 http_server_properties.GetAlternativeService(origin); 164 http_server_properties.GetAlternativeServices(origin);
165 if (alternative_service_vector.empty())
166 return AlternativeServiceVector();
156 167
157 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) 168 AlternativeServiceVector enabled_alternative_service_vector;
158 return kNoAlternativeService; 169 for (const AlternativeService& alternative_service :
159 if (http_server_properties.IsAlternativeServiceBroken(alternative_service)) { 170 alternative_service_vector) {
160 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN); 171 DCHECK(IsAlternateProtocolValid(alternative_service.protocol));
161 return kNoAlternativeService; 172 if (http_server_properties.IsAlternativeServiceBroken(
173 alternative_service)) {
174 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN);
175 continue;
176 }
177
178 // Some shared unix systems may have user home directories (like
179 // http://foo.com/~mike) which allow users to emit headers. This is a bad
180 // idea already, but with Alternate-Protocol, it provides the ability for a
181 // single user on a multi-user system to hijack the alternate protocol.
182 // These systems also enforce ports <1024 as restricted ports. So don't
183 // allow protocol upgrades to user-controllable ports.
184 const int kUnrestrictedPort = 1024;
185 if (!session_->params().enable_user_alternate_protocol_ports &&
186 (alternative_service.port >= kUnrestrictedPort &&
187 origin.port() < kUnrestrictedPort))
188 continue;
189
190 origin.set_port(alternative_service.port);
191 if (alternative_service.protocol >= NPN_SPDY_MINIMUM_VERSION &&
192 alternative_service.protocol <= NPN_SPDY_MAXIMUM_VERSION) {
193 if (!HttpStreamFactory::spdy_enabled())
194 continue;
195
196 if (session_->HasSpdyExclusion(origin))
197 continue;
198
199 enabled_alternative_service_vector.push_back(alternative_service);
200 continue;
201 }
202
203 DCHECK_EQ(QUIC, alternative_service.protocol);
204 if (!session_->params().enable_quic)
205 continue;
206
207 if (session_->quic_stream_factory()->IsQuicDisabled(origin.port()))
208 continue;
209
210 if (session_->params().disable_insecure_quic &&
211 !original_url.SchemeIs("https")) {
212 continue;
213 }
214
215 enabled_alternative_service_vector.push_back(alternative_service);
162 } 216 }
163 if (!IsAlternateProtocolValid(alternative_service.protocol)) { 217 return enabled_alternative_service_vector;
164 NOTREACHED();
165 return kNoAlternativeService;
166 }
167
168 // Some shared unix systems may have user home directories (like
169 // http://foo.com/~mike) which allow users to emit headers. This is a bad
170 // idea already, but with Alternate-Protocol, it provides the ability for a
171 // single user on a multi-user system to hijack the alternate protocol.
172 // These systems also enforce ports <1024 as restricted ports. So don't
173 // allow protocol upgrades to user-controllable ports.
174 const int kUnrestrictedPort = 1024;
175 if (!session_->params().enable_user_alternate_protocol_ports &&
176 (alternative_service.port >= kUnrestrictedPort &&
177 origin.port() < kUnrestrictedPort))
178 return kNoAlternativeService;
179
180 origin.set_port(alternative_service.port);
181 if (alternative_service.protocol >= NPN_SPDY_MINIMUM_VERSION &&
182 alternative_service.protocol <= NPN_SPDY_MAXIMUM_VERSION) {
183 if (!HttpStreamFactory::spdy_enabled())
184 return kNoAlternativeService;
185
186 if (session_->HasSpdyExclusion(origin))
187 return kNoAlternativeService;
188
189 return alternative_service;
190 }
191
192 DCHECK_EQ(QUIC, alternative_service.protocol);
193 if (!session_->params().enable_quic)
194 return kNoAlternativeService;
195
196 if (session_->quic_stream_factory()->IsQuicDisabled(origin.port()))
197 return kNoAlternativeService;
198
199 if (session_->params().disable_insecure_quic &&
200 !original_url.SchemeIs("https")) {
201 return kNoAlternativeService;
202 }
203
204 return alternative_service;
205 } 218 }
206 219
207 void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) { 220 void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) {
208 DCHECK(ContainsKey(request_map_, job)); 221 DCHECK(ContainsKey(request_map_, job));
209 DCHECK_EQ(request_map_[job], request); 222 DCHECK_EQ(request_map_[job], request);
210 DCHECK(!ContainsKey(orphaned_job_set_, job)); 223 DCHECK(!ContainsKey(orphaned_job_set_, job));
211 224
212 request_map_.erase(job); 225 request_map_.erase(job);
213 226
214 orphaned_job_set_.insert(job); 227 orphaned_job_set_.insert(job);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 delete job; 276 delete job;
264 } 277 }
265 278
266 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { 279 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) {
267 preconnect_job_set_.erase(job); 280 preconnect_job_set_.erase(job);
268 delete job; 281 delete job;
269 OnPreconnectsCompleteInternal(); 282 OnPreconnectsCompleteInternal();
270 } 283 }
271 284
272 } // namespace net 285 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698