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

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

Issue 1467603002: URLRequestJob: change ReadRawData contract (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add done_reading_called_ to MockNetworkTransaction Created 5 years 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());
345 AppCacheHistograms::CountResponseRetrieval( 344 AppCacheHistograms::CountResponseRetrieval(
346 true, is_main_resource_, manifest_url_.GetOrigin()); 345 true, is_main_resource_, manifest_url_.GetOrigin());
347 } else if (result < 0) { 346 } else if (result < 0) {
348 if (storage_->service()->storage() == storage_) { 347 if (storage_->service()->storage() == storage_) {
349 storage_->service()->CheckAppCacheResponse(manifest_url_, cache_id_, 348 storage_->service()->CheckAppCacheResponse(manifest_url_, cache_id_,
350 entry_.response_id()); 349 entry_.response_id());
351 } 350 }
352 NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, result));
353 AppCacheHistograms::CountResponseRetrieval( 351 AppCacheHistograms::CountResponseRetrieval(
354 false, is_main_resource_, manifest_url_.GetOrigin()); 352 false, is_main_resource_, manifest_url_.GetOrigin());
355 } else {
356 SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status
357 } 353 }
358 NotifyReadComplete(result); 354 ReadRawDataComplete(result);
359 } 355 }
360 356
361 // net::URLRequestJob overrides ------------------------------------------------ 357 // net::URLRequestJob overrides ------------------------------------------------
362 358
363 void AppCacheURLRequestJob::Start() { 359 void AppCacheURLRequestJob::Start() {
364 DCHECK(!has_been_started()); 360 DCHECK(!has_been_started());
365 has_been_started_ = true; 361 has_been_started_ = true;
366 start_time_tick_ = base::TimeTicks::Now(); 362 start_time_tick_ = base::TimeTicks::Now();
367 MaybeBeginDelivery(); 363 MaybeBeginDelivery();
368 } 364 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 return; 413 return;
418 *info = *http_info(); 414 *info = *http_info();
419 } 415 }
420 416
421 int AppCacheURLRequestJob::GetResponseCode() const { 417 int AppCacheURLRequestJob::GetResponseCode() const {
422 if (!http_info()) 418 if (!http_info())
423 return -1; 419 return -1;
424 return http_info()->headers->response_code(); 420 return http_info()->headers->response_code();
425 } 421 }
426 422
427 bool AppCacheURLRequestJob::ReadRawData(net::IOBuffer* buf, 423 int AppCacheURLRequestJob::ReadRawData(net::IOBuffer* buf, int buf_size) {
428 int buf_size,
429 int* bytes_read) {
430 DCHECK(is_delivering_appcache_response()); 424 DCHECK(is_delivering_appcache_response());
431 DCHECK_NE(buf_size, 0); 425 DCHECK_NE(buf_size, 0);
432 DCHECK(bytes_read);
433 DCHECK(!reader_->IsReadPending()); 426 DCHECK(!reader_->IsReadPending());
434 reader_->ReadData(buf, buf_size, 427 reader_->ReadData(buf, buf_size,
435 base::Bind(&AppCacheURLRequestJob::OnReadComplete, 428 base::Bind(&AppCacheURLRequestJob::OnReadComplete,
436 base::Unretained(this))); 429 base::Unretained(this)));
437 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); 430 return net::ERR_IO_PENDING;
438 return false;
439 } 431 }
440 432
441 void AppCacheURLRequestJob::SetExtraRequestHeaders( 433 void AppCacheURLRequestJob::SetExtraRequestHeaders(
442 const net::HttpRequestHeaders& headers) { 434 const net::HttpRequestHeaders& headers) {
443 std::string value; 435 std::string value;
444 std::vector<net::HttpByteRange> ranges; 436 std::vector<net::HttpByteRange> ranges;
445 if (!headers.GetHeader(net::HttpRequestHeaders::kRange, &value) || 437 if (!headers.GetHeader(net::HttpRequestHeaders::kRange, &value) ||
446 !net::HttpUtil::ParseRangeHeader(value, &ranges)) { 438 !net::HttpUtil::ParseRangeHeader(value, &ranges)) {
447 return; 439 return;
448 } 440 }
449 441
450 // If multiple ranges are requested, we play dumb and 442 // If multiple ranges are requested, we play dumb and
451 // return the entire response with 200 OK. 443 // return the entire response with 200 OK.
452 if (ranges.size() == 1U) 444 if (ranges.size() == 1U)
453 range_requested_ = ranges[0]; 445 range_requested_ = ranges[0];
454 } 446 }
455 447
456 void AppCacheURLRequestJob::NotifyRestartRequired() { 448 void AppCacheURLRequestJob::NotifyRestartRequired() {
457 on_prepare_to_restart_callback_.Run(); 449 on_prepare_to_restart_callback_.Run();
458 URLRequestJob::NotifyRestartRequired(); 450 URLRequestJob::NotifyRestartRequired();
459 } 451 }
460 452
461 } // namespace content 453 } // 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