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

Side by Side Diff: storage/browser/blob/blob_url_request_job.cc

Issue 1108083002: Create blobs from Disk Cache entries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lose two more const Created 5 years, 6 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 "storage/browser/blob/blob_url_request_job.h" 5 #include "storage/browser/blob/blob_url_request_job.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/files/file_util_proxy.h" 15 #include "base/files/file_util_proxy.h"
16 #include "base/format_macros.h" 16 #include "base/format_macros.h"
17 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "base/numerics/safe_conversions.h" 18 #include "base/numerics/safe_conversions.h"
19 #include "base/stl_util.h" 19 #include "base/stl_util.h"
20 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
22 #include "base/trace_event/trace_event.h" 22 #include "base/trace_event/trace_event.h"
23 #include "net/base/io_buffer.h" 23 #include "net/base/io_buffer.h"
24 #include "net/base/net_errors.h" 24 #include "net/base/net_errors.h"
25 #include "net/disk_cache/disk_cache.h"
25 #include "net/http/http_request_headers.h" 26 #include "net/http/http_request_headers.h"
26 #include "net/http/http_response_headers.h" 27 #include "net/http/http_response_headers.h"
27 #include "net/http/http_response_info.h" 28 #include "net/http/http_response_info.h"
28 #include "net/http/http_util.h" 29 #include "net/http/http_util.h"
29 #include "net/url_request/url_request.h" 30 #include "net/url_request/url_request.h"
30 #include "net/url_request/url_request_context.h" 31 #include "net/url_request/url_request_context.h"
31 #include "net/url_request/url_request_error_job.h" 32 #include "net/url_request/url_request_error_job.h"
32 #include "net/url_request/url_request_status.h" 33 #include "net/url_request/url_request_status.h"
33 #include "storage/browser/fileapi/file_stream_reader.h" 34 #include "storage/browser/fileapi/file_stream_reader.h"
34 #include "storage/browser/fileapi/file_system_context.h" 35 #include "storage/browser/fileapi/file_system_context.h"
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 // If nothing to read for current item, advance to next item. 350 // If nothing to read for current item, advance to next item.
350 if (bytes_to_read == 0) { 351 if (bytes_to_read == 0) {
351 AdvanceItem(); 352 AdvanceItem();
352 return true; 353 return true;
353 } 354 }
354 355
355 // Do the reading. 356 // Do the reading.
356 const BlobDataItem& item = *items.at(current_item_index_); 357 const BlobDataItem& item = *items.at(current_item_index_);
357 if (item.type() == DataElement::TYPE_BYTES) 358 if (item.type() == DataElement::TYPE_BYTES)
358 return ReadBytesItem(item, bytes_to_read); 359 return ReadBytesItem(item, bytes_to_read);
360 if (item.type() == DataElement::TYPE_DISK_CACHE_ENTRY)
361 return ReadDiskCacheEntryItem(item, bytes_to_read);
359 if (!IsFileType(item.type())) { 362 if (!IsFileType(item.type())) {
360 NOTREACHED(); 363 NOTREACHED();
361 return false; 364 return false;
362 } 365 }
363 storage::FileStreamReader* const reader = 366 storage::FileStreamReader* const reader =
364 GetFileStreamReader(current_item_index_); 367 GetFileStreamReader(current_item_index_);
365 if (!reader) { 368 if (!reader) {
366 NotifyFailure(net::ERR_FAILED); 369 NotifyFailure(net::ERR_FAILED);
367 return false; 370 return false;
368 } 371 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 bool BlobURLRequestJob::ReadFileItem(FileStreamReader* reader, 416 bool BlobURLRequestJob::ReadFileItem(FileStreamReader* reader,
414 int bytes_to_read) { 417 int bytes_to_read) {
415 DCHECK_GE(read_buf_->BytesRemaining(), bytes_to_read); 418 DCHECK_GE(read_buf_->BytesRemaining(), bytes_to_read);
416 DCHECK(reader); 419 DCHECK(reader);
417 int chunk_number = current_file_chunk_number_++; 420 int chunk_number = current_file_chunk_number_++;
418 TRACE_EVENT_ASYNC_BEGIN1("Blob", "BlobRequest::ReadFileItem", this, "uuid", 421 TRACE_EVENT_ASYNC_BEGIN1("Blob", "BlobRequest::ReadFileItem", this, "uuid",
419 blob_data_->uuid()); 422 blob_data_->uuid());
420 const int result = 423 const int result =
421 reader->Read(read_buf_.get(), bytes_to_read, 424 reader->Read(read_buf_.get(), bytes_to_read,
422 base::Bind(&BlobURLRequestJob::DidReadFile, 425 base::Bind(&BlobURLRequestJob::DidReadFile,
423 base::Unretained(this), chunk_number)); 426 weak_factory_.GetWeakPtr(), chunk_number));
gavinp 2015/06/17 15:14:21 This was a mistake, but I say we leave it in: it c
michaeln 2015/06/17 20:49:35 yes please, use a weakptr here too
424 if (result >= 0) { 427 if (result >= 0) {
425 // Data is immediately available. 428 // Data is immediately available.
426 if (GetStatus().is_io_pending()) 429 if (GetStatus().is_io_pending())
427 DidReadFile(chunk_number, result); 430 DidReadFile(chunk_number, result);
428 else 431 else
429 AdvanceBytesRead(result); 432 AdvanceBytesRead(result);
430 return true; 433 return true;
431 } 434 }
432 if (result == net::ERR_IO_PENDING) 435 if (result == net::ERR_IO_PENDING)
433 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); 436 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0));
(...skipping 27 matching lines...) Expand all
461 } 464 }
462 465
463 void BlobURLRequestJob::DeleteCurrentFileReader() { 466 void BlobURLRequestJob::DeleteCurrentFileReader() {
464 IndexToReaderMap::iterator found = index_to_reader_.find(current_item_index_); 467 IndexToReaderMap::iterator found = index_to_reader_.find(current_item_index_);
465 if (found != index_to_reader_.end() && found->second) { 468 if (found != index_to_reader_.end() && found->second) {
466 delete found->second; 469 delete found->second;
467 index_to_reader_.erase(found); 470 index_to_reader_.erase(found);
468 } 471 }
469 } 472 }
470 473
474 bool BlobURLRequestJob::ReadDiskCacheEntryItem(const BlobDataItem& item,
475 int bytes_to_read) {
476 DCHECK_GE(read_buf_->BytesRemaining(), bytes_to_read);
477
478 const int result = item.disk_cache_entry()->ReadData(
gavinp 2015/06/17 15:14:21 This const stayed in for consistency with line 423
479 item.disk_cache_stream_index(), current_item_offset_, read_buf_.get(),
480 bytes_to_read, base::Bind(&BlobURLRequestJob::DidReadDiskCacheEntry,
481 base::Unretained(this)));
gavinp 2015/06/17 15:14:21 OMG, I fixed the wrong base::Unretained()!
michaeln 2015/06/17 20:49:35 yikes, thnx for catching this!
482 if (result >= 0) {
483 // Data is immediately available.
484 if (GetStatus().is_io_pending())
485 DidReadDiskCacheEntry(result);
486 else
487 AdvanceBytesRead(result);
488 return true;
489 }
490 if (result == net::ERR_IO_PENDING)
491 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0));
492 else
493 NotifyFailure(result);
494 return false;
495 }
496
497 void BlobURLRequestJob::DidReadDiskCacheEntry(int result) {
498 if (result <= 0) {
499 NotifyFailure(net::ERR_FAILED);
500 return;
501 }
502 SetStatus(net::URLRequestStatus());
503
504 AdvanceBytesRead(result);
505
506 if (!read_buf_->BytesRemaining()) {
507 int bytes_read = BytesReadCompleted();
508 NotifyReadComplete(bytes_read);
509 return;
510 }
511
512 int bytes_read = 0;
513 if (ReadLoop(&bytes_read))
514 NotifyReadComplete(bytes_read);
515 }
516
471 int BlobURLRequestJob::BytesReadCompleted() { 517 int BlobURLRequestJob::BytesReadCompleted() {
472 int bytes_read = read_buf_->BytesConsumed(); 518 int bytes_read = read_buf_->BytesConsumed();
473 read_buf_ = NULL; 519 read_buf_ = NULL;
474 return bytes_read; 520 return bytes_read;
475 } 521 }
476 522
477 int BlobURLRequestJob::ComputeBytesToRead() const { 523 int BlobURLRequestJob::ComputeBytesToRead() const {
478 int64 current_item_length = item_length_list_[current_item_index_]; 524 int64 current_item_length = item_length_list_[current_item_index_];
479 525
480 int64 item_remaining = current_item_length - current_item_offset_; 526 int64 item_remaining = current_item_length - current_item_offset_;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 687
642 default: 688 default:
643 break; 689 break;
644 } 690 }
645 691
646 NOTREACHED(); 692 NOTREACHED();
647 return false; 693 return false;
648 } 694 }
649 695
650 } // namespace storage 696 } // namespace storage
OLDNEW
« no previous file with comments | « storage/browser/blob/blob_url_request_job.h ('k') | storage/browser/blob/shareable_file_reference.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698