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..c1431802d60a4a08cc1b7c62daf8b7e3dd6f88b8 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(); |
@@ -265,7 +266,8 @@ struct CacheStorageCache::PutContext { |
blob_data_handle(std::move(blob_data_handle)), |
callback(callback), |
request_context_getter(request_context_getter), |
- quota_manager_proxy(quota_manager_proxy) {} |
+ quota_manager_proxy(quota_manager_proxy), |
+ available_bytes(0) {} |
// Input parameters to the Put function. |
GURL origin; |
@@ -276,6 +278,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; |
michaeln
2016/01/26 00:16:08
could use = 0 here instead of adding the the initi
jkarlin
2016/01/26 12:08:35
Done.
|
private: |
DISALLOW_COPY_AND_ASSIGN(PutContext); |
@@ -794,6 +797,31 @@ void CacheStorageCache::PutDidDelete(scoped_ptr<PutContext> put_context, |
return; |
} |
+ quota_manager_proxy_->GetUsageAndQuota( |
+ base::ThreadTaskRunnerHandle::Get().get(), put_context->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 +888,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(); |