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..76c0de3709137f914bd91832e5123ad1e588e6cf 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; |
@@ -468,6 +471,42 @@ void BlobURLRequestJob::DeleteCurrentFileReader() { |
} |
} |
+bool BlobURLRequestJob::ReadDiskCacheEntryItem(const BlobDataItem& item, |
+ 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, |
+ base::Unretained(this))); |
jkarlin
2015/06/12 15:53:38
Is base::Unretained safe here? Aren't jobs cleared
gavinp
2015/06/12 18:10:30
But we're mid-read, so isn't the URLRequest::Deleg
jkarlin
2015/06/12 19:17:52
I don't know how blob URLRequests are routed. Do t
mmenke
2015/06/12 19:23:36
Blob URL requests do indeed go through the RDH (Or
mmenke
2015/06/12 19:38:44
Sorry..scratch that. The UserData stapling is for
|
+ DCHECK_LT(result, 0); |
jkarlin
2015/06/12 15:53:38
The header doesn't say that ReadData is async only
gavinp
2015/06/12 18:10:30
True enough; and the memory cache is actually sync
|
+ 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) { |
jkarlin
2015/06/12 15:53:38
What if the item was 0 bytes?
gavinp
2015/06/12 18:10:30
Then we never called ReadDiskCacheEntryItem and th
|
+ NotifyFailure(net::ERR_FAILED); |
+ return; |
+ } |
+ SetStatus(net::URLRequestStatus()); |
+ |
+ AdvanceBytesRead(result); |
+ |
+ if (!read_buf_->BytesRemaining()) { |
+ 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; |