Chromium Code Reviews| Index: storage/browser/blob/blob_url_request_job.cc |
| diff --git a/storage/browser/blob/blob_url_request_job.cc b/storage/browser/blob/blob_url_request_job.cc |
| index 26607cd3e5c5db4b7cca2b66b0b69ec1883a3857..ce199cbec8e0df8e5b5717121101527f10d7bc16 100644 |
| --- a/storage/browser/blob/blob_url_request_job.cc |
| +++ b/storage/browser/blob/blob_url_request_job.cc |
| @@ -22,6 +22,7 @@ |
| #include "base/trace_event/trace_event.h" |
| #include "net/base/io_buffer.h" |
| #include "net/base/net_errors.h" |
| +#include "net/disk_cache/disk_cache.h" |
| #include "net/http/http_request_headers.h" |
| #include "net/http/http_response_headers.h" |
| #include "net/http/http_response_info.h" |
| @@ -356,6 +357,8 @@ bool BlobURLRequestJob::ReadItem() { |
| const BlobDataItem& item = *items.at(current_item_index_); |
| if (item.type() == DataElement::TYPE_BYTES) |
| return ReadBytesItem(item, bytes_to_read); |
| + if (item.type() == DataElement::TYPE_DISK_CACHE_ENTRY) |
| + return ReadDiskCacheEntryItem(item, bytes_to_read); |
| if (!IsFileType(item.type())) { |
| NOTREACHED(); |
| return false; |
| @@ -420,7 +423,7 @@ bool BlobURLRequestJob::ReadFileItem(FileStreamReader* reader, |
| const int result = |
| reader->Read(read_buf_.get(), bytes_to_read, |
| base::Bind(&BlobURLRequestJob::DidReadFile, |
| - base::Unretained(this), chunk_number)); |
| + weak_factory_.GetWeakPtr(), chunk_number)); |
| if (result >= 0) { |
| // Data is immediately available. |
| if (GetStatus().is_io_pending()) |
| @@ -468,6 +471,49 @@ void BlobURLRequestJob::DeleteCurrentFileReader() { |
| } |
| } |
| +bool BlobURLRequestJob::ReadDiskCacheEntryItem(const BlobDataItem& item, |
|
mmenke
2015/06/17 19:11:16
Are there tests that exercise this code?
michaeln
2015/06/17 20:49:35
good question, there should be tests for this in b
|
| + int bytes_to_read) { |
| + DCHECK_GE(read_buf_->BytesRemaining(), bytes_to_read); |
| + |
| + const int result = item.disk_cache_entry()->ReadData( |
| + item.disk_cache_stream_index(), current_item_offset_, read_buf_.get(), |
| + bytes_to_read, base::Bind(&BlobURLRequestJob::DidReadDiskCacheEntry, |
| + weak_factory_.GetWeakPtr())); |
| + if (result >= 0) { |
| + // Data is immediately available. |
| + if (GetStatus().is_io_pending()) |
|
mmenke
2015/06/17 19:11:16
I'm going to refrain from commenting on this. Mos
mmenke
2015/06/17 19:20:05
This looks like a bug, actually. In the async cas
dmurph
2015/06/17 20:18:07
This class is super old, crufty, and the current s
mmenke
2015/06/17 20:29:25
My guess is that's because reads generally always
michaeln
2015/06/17 20:49:36
Hmmm, in practice this might not be a bug with the
mmenke
2015/06/17 20:57:12
Unless, of course, you can concatenate blobs of di
michaeln
2015/06/17 21:27:54
That would be ideal and might help eliminate a bug
gavinp
2015/06/18 18:50:55
Can you be more explicit about which function is d
mmenke
2015/06/18 19:01:55
Sorry, I missed the SetStatus call in BlobURLReque
gavinp
2015/06/18 19:49:42
I think this is possible.
Imagine a read made of
mmenke
2015/06/18 19:58:22
Why is is_io_pending true there? We set it to ok
gavinp
2015/06/18 20:19:52
Right.
I've removed the dead code, and added a fe
|
| + DidReadDiskCacheEntry(result); |
| + else |
| + AdvanceBytesRead(result); |
| + return true; |
| + } |
| + if (result == net::ERR_IO_PENDING) |
| + SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); |
| + else |
| + NotifyFailure(result); |
| + return false; |
| +} |
| + |
| +void BlobURLRequestJob::DidReadDiskCacheEntry(int result) { |
| + if (result <= 0) { |
|
mmenke
2015/06/17 19:11:16
This is weird: If ReadData returns an error synch
gavinp
2015/06/18 18:50:55
Fixed here, and in the case for files.
|
| + NotifyFailure(net::ERR_FAILED); |
| + return; |
| + } |
| + SetStatus(net::URLRequestStatus()); |
| + |
| + AdvanceBytesRead(result); |
| + |
| + if (!read_buf_->BytesRemaining()) { |
|
mmenke
2015/06/17 19:11:16
Is this block needed? The ReadLoop call below alr
gavinp
2015/06/18 18:50:55
Done.
|
| + int bytes_read = BytesReadCompleted(); |
| + NotifyReadComplete(bytes_read); |
| + return; |
| + } |
| + |
| + int bytes_read = 0; |
| + if (ReadLoop(&bytes_read)) |
| + NotifyReadComplete(bytes_read); |
| +} |
| + |
| int BlobURLRequestJob::BytesReadCompleted() { |
| int bytes_read = read_buf_->BytesConsumed(); |
| read_buf_ = NULL; |