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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "net/base/net_log.h" 12 #include "net/base/net_log.h"
13 #include "net/base/net_util.h" 13 #include "net/base/net_util.h"
14 #include "net/http/http_network_session.h" 14 #include "net/http/http_network_session.h"
15 #include "net/http/http_pipelined_connection.h" 15 #include "net/http/http_pipelined_connection.h"
16 #include "net/http/http_pipelined_host.h" 16 #include "net/http/http_pipelined_host.h"
17 #include "net/http/http_pipelined_stream.h" 17 #include "net/http/http_pipelined_stream.h"
18 #include "net/http/http_server_properties.h" 18 #include "net/http/http_server_properties.h"
19 #include "net/http/http_stream_factory_impl_job.h" 19 #include "net/http/http_stream_factory_impl_job.h"
20 #include "net/http/http_stream_factory_impl_request.h" 20 #include "net/http/http_stream_factory_impl_request.h"
21 #include "net/spdy/spdy_http_stream.h" 21 #include "net/spdy/spdy_http_stream.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 namespace net { 24 namespace net {
25 25
26 namespace { 26 namespace {
27 27
28 const PortAlternateProtocolPair kNoAlternateProtocol = { 28 const PortAlternateProtocolPair kNoAlternateProtocol = {
29 0, UNINITIALIZED_ALTERNATE_PROTOCOL 29 0, UNINITIALIZED_ALTERNATE_PROTOCOL};
30 };
31 30
32 GURL UpgradeUrlToHttps(const GURL& original_url, int port) { 31 GURL UpgradeUrlToHttps(const GURL& original_url, int port) {
33 GURL::Replacements replacements; 32 GURL::Replacements replacements;
34 // new_sheme and new_port need to be in scope here because GURL::Replacements 33 // new_sheme and new_port need to be in scope here because GURL::Replacements
35 // references the memory contained by them directly. 34 // references the memory contained by them directly.
36 const std::string new_scheme = "https"; 35 const std::string new_scheme = "https";
37 const std::string new_port = base::IntToString(port); 36 const std::string new_port = base::IntToString(port);
38 replacements.SetSchemeStr(new_scheme); 37 replacements.SetSchemeStr(new_scheme);
39 replacements.SetPortStr(new_port); 38 replacements.SetPortStr(new_port);
40 return original_url.ReplaceComponents(replacements); 39 return original_url.ReplaceComponents(replacements);
41 } 40 }
42 41
43 } // namespace 42 } // namespace
44 43
45 HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session, 44 HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session,
46 bool for_websockets) 45 bool for_websockets)
47 : session_(session), 46 : session_(session),
48 http_pipelined_host_pool_(this, NULL, 47 http_pipelined_host_pool_(this,
48 NULL,
49 session_->http_server_properties(), 49 session_->http_server_properties(),
50 session_->force_http_pipelining()), 50 session_->force_http_pipelining()),
51 for_websockets_(for_websockets) {} 51 for_websockets_(for_websockets) {
52 }
52 53
53 HttpStreamFactoryImpl::~HttpStreamFactoryImpl() { 54 HttpStreamFactoryImpl::~HttpStreamFactoryImpl() {
54 DCHECK(request_map_.empty()); 55 DCHECK(request_map_.empty());
55 DCHECK(spdy_session_request_map_.empty()); 56 DCHECK(spdy_session_request_map_.empty());
56 DCHECK(http_pipelining_request_map_.empty()); 57 DCHECK(http_pipelining_request_map_.empty());
57 58
58 std::set<const Job*> tmp_job_set; 59 std::set<const Job*> tmp_job_set;
59 tmp_job_set.swap(orphaned_job_set_); 60 tmp_job_set.swap(orphaned_job_set_);
60 STLDeleteContainerPointers(tmp_job_set.begin(), tmp_job_set.end()); 61 STLDeleteContainerPointers(tmp_job_set.begin(), tmp_job_set.end());
61 DCHECK(orphaned_job_set_.empty()); 62 DCHECK(orphaned_job_set_.empty());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 GURL alternate_url; 121 GURL alternate_url;
121 PortAlternateProtocolPair alternate = 122 PortAlternateProtocolPair alternate =
122 GetAlternateProtocolRequestFor(request_info.url, &alternate_url); 123 GetAlternateProtocolRequestFor(request_info.url, &alternate_url);
123 Job* alternate_job = NULL; 124 Job* alternate_job = NULL;
124 if (alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { 125 if (alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) {
125 // Never share connection with other jobs for FTP requests. 126 // Never share connection with other jobs for FTP requests.
126 DCHECK(!request_info.url.SchemeIs("ftp")); 127 DCHECK(!request_info.url.SchemeIs("ftp"));
127 128
128 HttpRequestInfo alternate_request_info = request_info; 129 HttpRequestInfo alternate_request_info = request_info;
129 alternate_request_info.url = alternate_url; 130 alternate_request_info.url = alternate_url;
130 alternate_job = 131 alternate_job = new Job(this,
131 new Job(this, session_, alternate_request_info, priority, 132 session_,
132 server_ssl_config, proxy_ssl_config, net_log.net_log()); 133 alternate_request_info,
134 priority,
135 server_ssl_config,
136 proxy_ssl_config,
137 net_log.net_log());
133 request->AttachJob(alternate_job); 138 request->AttachJob(alternate_job);
134 alternate_job->MarkAsAlternate(request_info.url, alternate); 139 alternate_job->MarkAsAlternate(request_info.url, alternate);
135 } 140 }
136 141
137 Job* job = new Job(this, session_, request_info, priority, 142 Job* job = new Job(this,
138 server_ssl_config, proxy_ssl_config, net_log.net_log()); 143 session_,
144 request_info,
145 priority,
146 server_ssl_config,
147 proxy_ssl_config,
148 net_log.net_log());
139 request->AttachJob(job); 149 request->AttachJob(job);
140 if (alternate_job) { 150 if (alternate_job) {
141 // Never share connection with other jobs for FTP requests. 151 // Never share connection with other jobs for FTP requests.
142 DCHECK(!request_info.url.SchemeIs("ftp")); 152 DCHECK(!request_info.url.SchemeIs("ftp"));
143 153
144 job->WaitFor(alternate_job); 154 job->WaitFor(alternate_job);
145 // Make sure to wait until we call WaitFor(), before starting 155 // Make sure to wait until we call WaitFor(), before starting
146 // |alternate_job|, otherwise |alternate_job| will not notify |job| 156 // |alternate_job|, otherwise |alternate_job| will not notify |job|
147 // appropriately. 157 // appropriately.
148 alternate_job->Start(request); 158 alternate_job->Start(request);
(...skipping 12 matching lines...) Expand all
161 const SSLConfig& server_ssl_config, 171 const SSLConfig& server_ssl_config,
162 const SSLConfig& proxy_ssl_config) { 172 const SSLConfig& proxy_ssl_config) {
163 DCHECK(!for_websockets_); 173 DCHECK(!for_websockets_);
164 GURL alternate_url; 174 GURL alternate_url;
165 PortAlternateProtocolPair alternate = 175 PortAlternateProtocolPair alternate =
166 GetAlternateProtocolRequestFor(request_info.url, &alternate_url); 176 GetAlternateProtocolRequestFor(request_info.url, &alternate_url);
167 Job* job = NULL; 177 Job* job = NULL;
168 if (alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { 178 if (alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) {
169 HttpRequestInfo alternate_request_info = request_info; 179 HttpRequestInfo alternate_request_info = request_info;
170 alternate_request_info.url = alternate_url; 180 alternate_request_info.url = alternate_url;
171 job = new Job(this, session_, alternate_request_info, priority, 181 job = new Job(this,
172 server_ssl_config, proxy_ssl_config, session_->net_log()); 182 session_,
183 alternate_request_info,
184 priority,
185 server_ssl_config,
186 proxy_ssl_config,
187 session_->net_log());
173 job->MarkAsAlternate(request_info.url, alternate); 188 job->MarkAsAlternate(request_info.url, alternate);
174 } else { 189 } else {
175 job = new Job(this, session_, request_info, priority, 190 job = new Job(this,
176 server_ssl_config, proxy_ssl_config, session_->net_log()); 191 session_,
192 request_info,
193 priority,
194 server_ssl_config,
195 proxy_ssl_config,
196 session_->net_log());
177 } 197 }
178 preconnect_job_set_.insert(job); 198 preconnect_job_set_.insert(job);
179 job->Preconnect(num_streams); 199 job->Preconnect(num_streams);
180 } 200 }
181 201
182 base::Value* HttpStreamFactoryImpl::PipelineInfoToValue() const { 202 base::Value* HttpStreamFactoryImpl::PipelineInfoToValue() const {
183 return http_pipelined_host_pool_.PipelineInfoToValue(); 203 return http_pipelined_host_pool_.PipelineInfoToValue();
184 } 204 }
185 205
186 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { 206 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 256
237 if (HttpStreamFactory::HasSpdyExclusion(origin)) 257 if (HttpStreamFactory::HasSpdyExclusion(origin))
238 return kNoAlternateProtocol; 258 return kNoAlternateProtocol;
239 259
240 *alternate_url = UpgradeUrlToHttps(original_url, alternate.port); 260 *alternate_url = UpgradeUrlToHttps(original_url, alternate.port);
241 } else { 261 } else {
242 DCHECK_EQ(QUIC, alternate.protocol); 262 DCHECK_EQ(QUIC, alternate.protocol);
243 if (!session_->params().enable_quic || 263 if (!session_->params().enable_quic ||
244 !(original_url.SchemeIs("http") || 264 !(original_url.SchemeIs("http") ||
245 session_->params().enable_quic_https)) { 265 session_->params().enable_quic_https)) {
246 return kNoAlternateProtocol; 266 return kNoAlternateProtocol;
247 } 267 }
248 // TODO(rch): Figure out how to make QUIC iteract with PAC 268 // TODO(rch): Figure out how to make QUIC iteract with PAC
249 // scripts. By not re-writing the URL, we will query the PAC script 269 // scripts. By not re-writing the URL, we will query the PAC script
250 // for the proxy to use to reach the original URL via TCP. But 270 // for the proxy to use to reach the original URL via TCP. But
251 // the alternate request will be going via UDP to a different port. 271 // the alternate request will be going via UDP to a different port.
252 *alternate_url = original_url; 272 *alternate_url = original_url;
253 } 273 }
254 return alternate; 274 return alternate;
255 } 275 }
256 276
(...skipping 24 matching lines...) Expand all
281 // Each iteration may empty out the RequestSet for |spdy_session_key| in 301 // Each iteration may empty out the RequestSet for |spdy_session_key| in
282 // |spdy_session_request_map_|. So each time, check for RequestSet and use 302 // |spdy_session_request_map_|. So each time, check for RequestSet and use
283 // the first one. 303 // the first one.
284 // 304 //
285 // TODO(willchan): If it's important, switch RequestSet out for a FIFO 305 // TODO(willchan): If it's important, switch RequestSet out for a FIFO
286 // queue (Order by priority first, then FIFO within same priority). Unclear 306 // queue (Order by priority first, then FIFO within same priority). Unclear
287 // that it matters here. 307 // that it matters here.
288 if (!ContainsKey(spdy_session_request_map_, spdy_session_key)) 308 if (!ContainsKey(spdy_session_request_map_, spdy_session_key))
289 break; 309 break;
290 Request* request = *spdy_session_request_map_[spdy_session_key].begin(); 310 Request* request = *spdy_session_request_map_[spdy_session_key].begin();
291 request->Complete(was_npn_negotiated, 311 request->Complete(
292 protocol_negotiated, 312 was_npn_negotiated, protocol_negotiated, using_spdy, net_log);
293 using_spdy,
294 net_log);
295 if (for_websockets_) { 313 if (for_websockets_) {
296 // TODO(ricea): Restore this code path when WebSocket over SPDY 314 // TODO(ricea): Restore this code path when WebSocket over SPDY
297 // implementation is ready. 315 // implementation is ready.
298 NOTREACHED(); 316 NOTREACHED();
299 } else { 317 } else {
300 bool use_relative_url = direct || request->url().SchemeIs("https"); 318 bool use_relative_url = direct || request->url().SchemeIs("https");
301 request->OnStreamReady( 319 request->OnStreamReady(
302 NULL, 320 NULL,
303 used_ssl_config, 321 used_ssl_config,
304 used_proxy_info, 322 used_proxy_info,
(...skipping 22 matching lines...) Expand all
327 host->GetKey()); 345 host->GetKey());
328 if (!stream) { 346 if (!stream) {
329 break; 347 break;
330 } 348 }
331 349
332 Request* request = *http_pipelining_request_map_[host->GetKey()].begin(); 350 Request* request = *http_pipelining_request_map_[host->GetKey()].begin();
333 request->Complete(stream->was_npn_negotiated(), 351 request->Complete(stream->was_npn_negotiated(),
334 stream->protocol_negotiated(), 352 stream->protocol_negotiated(),
335 false, // not using_spdy 353 false, // not using_spdy
336 stream->net_log()); 354 stream->net_log());
337 request->OnStreamReady(NULL, 355 request->OnStreamReady(
338 stream->used_ssl_config(), 356 NULL, stream->used_ssl_config(), stream->used_proxy_info(), stream);
339 stream->used_proxy_info(),
340 stream);
341 } 357 }
342 } 358 }
343 359
344 void HttpStreamFactoryImpl::AbortPipelinedRequestsWithKey( 360 void HttpStreamFactoryImpl::AbortPipelinedRequestsWithKey(
345 const Job* job, const HttpPipelinedHost::Key& key, int status, 361 const Job* job,
362 const HttpPipelinedHost::Key& key,
363 int status,
346 const SSLConfig& used_ssl_config) { 364 const SSLConfig& used_ssl_config) {
347 RequestVector requests_to_fail = http_pipelining_request_map_[key]; 365 RequestVector requests_to_fail = http_pipelining_request_map_[key];
348 for (RequestVector::const_iterator it = requests_to_fail.begin(); 366 for (RequestVector::const_iterator it = requests_to_fail.begin();
349 it != requests_to_fail.end(); ++it) { 367 it != requests_to_fail.end();
368 ++it) {
350 Request* request = *it; 369 Request* request = *it;
351 if (request == request_map_[job]) { 370 if (request == request_map_[job]) {
352 continue; 371 continue;
353 } 372 }
354 request->OnStreamFailed(NULL, status, used_ssl_config); 373 request->OnStreamFailed(NULL, status, used_ssl_config);
355 } 374 }
356 } 375 }
357 376
358 } // namespace net 377 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698