OLD | NEW |
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> |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 // If nothing to read for current item, advance to next item. | 349 // If nothing to read for current item, advance to next item. |
350 if (bytes_to_read == 0) { | 350 if (bytes_to_read == 0) { |
351 AdvanceItem(); | 351 AdvanceItem(); |
352 return true; | 352 return true; |
353 } | 353 } |
354 | 354 |
355 // Do the reading. | 355 // Do the reading. |
356 const BlobDataItem& item = *items.at(current_item_index_); | 356 const BlobDataItem& item = *items.at(current_item_index_); |
357 if (item.type() == DataElement::TYPE_BYTES) | 357 if (item.type() == DataElement::TYPE_BYTES) |
358 return ReadBytesItem(item, bytes_to_read); | 358 return ReadBytesItem(item, bytes_to_read); |
| 359 if (item.type() == DataElement::TYPE_DISK_CACHE_ENTRY) |
| 360 return ReadDiskCacheEntryItem(item, bytes_to_read); |
359 if (!IsFileType(item.type())) { | 361 if (!IsFileType(item.type())) { |
360 NOTREACHED(); | 362 NOTREACHED(); |
361 return false; | 363 return false; |
362 } | 364 } |
363 storage::FileStreamReader* const reader = | 365 storage::FileStreamReader* const reader = |
364 GetFileStreamReader(current_item_index_); | 366 GetFileStreamReader(current_item_index_); |
365 if (!reader) { | 367 if (!reader) { |
366 NotifyFailure(net::ERR_FAILED); | 368 NotifyFailure(net::ERR_FAILED); |
367 return false; | 369 return false; |
368 } | 370 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 } | 463 } |
462 | 464 |
463 void BlobURLRequestJob::DeleteCurrentFileReader() { | 465 void BlobURLRequestJob::DeleteCurrentFileReader() { |
464 IndexToReaderMap::iterator found = index_to_reader_.find(current_item_index_); | 466 IndexToReaderMap::iterator found = index_to_reader_.find(current_item_index_); |
465 if (found != index_to_reader_.end() && found->second) { | 467 if (found != index_to_reader_.end() && found->second) { |
466 delete found->second; | 468 delete found->second; |
467 index_to_reader_.erase(found); | 469 index_to_reader_.erase(found); |
468 } | 470 } |
469 } | 471 } |
470 | 472 |
| 473 bool BlobURLRequestJob::ReadDiskCacheEntryItem(const BlobDataItem& item, |
| 474 int bytes_to_read) { |
| 475 DCHECK_GE(read_buf_->BytesRemaining(), bytes_to_read); |
| 476 |
| 477 const int result = item.disk_cache_entry()->ReadData( |
| 478 item.disk_cache_stream_index(), current_item_offset_, read_buf_.get(), |
| 479 bytes_to_read, base::Bind(&BlobURLRequestJob::DidReadDiskCacheEntry, |
| 480 base::Unretained(this))); |
| 481 DCHECK_LT(result, 0); |
| 482 if (result == net::ERR_IO_PENDING) |
| 483 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); |
| 484 else |
| 485 NotifyFailure(result); |
| 486 return false; |
| 487 } |
| 488 |
| 489 void BlobURLRequestJob::DidReadDiskCacheEntry(int result) { |
| 490 if (result <= 0) { |
| 491 NotifyFailure(net::ERR_FAILED); |
| 492 return; |
| 493 } |
| 494 SetStatus(net::URLRequestStatus()); |
| 495 |
| 496 AdvanceBytesRead(result); |
| 497 |
| 498 if (!read_buf_->BytesRemaining()) { |
| 499 int bytes_read = BytesReadCompleted(); |
| 500 NotifyReadComplete(bytes_read); |
| 501 return; |
| 502 } |
| 503 |
| 504 int bytes_read = 0; |
| 505 if (ReadLoop(&bytes_read)) |
| 506 NotifyReadComplete(bytes_read); |
| 507 } |
| 508 |
471 int BlobURLRequestJob::BytesReadCompleted() { | 509 int BlobURLRequestJob::BytesReadCompleted() { |
472 int bytes_read = read_buf_->BytesConsumed(); | 510 int bytes_read = read_buf_->BytesConsumed(); |
473 read_buf_ = NULL; | 511 read_buf_ = NULL; |
474 return bytes_read; | 512 return bytes_read; |
475 } | 513 } |
476 | 514 |
477 int BlobURLRequestJob::ComputeBytesToRead() const { | 515 int BlobURLRequestJob::ComputeBytesToRead() const { |
478 int64 current_item_length = item_length_list_[current_item_index_]; | 516 int64 current_item_length = item_length_list_[current_item_index_]; |
479 | 517 |
480 int64 item_remaining = current_item_length - current_item_offset_; | 518 int64 item_remaining = current_item_length - current_item_offset_; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 | 680 |
643 default: | 681 default: |
644 break; | 682 break; |
645 } | 683 } |
646 | 684 |
647 NOTREACHED(); | 685 NOTREACHED(); |
648 return false; | 686 return false; |
649 } | 687 } |
650 | 688 |
651 } // namespace storage | 689 } // namespace storage |
OLD | NEW |