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

Side by Side Diff: chrome/browser/net/http_pipelining_compatibility_client.cc

Issue 9567025: Ensure pipelined requests are sent in the same order they're queued. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 9 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 "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"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 request_id, description); 78 request_id, description);
79 } 79 }
80 80
81 HttpPipeliningCompatibilityClient::Request::Request( 81 HttpPipeliningCompatibilityClient::Request::Request(
82 int request_id, 82 int request_id,
83 const std::string& base_url, 83 const std::string& base_url,
84 const RequestInfo& info, 84 const RequestInfo& info,
85 HttpPipeliningCompatibilityClient* client, 85 HttpPipeliningCompatibilityClient* client,
86 net::URLRequestContext* url_request_context) 86 net::URLRequestContext* url_request_context)
87 : request_id_(request_id), 87 : request_id_(request_id),
88 request_(GURL(base_url + info.filename), this), 88 request_(new net::URLRequest(GURL(base_url + info.filename), this)),
89 info_(info), 89 info_(info),
90 client_(client), 90 client_(client) {
91 finished_(false) { 91 request_->set_context(url_request_context);
92 request_.set_context(url_request_context); 92 request_->set_load_flags(net::LOAD_BYPASS_CACHE |
93 request_.set_load_flags(net::LOAD_BYPASS_CACHE | 93 net::LOAD_DISABLE_CACHE |
94 net::LOAD_DISABLE_CACHE | 94 net::LOAD_DO_NOT_SAVE_COOKIES |
95 net::LOAD_DO_NOT_SAVE_COOKIES | 95 net::LOAD_DO_NOT_SEND_COOKIES |
96 net::LOAD_DO_NOT_SEND_COOKIES | 96 net::LOAD_DO_NOT_PROMPT_FOR_LOGIN |
97 net::LOAD_DO_NOT_PROMPT_FOR_LOGIN | 97 net::LOAD_DO_NOT_SEND_AUTH_DATA);
98 net::LOAD_DO_NOT_SEND_AUTH_DATA); 98 request_->Start();
99 request_.Start();
100 } 99 }
101 100
102 HttpPipeliningCompatibilityClient::Request::~Request() { 101 HttpPipeliningCompatibilityClient::Request::~Request() {
103 } 102 }
104 103
105 void HttpPipeliningCompatibilityClient::Request::OnReceivedRedirect( 104 void HttpPipeliningCompatibilityClient::Request::OnReceivedRedirect(
106 net::URLRequest* request, 105 net::URLRequest* request,
107 const GURL& new_url, 106 const GURL& new_url,
108 bool* defer_redirect) { 107 bool* defer_redirect) {
109 *defer_redirect = true; 108 *defer_redirect = true;
110 request->Cancel(); 109 request->Cancel();
111 Finished(REDIRECTED); 110 Finished(REDIRECTED);
112 } 111 }
113 112
114 void HttpPipeliningCompatibilityClient::Request::OnSSLCertificateError( 113 void HttpPipeliningCompatibilityClient::Request::OnSSLCertificateError(
115 net::URLRequest* request, 114 net::URLRequest* request,
116 const net::SSLInfo& ssl_info, 115 const net::SSLInfo& ssl_info,
117 bool fatal) { 116 bool fatal) {
118 Finished(CERT_ERROR); 117 Finished(CERT_ERROR);
119 } 118 }
120 119
121 void HttpPipeliningCompatibilityClient::Request::OnResponseStarted( 120 void HttpPipeliningCompatibilityClient::Request::OnResponseStarted(
122 net::URLRequest* request) { 121 net::URLRequest* request) {
123 if (finished_) {
124 return;
125 }
126 int response_code = request->GetResponseCode(); 122 int response_code = request->GetResponseCode();
127 if (response_code > 0) { 123 if (response_code > 0) {
128 client_->ReportResponseCode(request_id_, response_code); 124 client_->ReportResponseCode(request_id_, response_code);
129 } 125 }
130 if (response_code == 200) { 126 if (response_code == 200) {
131 const net::HttpVersion required_version(1, 1); 127 const net::HttpVersion required_version(1, 1);
132 if (request->response_info().headers->GetParsedHttpVersion() < 128 if (request->response_info().headers->GetParsedHttpVersion() <
133 required_version) { 129 required_version) {
134 Finished(BAD_HTTP_VERSION); 130 Finished(BAD_HTTP_VERSION);
135 } else { 131 } else {
(...skipping 19 matching lines...) Expand all
155 } else if (response_.find(info_.expected_response) == 0) { 151 } else if (response_.find(info_.expected_response) == 0) {
156 Finished(TOO_LARGE); 152 Finished(TOO_LARGE);
157 } else { 153 } else {
158 Finished(CONTENT_MISMATCH); 154 Finished(CONTENT_MISMATCH);
159 } 155 }
160 } 156 }
161 } 157 }
162 158
163 void HttpPipeliningCompatibilityClient::Request::DoRead() { 159 void HttpPipeliningCompatibilityClient::Request::DoRead() {
164 int bytes_read = 0; 160 int bytes_read = 0;
165 if (request_.Read(read_buffer_.get(), info_.expected_response.length(), 161 if (request_->Read(read_buffer_.get(), info_.expected_response.length(),
166 &bytes_read)) { 162 &bytes_read)) {
167 OnReadCompleted(&request_, bytes_read); 163 OnReadCompleted(request_.get(), bytes_read);
168 } 164 }
169 } 165 }
170 166
171 void HttpPipeliningCompatibilityClient::Request::DoReadFinished() { 167 void HttpPipeliningCompatibilityClient::Request::DoReadFinished() {
172 if (response_.length() != info_.expected_response.length()) { 168 if (response_.length() != info_.expected_response.length()) {
173 if (info_.expected_response.find(response_) == 0) { 169 if (info_.expected_response.find(response_) == 0) {
174 Finished(TOO_SMALL); 170 Finished(TOO_SMALL);
175 } else { 171 } else {
176 Finished(CONTENT_MISMATCH); 172 Finished(CONTENT_MISMATCH);
177 } 173 }
178 } else if (response_ == info_.expected_response) { 174 } else if (response_ == info_.expected_response) {
179 Finished(SUCCESS); 175 Finished(SUCCESS);
180 } else { 176 } else {
181 Finished(CONTENT_MISMATCH); 177 Finished(CONTENT_MISMATCH);
182 } 178 }
183 } 179 }
184 180
185 void HttpPipeliningCompatibilityClient::Request::Finished(Status result) { 181 void HttpPipeliningCompatibilityClient::Request::Finished(Status result) {
186 if (finished_) { 182 const net::URLRequestStatus& status = request_->status();
187 return;
188 }
189 finished_ = true;
190 const net::URLRequestStatus& status = request_.status();
191 if (status.status() == net::URLRequestStatus::FAILED) { 183 if (status.status() == net::URLRequestStatus::FAILED) {
192 // Network errors trump all other status codes, because network errors can 184 // Network errors trump all other status codes, because network errors can
193 // be detected by the network stack even with real content. If we determine 185 // be detected by the network stack even with real content. If we determine
194 // that all pipelining errors can be detected by the network stack, then we 186 // that all pipelining errors can be detected by the network stack, then we
195 // don't need to worry about broken proxies. 187 // don't need to worry about broken proxies.
196 client_->ReportNetworkError(request_id_, status.error()); 188 client_->ReportNetworkError(request_id_, status.error());
197 client_->OnRequestFinished(request_id_, NETWORK_ERROR); 189 client_->OnRequestFinished(request_id_, NETWORK_ERROR);
198 return; 190 } else {
191 client_->OnRequestFinished(request_id_, result);
199 } 192 }
200 client_->OnRequestFinished(request_id_, result); 193 request_.reset();
201 } 194 }
202 195
203 } // namespace chrome_browser_net 196 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698