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

Side by Side Diff: content/browser/appcache/appcache_url_request_job.cc

Issue 1459333002: Revert "Reland: URLRequestJob: change ReadRawData contract" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 "content/browser/appcache/appcache_url_request_job.h" 5 #include "content/browser/appcache/appcache_url_request_job.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 range_response_info_.reset( 334 range_response_info_.reset(
335 new net::HttpResponseInfo(*info_->http_response_info())); 335 new net::HttpResponseInfo(*info_->http_response_info()));
336 net::HttpResponseHeaders* headers = range_response_info_->headers.get(); 336 net::HttpResponseHeaders* headers = range_response_info_->headers.get();
337 headers->UpdateWithNewRange( 337 headers->UpdateWithNewRange(
338 range_requested_, resource_size, true /* replace status line */); 338 range_requested_, resource_size, true /* replace status line */);
339 } 339 }
340 340
341 void AppCacheURLRequestJob::OnReadComplete(int result) { 341 void AppCacheURLRequestJob::OnReadComplete(int result) {
342 DCHECK(is_delivering_appcache_response()); 342 DCHECK(is_delivering_appcache_response());
343 if (result == 0) { 343 if (result == 0) {
344 NotifyDone(net::URLRequestStatus());
344 AppCacheHistograms::CountResponseRetrieval( 345 AppCacheHistograms::CountResponseRetrieval(
345 true, is_main_resource_, manifest_url_.GetOrigin()); 346 true, is_main_resource_, manifest_url_.GetOrigin());
346 } else if (result < 0) { 347 } else if (result < 0) {
347 if (storage_->service()->storage() == storage_) { 348 if (storage_->service()->storage() == storage_) {
348 storage_->service()->CheckAppCacheResponse(manifest_url_, cache_id_, 349 storage_->service()->CheckAppCacheResponse(manifest_url_, cache_id_,
349 entry_.response_id()); 350 entry_.response_id());
350 } 351 }
352 NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, result));
351 AppCacheHistograms::CountResponseRetrieval( 353 AppCacheHistograms::CountResponseRetrieval(
352 false, is_main_resource_, manifest_url_.GetOrigin()); 354 false, is_main_resource_, manifest_url_.GetOrigin());
355 } else {
356 SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status
353 } 357 }
354 ReadRawDataComplete(result); 358 NotifyReadComplete(result);
355 } 359 }
356 360
357 // net::URLRequestJob overrides ------------------------------------------------ 361 // net::URLRequestJob overrides ------------------------------------------------
358 362
359 void AppCacheURLRequestJob::Start() { 363 void AppCacheURLRequestJob::Start() {
360 DCHECK(!has_been_started()); 364 DCHECK(!has_been_started());
361 has_been_started_ = true; 365 has_been_started_ = true;
362 start_time_tick_ = base::TimeTicks::Now(); 366 start_time_tick_ = base::TimeTicks::Now();
363 MaybeBeginDelivery(); 367 MaybeBeginDelivery();
364 } 368 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 return; 417 return;
414 *info = *http_info(); 418 *info = *http_info();
415 } 419 }
416 420
417 int AppCacheURLRequestJob::GetResponseCode() const { 421 int AppCacheURLRequestJob::GetResponseCode() const {
418 if (!http_info()) 422 if (!http_info())
419 return -1; 423 return -1;
420 return http_info()->headers->response_code(); 424 return http_info()->headers->response_code();
421 } 425 }
422 426
423 int AppCacheURLRequestJob::ReadRawData(net::IOBuffer* buf, int buf_size) { 427 bool AppCacheURLRequestJob::ReadRawData(net::IOBuffer* buf,
428 int buf_size,
429 int* bytes_read) {
424 DCHECK(is_delivering_appcache_response()); 430 DCHECK(is_delivering_appcache_response());
425 DCHECK_NE(buf_size, 0); 431 DCHECK_NE(buf_size, 0);
432 DCHECK(bytes_read);
426 DCHECK(!reader_->IsReadPending()); 433 DCHECK(!reader_->IsReadPending());
427 reader_->ReadData(buf, buf_size, 434 reader_->ReadData(buf, buf_size,
428 base::Bind(&AppCacheURLRequestJob::OnReadComplete, 435 base::Bind(&AppCacheURLRequestJob::OnReadComplete,
429 base::Unretained(this))); 436 base::Unretained(this)));
430 return net::ERR_IO_PENDING; 437 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0));
438 return false;
431 } 439 }
432 440
433 void AppCacheURLRequestJob::SetExtraRequestHeaders( 441 void AppCacheURLRequestJob::SetExtraRequestHeaders(
434 const net::HttpRequestHeaders& headers) { 442 const net::HttpRequestHeaders& headers) {
435 std::string value; 443 std::string value;
436 std::vector<net::HttpByteRange> ranges; 444 std::vector<net::HttpByteRange> ranges;
437 if (!headers.GetHeader(net::HttpRequestHeaders::kRange, &value) || 445 if (!headers.GetHeader(net::HttpRequestHeaders::kRange, &value) ||
438 !net::HttpUtil::ParseRangeHeader(value, &ranges)) { 446 !net::HttpUtil::ParseRangeHeader(value, &ranges)) {
439 return; 447 return;
440 } 448 }
441 449
442 // If multiple ranges are requested, we play dumb and 450 // If multiple ranges are requested, we play dumb and
443 // return the entire response with 200 OK. 451 // return the entire response with 200 OK.
444 if (ranges.size() == 1U) 452 if (ranges.size() == 1U)
445 range_requested_ = ranges[0]; 453 range_requested_ = ranges[0];
446 } 454 }
447 455
448 void AppCacheURLRequestJob::NotifyRestartRequired() { 456 void AppCacheURLRequestJob::NotifyRestartRequired() {
449 on_prepare_to_restart_callback_.Run(); 457 on_prepare_to_restart_callback_.Run();
450 URLRequestJob::NotifyRestartRequired(); 458 URLRequestJob::NotifyRestartRequired();
451 } 459 }
452 460
453 } // namespace content 461 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_url_request_job.h ('k') | content/browser/fileapi/file_writer_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698