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

Unified Diff: content/browser/service_worker/service_worker_cache.cc

Issue 810403004: [Storage] Blob Storage Refactoring pt 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: memory leak fixed Created 5 years, 11 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
Index: content/browser/service_worker/service_worker_cache.cc
diff --git a/content/browser/service_worker/service_worker_cache.cc b/content/browser/service_worker/service_worker_cache.cc
index 3011356f4f17f3b81f8ae0867ae561e265da2fd2..0ca7e9d2e5ebaca4fe0021097a6f2b168c1d8f99 100644
--- a/content/browser/service_worker/service_worker_cache.cc
+++ b/content/browser/service_worker/service_worker_cache.cc
@@ -183,10 +183,11 @@ class ServiceWorkerCache::BlobReader : public net::URLRequest::Delegate {
weak_ptr_factory_(this) {}
// |entry| is passed to the callback once complete.
- void StreamBlobToCache(disk_cache::ScopedEntryPtr entry,
- net::URLRequestContext* request_context,
- scoped_ptr<storage::BlobDataHandle> blob_data_handle,
- const EntryAndBoolCallback& callback) {
+ void StreamBlobToCache(
+ disk_cache::ScopedEntryPtr entry,
+ net::URLRequestContext* request_context,
+ scoped_ptr<storage::BlobDataSnapshotHandle> blob_data_handle,
+ const EntryAndBoolCallback& callback) {
DCHECK(entry);
entry_ = entry.Pass();
callback_ = callback;
@@ -343,7 +344,7 @@ struct ServiceWorkerCache::MatchContext {
// Output
scoped_ptr<ServiceWorkerResponse> response;
- scoped_refptr<storage::BlobData> blob_data;
+ scoped_ptr<storage::BlobDataBuilder> blob_data;
// For reading the cache entry data into a blob.
scoped_refptr<net::IOBufferWithSize> response_body_buffer;
@@ -358,7 +359,7 @@ struct ServiceWorkerCache::PutContext {
const GURL& origin,
scoped_ptr<ServiceWorkerFetchRequest> request,
scoped_ptr<ServiceWorkerResponse> response,
- scoped_ptr<storage::BlobDataHandle> blob_data_handle,
+ scoped_ptr<storage::BlobDataSnapshotHandle> blob_data_handle,
const ServiceWorkerCache::ResponseCallback& callback,
net::URLRequestContext* request_context,
const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy)
@@ -379,7 +380,7 @@ struct ServiceWorkerCache::PutContext {
GURL origin;
scoped_ptr<ServiceWorkerFetchRequest> request;
scoped_ptr<ServiceWorkerResponse> response;
- scoped_ptr<storage::BlobDataHandle> blob_data_handle;
+ scoped_ptr<storage::BlobDataSnapshotHandle> blob_data_handle;
ServiceWorkerCache::ResponseCallback callback;
net::URLRequestContext* request_context;
scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy;
@@ -389,7 +390,7 @@ struct ServiceWorkerCache::PutContext {
disk_cache::Entry* cache_entry;
// The BlobDataHandle for the output ServiceWorkerResponse.
- scoped_ptr<storage::BlobDataHandle> out_blob_data_handle;
+ scoped_ptr<storage::BlobDataSnapshotHandle> out_blob_data_handle;
DISALLOW_COPY_AND_ASSIGN(PutContext);
};
@@ -432,13 +433,13 @@ void ServiceWorkerCache::Put(scoped_ptr<ServiceWorkerFetchRequest> request,
ResponseCallback pending_callback =
base::Bind(&ServiceWorkerCache::PendingResponseCallback,
weak_ptr_factory_.GetWeakPtr(), callback);
- scoped_ptr<storage::BlobDataHandle> blob_data_handle;
+ scoped_ptr<storage::BlobDataSnapshotHandle> blob_data_handle;
if (!response->blob_uuid.empty()) {
if (!blob_storage_context_) {
pending_callback.Run(ErrorTypeStorage,
scoped_ptr<ServiceWorkerResponse>(),
- scoped_ptr<storage::BlobDataHandle>());
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
}
blob_data_handle =
@@ -446,7 +447,7 @@ void ServiceWorkerCache::Put(scoped_ptr<ServiceWorkerFetchRequest> request,
if (!blob_data_handle) {
pending_callback.Run(ErrorTypeStorage,
scoped_ptr<ServiceWorkerResponse>(),
- scoped_ptr<storage::BlobDataHandle>());
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
}
}
@@ -490,7 +491,7 @@ void ServiceWorkerCache::Match(scoped_ptr<ServiceWorkerFetchRequest> request,
case BACKEND_CLOSED:
pending_callback.Run(ErrorTypeStorage,
scoped_ptr<ServiceWorkerResponse>(),
- scoped_ptr<storage::BlobDataHandle>());
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
case BACKEND_OPEN:
DCHECK(backend_);
@@ -661,9 +662,10 @@ void ServiceWorkerCache::MatchDidOpenEntry(
scoped_ptr<MatchContext> match_context,
int rv) {
if (rv != net::OK) {
- match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeNotFound,
- scoped_ptr<ServiceWorkerResponse>(),
- scoped_ptr<storage::BlobDataHandle>());
+ match_context->original_callback.Run(
+ ServiceWorkerCache::ErrorTypeNotFound,
+ scoped_ptr<ServiceWorkerResponse>(),
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
}
@@ -682,9 +684,10 @@ void ServiceWorkerCache::MatchDidReadMetadata(
scoped_ptr<MatchContext> match_context,
scoped_ptr<ServiceWorkerCacheMetadata> metadata) {
if (!metadata) {
- match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeStorage,
- scoped_ptr<ServiceWorkerResponse>(),
- scoped_ptr<storage::BlobDataHandle>());
+ match_context->original_callback.Run(
+ ServiceWorkerCache::ErrorTypeStorage,
+ scoped_ptr<ServiceWorkerResponse>(),
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
}
@@ -712,30 +715,33 @@ void ServiceWorkerCache::MatchDidReadMetadata(
if (!VaryMatches(match_context->request->headers, cached_request_headers,
response->headers)) {
- match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeNotFound,
- scoped_ptr<ServiceWorkerResponse>(),
- scoped_ptr<storage::BlobDataHandle>());
+ match_context->original_callback.Run(
+ ServiceWorkerCache::ErrorTypeNotFound,
+ scoped_ptr<ServiceWorkerResponse>(),
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
}
if (match_context->entry->GetDataSize(INDEX_RESPONSE_BODY) == 0) {
- match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeOK,
- match_context->response.Pass(),
- scoped_ptr<storage::BlobDataHandle>());
+ match_context->original_callback.Run(
+ ServiceWorkerCache::ErrorTypeOK, match_context->response.Pass(),
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
}
// Stream the response body into a blob.
if (!match_context->blob_storage_context) {
- match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeStorage,
- scoped_ptr<ServiceWorkerResponse>(),
- scoped_ptr<storage::BlobDataHandle>());
+ match_context->original_callback.Run(
+ ServiceWorkerCache::ErrorTypeStorage,
+ scoped_ptr<ServiceWorkerResponse>(),
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
}
response->blob_uuid = base::GenerateGUID();
- match_context->blob_data = new storage::BlobData(response->blob_uuid);
+ match_context->blob_data.reset(
+ new storage::BlobDataBuilder(response->blob_uuid));
match_context->response_body_buffer = new net::IOBufferWithSize(kBufferSize);
disk_cache::Entry* tmp_entry_ptr = match_context->entry;
@@ -763,9 +769,10 @@ void ServiceWorkerCache::MatchDidReadResponseBodyData(
"422516 ServiceWorkerCache::MatchDidReadResponseBodyData"));
if (rv < 0) {
- match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeStorage,
- scoped_ptr<ServiceWorkerResponse>(),
- scoped_ptr<storage::BlobDataHandle>());
+ match_context->original_callback.Run(
+ ServiceWorkerCache::ErrorTypeStorage,
+ scoped_ptr<ServiceWorkerResponse>(),
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
}
@@ -802,15 +809,16 @@ void ServiceWorkerCache::MatchDidReadResponseBodyData(
void ServiceWorkerCache::MatchDoneWithBody(
scoped_ptr<MatchContext> match_context) {
if (!match_context->blob_storage_context) {
- match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeStorage,
- scoped_ptr<ServiceWorkerResponse>(),
- scoped_ptr<storage::BlobDataHandle>());
+ match_context->original_callback.Run(
+ ServiceWorkerCache::ErrorTypeStorage,
+ scoped_ptr<ServiceWorkerResponse>(),
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
}
- scoped_ptr<storage::BlobDataHandle> blob_data_handle(
+ scoped_ptr<storage::BlobDataSnapshotHandle> blob_data_handle(
match_context->blob_storage_context->AddFinishedBlob(
- match_context->blob_data.get()));
+ *match_context->blob_data.get()));
match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeOK,
match_context->response.Pass(),
@@ -821,7 +829,7 @@ void ServiceWorkerCache::PutImpl(scoped_ptr<PutContext> put_context) {
if (backend_state_ != BACKEND_OPEN) {
put_context->callback.Run(ErrorTypeStorage,
scoped_ptr<ServiceWorkerResponse>(),
- scoped_ptr<storage::BlobDataHandle>());
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
}
@@ -838,7 +846,7 @@ void ServiceWorkerCache::PutDidDelete(scoped_ptr<PutContext> put_context,
if (backend_state_ != BACKEND_OPEN) {
put_context->callback.Run(ErrorTypeStorage,
scoped_ptr<ServiceWorkerResponse>(),
- scoped_ptr<storage::BlobDataHandle>());
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
}
@@ -862,7 +870,7 @@ void ServiceWorkerCache::PutDidCreateEntry(scoped_ptr<PutContext> put_context,
if (rv != net::OK) {
put_context->callback.Run(ServiceWorkerCache::ErrorTypeExists,
scoped_ptr<ServiceWorkerResponse>(),
- scoped_ptr<storage::BlobDataHandle>());
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
}
@@ -899,7 +907,7 @@ void ServiceWorkerCache::PutDidCreateEntry(scoped_ptr<PutContext> put_context,
if (!metadata.SerializeToString(serialized.get())) {
put_context->callback.Run(ServiceWorkerCache::ErrorTypeStorage,
scoped_ptr<ServiceWorkerResponse>(),
- scoped_ptr<storage::BlobDataHandle>());
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
}
@@ -931,7 +939,7 @@ void ServiceWorkerCache::PutDidWriteHeaders(scoped_ptr<PutContext> put_context,
put_context->cache_entry->Doom();
put_context->callback.Run(ServiceWorkerCache::ErrorTypeStorage,
scoped_ptr<ServiceWorkerResponse>(),
- scoped_ptr<storage::BlobDataHandle>());
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
}
@@ -949,7 +957,7 @@ void ServiceWorkerCache::PutDidWriteHeaders(scoped_ptr<PutContext> put_context,
put_context->callback.Run(ServiceWorkerCache::ErrorTypeOK,
put_context->response.Pass(),
- scoped_ptr<storage::BlobDataHandle>());
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
}
@@ -962,7 +970,7 @@ void ServiceWorkerCache::PutDidWriteHeaders(scoped_ptr<PutContext> put_context,
// Grab some pointers before passing put_context in Bind.
net::URLRequestContext* request_context = put_context->request_context;
- scoped_ptr<storage::BlobDataHandle> blob_data_handle =
+ scoped_ptr<storage::BlobDataSnapshotHandle> blob_data_handle =
put_context->blob_data_handle.Pass();
reader_ptr->StreamBlobToCache(
@@ -985,7 +993,7 @@ void ServiceWorkerCache::PutDidWriteBlobToCache(
put_context->cache_entry->Doom();
put_context->callback.Run(ServiceWorkerCache::ErrorTypeStorage,
scoped_ptr<ServiceWorkerResponse>(),
- scoped_ptr<storage::BlobDataHandle>());
+ scoped_ptr<storage::BlobDataSnapshotHandle>());
return;
}
@@ -1208,7 +1216,7 @@ void ServiceWorkerCache::PendingResponseCallback(
const ResponseCallback& callback,
ErrorType error,
scoped_ptr<ServiceWorkerResponse> response,
- scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
+ scoped_ptr<storage::BlobDataSnapshotHandle> blob_data_handle) {
callback.Run(error, response.Pass(), blob_data_handle.Pass());
DecPendingOps();
}

Powered by Google App Engine
This is Rietveld 408576698