OLD | NEW |
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" | |
16 #include "net/http/http_pipelined_host.h" | |
17 #include "net/http/http_pipelined_stream.h" | |
18 #include "net/http/http_server_properties.h" | 15 #include "net/http/http_server_properties.h" |
19 #include "net/http/http_stream_factory_impl_job.h" | 16 #include "net/http/http_stream_factory_impl_job.h" |
20 #include "net/http/http_stream_factory_impl_request.h" | 17 #include "net/http/http_stream_factory_impl_request.h" |
21 #include "net/spdy/spdy_http_stream.h" | 18 #include "net/spdy/spdy_http_stream.h" |
22 #include "url/gurl.h" | 19 #include "url/gurl.h" |
23 | 20 |
24 namespace net { | 21 namespace net { |
25 | 22 |
26 namespace { | 23 namespace { |
27 | 24 |
(...skipping 10 matching lines...) Expand all Loading... |
38 replacements.SetSchemeStr(new_scheme); | 35 replacements.SetSchemeStr(new_scheme); |
39 replacements.SetPortStr(new_port); | 36 replacements.SetPortStr(new_port); |
40 return original_url.ReplaceComponents(replacements); | 37 return original_url.ReplaceComponents(replacements); |
41 } | 38 } |
42 | 39 |
43 } // namespace | 40 } // namespace |
44 | 41 |
45 HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session, | 42 HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session, |
46 bool for_websockets) | 43 bool for_websockets) |
47 : session_(session), | 44 : session_(session), |
48 http_pipelined_host_pool_(this, NULL, | |
49 session_->http_server_properties(), | |
50 session_->force_http_pipelining()), | |
51 for_websockets_(for_websockets) {} | 45 for_websockets_(for_websockets) {} |
52 | 46 |
53 HttpStreamFactoryImpl::~HttpStreamFactoryImpl() { | 47 HttpStreamFactoryImpl::~HttpStreamFactoryImpl() { |
54 DCHECK(request_map_.empty()); | 48 DCHECK(request_map_.empty()); |
55 DCHECK(spdy_session_request_map_.empty()); | 49 DCHECK(spdy_session_request_map_.empty()); |
56 DCHECK(http_pipelining_request_map_.empty()); | |
57 | 50 |
58 std::set<const Job*> tmp_job_set; | 51 std::set<const Job*> tmp_job_set; |
59 tmp_job_set.swap(orphaned_job_set_); | 52 tmp_job_set.swap(orphaned_job_set_); |
60 STLDeleteContainerPointers(tmp_job_set.begin(), tmp_job_set.end()); | 53 STLDeleteContainerPointers(tmp_job_set.begin(), tmp_job_set.end()); |
61 DCHECK(orphaned_job_set_.empty()); | 54 DCHECK(orphaned_job_set_.empty()); |
62 | 55 |
63 tmp_job_set.clear(); | 56 tmp_job_set.clear(); |
64 tmp_job_set.swap(preconnect_job_set_); | 57 tmp_job_set.swap(preconnect_job_set_); |
65 STLDeleteContainerPointers(tmp_job_set.begin(), tmp_job_set.end()); | 58 STLDeleteContainerPointers(tmp_job_set.begin(), tmp_job_set.end()); |
66 DCHECK(preconnect_job_set_.empty()); | 59 DCHECK(preconnect_job_set_.empty()); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 server_ssl_config, proxy_ssl_config, session_->net_log()); | 165 server_ssl_config, proxy_ssl_config, session_->net_log()); |
173 job->MarkAsAlternate(request_info.url, alternate); | 166 job->MarkAsAlternate(request_info.url, alternate); |
174 } else { | 167 } else { |
175 job = new Job(this, session_, request_info, priority, | 168 job = new Job(this, session_, request_info, priority, |
176 server_ssl_config, proxy_ssl_config, session_->net_log()); | 169 server_ssl_config, proxy_ssl_config, session_->net_log()); |
177 } | 170 } |
178 preconnect_job_set_.insert(job); | 171 preconnect_job_set_.insert(job); |
179 job->Preconnect(num_streams); | 172 job->Preconnect(num_streams); |
180 } | 173 } |
181 | 174 |
182 base::Value* HttpStreamFactoryImpl::PipelineInfoToValue() const { | |
183 return http_pipelined_host_pool_.PipelineInfoToValue(); | |
184 } | |
185 | |
186 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { | 175 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { |
187 return session_->params().host_mapping_rules; | 176 return session_->params().host_mapping_rules; |
188 } | 177 } |
189 | 178 |
190 PortAlternateProtocolPair HttpStreamFactoryImpl::GetAlternateProtocolRequestFor( | 179 PortAlternateProtocolPair HttpStreamFactoryImpl::GetAlternateProtocolRequestFor( |
191 const GURL& original_url, | 180 const GURL& original_url, |
192 GURL* alternate_url) { | 181 GURL* alternate_url) { |
193 if (!use_alternate_protocols()) | 182 if (!use_alternate_protocols()) |
194 return kNoAlternateProtocol; | 183 return kNoAlternateProtocol; |
195 | 184 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 orphaned_job_set_.erase(job); | 301 orphaned_job_set_.erase(job); |
313 delete job; | 302 delete job; |
314 } | 303 } |
315 | 304 |
316 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { | 305 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { |
317 preconnect_job_set_.erase(job); | 306 preconnect_job_set_.erase(job); |
318 delete job; | 307 delete job; |
319 OnPreconnectsCompleteInternal(); | 308 OnPreconnectsCompleteInternal(); |
320 } | 309 } |
321 | 310 |
322 void HttpStreamFactoryImpl::OnHttpPipelinedHostHasAdditionalCapacity( | |
323 HttpPipelinedHost* host) { | |
324 while (ContainsKey(http_pipelining_request_map_, host->GetKey())) { | |
325 HttpPipelinedStream* stream = | |
326 http_pipelined_host_pool_.CreateStreamOnExistingPipeline( | |
327 host->GetKey()); | |
328 if (!stream) { | |
329 break; | |
330 } | |
331 | |
332 Request* request = *http_pipelining_request_map_[host->GetKey()].begin(); | |
333 request->Complete(stream->was_npn_negotiated(), | |
334 stream->protocol_negotiated(), | |
335 false, // not using_spdy | |
336 stream->net_log()); | |
337 request->OnStreamReady(NULL, | |
338 stream->used_ssl_config(), | |
339 stream->used_proxy_info(), | |
340 stream); | |
341 } | |
342 } | |
343 | |
344 void HttpStreamFactoryImpl::AbortPipelinedRequestsWithKey( | |
345 const Job* job, const HttpPipelinedHost::Key& key, int status, | |
346 const SSLConfig& used_ssl_config) { | |
347 RequestVector requests_to_fail = http_pipelining_request_map_[key]; | |
348 for (RequestVector::const_iterator it = requests_to_fail.begin(); | |
349 it != requests_to_fail.end(); ++it) { | |
350 Request* request = *it; | |
351 if (request == request_map_[job]) { | |
352 continue; | |
353 } | |
354 request->OnStreamFailed(NULL, status, used_ssl_config); | |
355 } | |
356 } | |
357 | |
358 } // namespace net | 311 } // namespace net |
OLD | NEW |