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

Unified Diff: content/browser/cache_storage/cache_storage_cache.cc

Issue 1636613002: [CacheStorage] Check quota before put operations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Set quota per origin and fix order of operations error Created 4 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/cache_storage/cache_storage_cache.cc
diff --git a/content/browser/cache_storage/cache_storage_cache.cc b/content/browser/cache_storage/cache_storage_cache.cc
index 2fc74110e7e16906675d343cd560a44dea2dfb6d..8d4f811008144ddf35b29cc82c949e9b76e327d0 100644
--- a/content/browser/cache_storage/cache_storage_cache.cc
+++ b/content/browser/cache_storage/cache_storage_cache.cc
@@ -15,6 +15,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
+#include "base/thread_task_runner_handle.h"
#include "content/browser/cache_storage/cache_storage.pb.h"
#include "content/browser/cache_storage/cache_storage_blob_to_disk_cache.h"
#include "content/browser/cache_storage/cache_storage_scheduler.h"
@@ -58,9 +59,9 @@ typedef base::Callback<void(scoped_ptr<CacheMetadata>)> MetadataCallback;
enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY };
-// The maximum size of an individual cache. Ultimately cache size is controlled
-// per-origin.
-const int kMaxCacheBytes = 512 * 1024 * 1024;
+// The maximum size of each cache. Ultimately, cache size
+// is controlled per-origin by the QuotaManager.
+const int kMaxCacheBytes = std::numeric_limits<int>::max();
void NotReachedCompletionCallback(int rv) {
NOTREACHED();
@@ -276,6 +277,7 @@ struct CacheStorageCache::PutContext {
scoped_refptr<net::URLRequestContextGetter> request_context_getter;
scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy;
disk_cache::ScopedEntryPtr cache_entry;
+ int64_t available_bytes = 0;
private:
DISALLOW_COPY_AND_ASSIGN(PutContext);
@@ -794,6 +796,31 @@ void CacheStorageCache::PutDidDelete(scoped_ptr<PutContext> put_context,
return;
}
+ quota_manager_proxy_->GetUsageAndQuota(
+ base::ThreadTaskRunnerHandle::Get().get(), origin_,
+ storage::kStorageTypeTemporary,
+ base::Bind(&CacheStorageCache::PutDidGetUsageAndQuota,
+ weak_ptr_factory_.GetWeakPtr(),
+ base::Passed(std::move(put_context))));
+}
+
+void CacheStorageCache::PutDidGetUsageAndQuota(
+ scoped_ptr<PutContext> put_context,
+ storage::QuotaStatusCode status_code,
+ int64_t usage,
+ int64_t quota) {
+ if (backend_state_ != BACKEND_OPEN) {
+ put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE);
+ return;
+ }
+
+ if (status_code != storage::kQuotaStatusOk) {
+ put_context->callback.Run(CACHE_STORAGE_ERROR_QUOTA_EXCEEDED);
+ return;
+ }
+
+ put_context->available_bytes = quota - usage;
+
scoped_ptr<disk_cache::Entry*> scoped_entry_ptr(new disk_cache::Entry*());
disk_cache::Entry** entry_ptr = scoped_entry_ptr.get();
ServiceWorkerFetchRequest* request_ptr = put_context->request.get();
@@ -860,6 +887,12 @@ void CacheStorageCache::PutDidCreateEntry(
scoped_refptr<net::StringIOBuffer> buffer(
new net::StringIOBuffer(std::move(serialized)));
+ int64_t bytes_to_write = buffer->size() + put_context->response->blob_size;
+ if (put_context->available_bytes < bytes_to_write) {
+ put_context->callback.Run(CACHE_STORAGE_ERROR_QUOTA_EXCEEDED);
+ return;
+ }
+
// Get a temporary copy of the entry pointer before passing it in base::Bind.
disk_cache::Entry* temp_entry_ptr = put_context->cache_entry.get();
« no previous file with comments | « content/browser/cache_storage/cache_storage_cache.h ('k') | content/browser/cache_storage/cache_storage_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698