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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ab19f080ff5c397f6515553f5ba219a16236cbbb 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));
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
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,
+ int bytes_to_read) {
+ DCHECK_GE(read_buf_->BytesRemaining(), bytes_to_read);
+
+ const int result = item.disk_cache_entry()->ReadData(
gavinp 2015/06/17 15:14:21 This const stayed in for consistency with line 423
+ item.disk_cache_stream_index(), current_item_offset_, read_buf_.get(),
+ bytes_to_read, base::Bind(&BlobURLRequestJob::DidReadDiskCacheEntry,
+ 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!
+ if (result >= 0) {
+ // Data is immediately available.
+ if (GetStatus().is_io_pending())
+ 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) {
+ 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;
« 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