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

Side by Side Diff: net/proxy/proxy_script_fetcher_impl.cc

Issue 2265873002: Adjust callers and networking delegates in net/ to modified APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@URLRequestRead
Patch Set: rebased Created 4 years, 3 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/proxy/proxy_script_fetcher_impl.h" 5 #include "net/proxy/proxy_script_fetcher_impl.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 max_duration_ = timeout; 97 max_duration_ = timeout;
98 return prev; 98 return prev;
99 } 99 }
100 100
101 size_t ProxyScriptFetcherImpl::SetSizeConstraint(size_t size_bytes) { 101 size_t ProxyScriptFetcherImpl::SetSizeConstraint(size_t size_bytes) {
102 size_t prev = max_response_bytes_; 102 size_t prev = max_response_bytes_;
103 max_response_bytes_ = size_bytes; 103 max_response_bytes_ = size_bytes;
104 return prev; 104 return prev;
105 } 105 }
106 106
107 void ProxyScriptFetcherImpl::OnResponseCompleted(URLRequest* request) { 107 void ProxyScriptFetcherImpl::OnResponseCompleted(URLRequest* request,
108 int net_error) {
108 DCHECK_EQ(request, cur_request_.get()); 109 DCHECK_EQ(request, cur_request_.get());
109 110
110 // Use |result_code_| as the request's error if we have already set it to 111 // Use |result_code_| as the request's error if we have already set it to
111 // something specific. 112 // something specific.
112 if (result_code_ == OK && !request->status().is_success()) 113 if (result_code_ == OK && net_error != OK)
113 result_code_ = request->status().error(); 114 result_code_ = net_error;
114 115
115 FetchCompleted(); 116 FetchCompleted();
116 } 117 }
117 118
118 int ProxyScriptFetcherImpl::Fetch( 119 int ProxyScriptFetcherImpl::Fetch(
119 const GURL& url, base::string16* text, const CompletionCallback& callback) { 120 const GURL& url, base::string16* text, const CompletionCallback& callback) {
120 // It is invalid to call Fetch() while a request is already in progress. 121 // It is invalid to call Fetch() while a request is already in progress.
121 DCHECK(!cur_request_.get()); 122 DCHECK(!cur_request_.get());
122 DCHECK(!callback.is_null()); 123 DCHECK(!callback.is_null());
123 DCHECK(text); 124 DCHECK(text);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 if (IsCertStatusMinorError(ssl_info.cert_status)) { 200 if (IsCertStatusMinorError(ssl_info.cert_status)) {
200 request->ContinueDespiteLastError(); 201 request->ContinueDespiteLastError();
201 return; 202 return;
202 } 203 }
203 LOG(WARNING) << "SSL certificate error when fetching PAC script, aborting."; 204 LOG(WARNING) << "SSL certificate error when fetching PAC script, aborting.";
204 // Certificate errors are in same space as net errors. 205 // Certificate errors are in same space as net errors.
205 result_code_ = MapCertStatusToNetError(ssl_info.cert_status); 206 result_code_ = MapCertStatusToNetError(ssl_info.cert_status);
206 request->Cancel(); 207 request->Cancel();
207 } 208 }
208 209
209 void ProxyScriptFetcherImpl::OnResponseStarted(URLRequest* request) { 210 void ProxyScriptFetcherImpl::OnResponseStarted(URLRequest* request,
211 int net_error) {
210 DCHECK_EQ(request, cur_request_.get()); 212 DCHECK_EQ(request, cur_request_.get());
213 DCHECK_NE(ERR_IO_PENDING, net_error);
211 214
212 if (!request->status().is_success()) { 215 if (net_error != OK) {
213 OnResponseCompleted(request); 216 OnResponseCompleted(request, net_error);
214 return; 217 return;
215 } 218 }
216 219
217 // Require HTTP responses to have a success status code. 220 // Require HTTP responses to have a success status code.
218 if (request->url().SchemeIsHTTPOrHTTPS()) { 221 if (request->url().SchemeIsHTTPOrHTTPS()) {
219 // NOTE about status codes: We are like Firefox 3 in this respect. 222 // NOTE about status codes: We are like Firefox 3 in this respect.
220 // {IE 7, Safari 3, Opera 9.5} do not care about the status code. 223 // {IE 7, Safari 3, Opera 9.5} do not care about the status code.
221 if (request->GetResponseCode() != 200) { 224 if (request->GetResponseCode() != 200) {
222 VLOG(1) << "Fetched PAC script had (bad) status line: " 225 VLOG(1) << "Fetched PAC script had (bad) status line: "
223 << request->response_headers()->GetStatusLine(); 226 << request->response_headers()->GetStatusLine();
(...skipping 11 matching lines...) Expand all
235 VLOG(1) << "Fetched PAC script does not have a proper mime type: " 238 VLOG(1) << "Fetched PAC script does not have a proper mime type: "
236 << mime_type; 239 << mime_type;
237 } 240 }
238 } 241 }
239 242
240 ReadBody(request); 243 ReadBody(request);
241 } 244 }
242 245
243 void ProxyScriptFetcherImpl::OnReadCompleted(URLRequest* request, 246 void ProxyScriptFetcherImpl::OnReadCompleted(URLRequest* request,
244 int num_bytes) { 247 int num_bytes) {
248 DCHECK_NE(ERR_IO_PENDING, num_bytes);
249
245 DCHECK_EQ(request, cur_request_.get()); 250 DCHECK_EQ(request, cur_request_.get());
246 if (ConsumeBytesRead(request, num_bytes)) { 251 if (ConsumeBytesRead(request, num_bytes)) {
247 // Keep reading. 252 // Keep reading.
248 ReadBody(request); 253 ReadBody(request);
249 } 254 }
250 } 255 }
251 256
252 void ProxyScriptFetcherImpl::ReadBody(URLRequest* request) { 257 void ProxyScriptFetcherImpl::ReadBody(URLRequest* request) {
253 // Read as many bytes as are available synchronously. 258 // Read as many bytes as are available synchronously.
254 while (true) { 259 while (true) {
255 int num_bytes; 260 int num_bytes = request->Read(buf_.get(), kBufSize);
256 if (!request->Read(buf_.get(), kBufSize, &num_bytes)) { 261 if (num_bytes < 0) {
257 // Check whether the read failed synchronously. 262 // Check whether the read failed synchronously.
258 if (!request->status().is_io_pending()) 263 if (num_bytes != ERR_IO_PENDING)
259 OnResponseCompleted(request); 264 OnResponseCompleted(request, num_bytes);
260 return; 265 return;
261 } 266 }
mmenke 2016/08/30 22:13:22 Think this is clearer as: if (num_bytes == ERR_IO
maksims (do not use this acc) 2016/09/01 12:22:30 Done.
262 if (!ConsumeBytesRead(request, num_bytes)) 267 if (!ConsumeBytesRead(request, num_bytes))
263 return; 268 return;
264 } 269 }
265 } 270 }
266 271
267 bool ProxyScriptFetcherImpl::ConsumeBytesRead(URLRequest* request, 272 bool ProxyScriptFetcherImpl::ConsumeBytesRead(URLRequest* request,
268 int num_bytes) { 273 int num_bytes) {
269 if (num_bytes <= 0) { 274 if (num_bytes <= 0) {
270 // Error while reading, or EOF. 275 // Error while reading, or EOF.
271 OnResponseCompleted(request); 276 OnResponseCompleted(request, num_bytes);
272 return false; 277 return false;
273 } 278 }
274 279
275 // Enforce maximum size bound. 280 // Enforce maximum size bound.
276 if (num_bytes + bytes_read_so_far_.size() > 281 if (num_bytes + bytes_read_so_far_.size() >
277 static_cast<size_t>(max_response_bytes_)) { 282 static_cast<size_t>(max_response_bytes_)) {
278 result_code_ = ERR_FILE_TOO_BIG; 283 result_code_ = ERR_FILE_TOO_BIG;
279 request->Cancel(); 284 request->Cancel();
280 return false; 285 return false;
281 } 286 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 // is still applicable. 336 // is still applicable.
332 if (cur_request_id_ != id) 337 if (cur_request_id_ != id)
333 return; 338 return;
334 339
335 DCHECK(cur_request_.get()); 340 DCHECK(cur_request_.get());
336 result_code_ = ERR_TIMED_OUT; 341 result_code_ = ERR_TIMED_OUT;
337 cur_request_->Cancel(); 342 cur_request_->Cancel();
338 } 343 }
339 344
340 } // namespace net 345 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698