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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 } | 344 } |
345 | 345 |
346 // Do the reading. | 346 // Do the reading. |
347 const BlobDataItem& item = *items.at(current_item_index_); | 347 const BlobDataItem& item = *items.at(current_item_index_); |
348 if (item.type() == DataElement::TYPE_BYTES) | 348 if (item.type() == DataElement::TYPE_BYTES) |
349 return ReadBytesItem(item, bytes_to_read); | 349 return ReadBytesItem(item, bytes_to_read); |
350 if (IsFileType(item.type())) { | 350 if (IsFileType(item.type())) { |
351 return ReadFileItem(GetFileStreamReader(current_item_index_), | 351 return ReadFileItem(GetFileStreamReader(current_item_index_), |
352 bytes_to_read); | 352 bytes_to_read); |
353 } | 353 } |
354 if (item.type() == DataElement::TYPE_DISK_CACHE_ENTRY) | |
355 return ReadDiskCacheEntryItem(item, bytes_to_read); | |
354 NOTREACHED(); | 356 NOTREACHED(); |
355 return false; | 357 return false; |
356 } | 358 } |
357 | 359 |
358 void BlobURLRequestJob::AdvanceItem() { | 360 void BlobURLRequestJob::AdvanceItem() { |
359 // Close the file if the current item is a file. | 361 // Close the file if the current item is a file. |
360 DeleteCurrentFileReader(); | 362 DeleteCurrentFileReader(); |
361 | 363 |
362 // Advance to the next item. | 364 // Advance to the next item. |
363 current_item_index_++; | 365 current_item_index_++; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
446 } | 448 } |
447 | 449 |
448 void BlobURLRequestJob::DeleteCurrentFileReader() { | 450 void BlobURLRequestJob::DeleteCurrentFileReader() { |
449 IndexToReaderMap::iterator found = index_to_reader_.find(current_item_index_); | 451 IndexToReaderMap::iterator found = index_to_reader_.find(current_item_index_); |
450 if (found != index_to_reader_.end() && found->second) { | 452 if (found != index_to_reader_.end() && found->second) { |
451 delete found->second; | 453 delete found->second; |
452 index_to_reader_.erase(found); | 454 index_to_reader_.erase(found); |
453 } | 455 } |
454 } | 456 } |
455 | 457 |
458 bool BlobURLRequestJob::ReadDiskCacheEntryItem(const BlobDataItem& item, | |
459 int bytes_to_read) { | |
460 DCHECK_GE(read_buf_->BytesRemaining(), bytes_to_read); | |
461 | |
462 const int result = item.disk_cache_entry()->ReadData( | |
463 item.disk_cache_stream_index(), current_item_offset_, read_buf_.get(), | |
464 bytes_to_read, base::Bind(&BlobURLRequestJob::DidReadDiskCacheEntry, | |
465 base::Unretained(this))); | |
michaeln
2015/06/12 22:35:09
2 questions:
1) How is base::Unretained here safe
gavinp
2015/06/15 14:01:19
I think you're right. jkarlin first raised this in
| |
466 DCHECK_LT(result, 0); | |
467 if (result == net::ERR_IO_PENDING) | |
468 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); | |
469 else | |
470 NotifyFailure(result); | |
471 return false; | |
472 } | |
473 | |
474 void BlobURLRequestJob::DidReadDiskCacheEntry(int result) { | |
475 if (result <= 0) { | |
476 NotifyFailure(net::ERR_FAILED); | |
477 return; | |
478 } | |
479 SetStatus(net::URLRequestStatus()); | |
480 | |
481 AdvanceBytesRead(result); | |
482 | |
483 if (!read_buf_->BytesRemaining()) { | |
484 int bytes_read = BytesReadCompleted(); | |
485 NotifyReadComplete(bytes_read); | |
486 return; | |
487 } | |
488 | |
489 int bytes_read = 0; | |
490 if (ReadLoop(&bytes_read)) | |
491 NotifyReadComplete(bytes_read); | |
492 } | |
493 | |
456 int BlobURLRequestJob::BytesReadCompleted() { | 494 int BlobURLRequestJob::BytesReadCompleted() { |
457 int bytes_read = read_buf_->BytesConsumed(); | 495 int bytes_read = read_buf_->BytesConsumed(); |
458 read_buf_ = NULL; | 496 read_buf_ = NULL; |
459 return bytes_read; | 497 return bytes_read; |
460 } | 498 } |
461 | 499 |
462 int BlobURLRequestJob::ComputeBytesToRead() const { | 500 int BlobURLRequestJob::ComputeBytesToRead() const { |
463 int64 current_item_length = item_length_list_[current_item_index_]; | 501 int64 current_item_length = item_length_list_[current_item_index_]; |
464 | 502 |
465 int64 item_remaining = current_item_length - current_item_offset_; | 503 int64 item_remaining = current_item_length - current_item_offset_; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
614 .release(); | 652 .release(); |
615 break; | 653 break; |
616 default: | 654 default: |
617 NOTREACHED(); | 655 NOTREACHED(); |
618 } | 656 } |
619 DCHECK(reader); | 657 DCHECK(reader); |
620 index_to_reader_[index] = reader; | 658 index_to_reader_[index] = reader; |
621 } | 659 } |
622 | 660 |
623 } // namespace storage | 661 } // namespace storage |
OLD | NEW |