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 "chrome/browser/net/http_pipelining_compatibility_client.h" | 5 #include "chrome/browser/net/http_pipelining_compatibility_client.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "net/base/load_flags.h" | 9 #include "net/base/load_flags.h" |
10 #include "net/disk_cache/histogram_macros.h" | 10 #include "net/disk_cache/histogram_macros.h" |
| 11 #include "net/http/http_network_layer.h" |
| 12 #include "net/http/http_network_session.h" |
11 #include "net/http/http_response_headers.h" | 13 #include "net/http/http_response_headers.h" |
12 #include "net/http/http_version.h" | 14 #include "net/http/http_version.h" |
13 | 15 |
14 namespace chrome_browser_net { | 16 namespace chrome_browser_net { |
15 | 17 |
16 HttpPipeliningCompatibilityClient::HttpPipeliningCompatibilityClient() | 18 HttpPipeliningCompatibilityClient::HttpPipeliningCompatibilityClient() |
17 : num_finished_(0) { | 19 : num_finished_(0) { |
18 } | 20 } |
19 | 21 |
20 HttpPipeliningCompatibilityClient::~HttpPipeliningCompatibilityClient() { | 22 HttpPipeliningCompatibilityClient::~HttpPipeliningCompatibilityClient() { |
21 } | 23 } |
22 | 24 |
23 void HttpPipeliningCompatibilityClient::Start( | 25 void HttpPipeliningCompatibilityClient::Start( |
24 const std::string& base_url, | 26 const std::string& base_url, |
25 std::vector<RequestInfo>& requests, | 27 std::vector<RequestInfo>& requests, |
26 const net::CompletionCallback& callback, | 28 const net::CompletionCallback& callback, |
27 net::URLRequestContext* url_request_context) { | 29 net::URLRequestContext* url_request_context) { |
| 30 net::HttpNetworkSession* old_session = |
| 31 url_request_context->http_transaction_factory()->GetSession(); |
| 32 net::HttpNetworkSession::Params params = old_session->params(); |
| 33 params.force_http_pipelining = true; |
| 34 scoped_refptr<net::HttpNetworkSession> session = |
| 35 new net::HttpNetworkSession(params); |
| 36 http_transaction_factory_.reset( |
| 37 net::HttpNetworkLayer::CreateFactory(session.get())); |
| 38 |
| 39 url_request_context_ = new net::URLRequestContext; |
| 40 url_request_context_->CopyFrom(url_request_context); |
| 41 url_request_context_->set_http_transaction_factory( |
| 42 http_transaction_factory_.get()); |
| 43 |
28 finished_callback_ = callback; | 44 finished_callback_ = callback; |
29 for (size_t i = 0; i < requests.size(); ++i) { | 45 for (size_t i = 0; i < requests.size(); ++i) { |
30 requests_.push_back(new Request(i, base_url, requests[i], this, | 46 requests_.push_back(new Request(i, base_url, requests[i], this, |
31 url_request_context)); | 47 url_request_context_.get())); |
32 } | 48 } |
33 } | 49 } |
34 | 50 |
35 void HttpPipeliningCompatibilityClient::OnRequestFinished(int request_id, | 51 void HttpPipeliningCompatibilityClient::OnRequestFinished(int request_id, |
36 Status status) { | 52 Status status) { |
37 // The CACHE_HISTOGRAM_* macros are used, because they allow dynamic metric | 53 // The CACHE_HISTOGRAM_* macros are used, because they allow dynamic metric |
38 // names. | 54 // names. |
39 CACHE_HISTOGRAM_ENUMERATION(GetMetricName(request_id, "Status"), | 55 CACHE_HISTOGRAM_ENUMERATION(GetMetricName(request_id, "Status"), |
40 status, STATUS_MAX); | 56 status, STATUS_MAX); |
41 ++num_finished_; | 57 ++num_finished_; |
(...skipping 25 matching lines...) Expand all Loading... |
67 const std::string& base_url, | 83 const std::string& base_url, |
68 const RequestInfo& info, | 84 const RequestInfo& info, |
69 HttpPipeliningCompatibilityClient* client, | 85 HttpPipeliningCompatibilityClient* client, |
70 net::URLRequestContext* url_request_context) | 86 net::URLRequestContext* url_request_context) |
71 : request_id_(request_id), | 87 : request_id_(request_id), |
72 request_(GURL(base_url + info.filename), this), | 88 request_(GURL(base_url + info.filename), this), |
73 info_(info), | 89 info_(info), |
74 client_(client), | 90 client_(client), |
75 finished_(false) { | 91 finished_(false) { |
76 request_.set_context(url_request_context); | 92 request_.set_context(url_request_context); |
77 // TODO(simonjam): Force pipelining. | |
78 request_.set_load_flags(net::LOAD_BYPASS_CACHE | | 93 request_.set_load_flags(net::LOAD_BYPASS_CACHE | |
79 net::LOAD_DISABLE_CACHE | | 94 net::LOAD_DISABLE_CACHE | |
80 net::LOAD_DO_NOT_SAVE_COOKIES | | 95 net::LOAD_DO_NOT_SAVE_COOKIES | |
81 net::LOAD_DO_NOT_SEND_COOKIES | | 96 net::LOAD_DO_NOT_SEND_COOKIES | |
82 net::LOAD_DO_NOT_PROMPT_FOR_LOGIN | | 97 net::LOAD_DO_NOT_PROMPT_FOR_LOGIN | |
83 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 98 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
84 request_.Start(); | 99 request_.Start(); |
85 } | 100 } |
86 | 101 |
87 HttpPipeliningCompatibilityClient::Request::~Request() { | 102 HttpPipeliningCompatibilityClient::Request::~Request() { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 // that all pipelining errors can be detected by the network stack, then we | 194 // that all pipelining errors can be detected by the network stack, then we |
180 // don't need to worry about broken proxies. | 195 // don't need to worry about broken proxies. |
181 client_->ReportNetworkError(request_id_, status.error()); | 196 client_->ReportNetworkError(request_id_, status.error()); |
182 client_->OnRequestFinished(request_id_, NETWORK_ERROR); | 197 client_->OnRequestFinished(request_id_, NETWORK_ERROR); |
183 return; | 198 return; |
184 } | 199 } |
185 client_->OnRequestFinished(request_id_, result); | 200 client_->OnRequestFinished(request_id_, result); |
186 } | 201 } |
187 | 202 |
188 } // namespace chrome_browser_net | 203 } // namespace chrome_browser_net |
OLD | NEW |