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

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

Issue 2416713002: Write out CacheStorageCache size to index file. (Closed)
Patch Set: Consolidated observer methods, renames, cleanup, etc. Created 4 years, 1 month 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 6ca5786b882581b11095984e4565ee02f7e691fc..ff8778cd65481f3d95a5edf427ff2441ce054d95 100644
--- a/content/browser/cache_storage/cache_storage_cache.cc
+++ b/content/browser/cache_storage/cache_storage_cache.cc
@@ -24,6 +24,7 @@
#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_cache_handle.h"
+#include "content/browser/cache_storage/cache_storage_cache_observer.h"
#include "content/browser/cache_storage/cache_storage_scheduler.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/referrer.h"
@@ -265,8 +266,8 @@ std::unique_ptr<CacheStorageCache> CacheStorageCache::CreateMemoryCache(
CacheStorageCache* cache =
new CacheStorageCache(origin, cache_name, base::FilePath(), cache_storage,
std::move(request_context_getter),
- std::move(quota_manager_proxy), blob_context);
- cache->InitBackend();
+ std::move(quota_manager_proxy), blob_context, 0);
jkarlin 2016/11/11 18:24:57 nit: can you add /* cache size */ after the 0?
cmumford 2016/11/22 17:45:03 Done.
+ cache->SetObserver(cache_storage), cache->InitBackend();
return base::WrapUnique(cache);
}
@@ -278,12 +279,13 @@ std::unique_ptr<CacheStorageCache> CacheStorageCache::CreatePersistentCache(
const base::FilePath& path,
scoped_refptr<net::URLRequestContextGetter> request_context_getter,
scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy,
- base::WeakPtr<storage::BlobStorageContext> blob_context) {
- CacheStorageCache* cache =
- new CacheStorageCache(origin, cache_name, path, cache_storage,
- std::move(request_context_getter),
- std::move(quota_manager_proxy), blob_context);
- cache->InitBackend();
+ base::WeakPtr<storage::BlobStorageContext> blob_context,
+ int64_t cache_size) {
+ CacheStorageCache* cache = new CacheStorageCache(
+ origin, cache_name, path, cache_storage,
+ std::move(request_context_getter), std::move(quota_manager_proxy),
+ blob_context, cache_size);
+ cache->SetObserver(cache_storage), cache->InitBackend();
return base::WrapUnique(cache);
}
@@ -497,6 +499,10 @@ void CacheStorageCache::GetSizeThenClose(const SizeCallback& callback) {
scheduler_->WrapCallbackToRunNext(callback))));
}
+void CacheStorageCache::SetObserver(CacheStorageCacheObserver* observer) {
+ cache_observer_ = observer;
+}
+
CacheStorageCache::~CacheStorageCache() {
quota_manager_proxy_->NotifyOriginNoLongerInUse(origin_);
}
@@ -508,7 +514,8 @@ CacheStorageCache::CacheStorageCache(
CacheStorage* cache_storage,
scoped_refptr<net::URLRequestContextGetter> request_context_getter,
scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy,
- base::WeakPtr<storage::BlobStorageContext> blob_context)
+ base::WeakPtr<storage::BlobStorageContext> blob_context,
+ int64_t cache_size)
: origin_(origin),
cache_name_(cache_name),
path_(path),
@@ -518,7 +525,9 @@ CacheStorageCache::CacheStorageCache(
blob_storage_context_(blob_context),
scheduler_(
new CacheStorageScheduler(CacheStorageSchedulerClient::CLIENT_CACHE)),
+ cache_size_(cache_size),
max_query_size_bytes_(kMaxQueryCacheResultBytes),
+ cache_observer_(nullptr),
memory_only_(path.empty()),
weak_ptr_factory_(this) {
DCHECK(!origin_.is_empty());
@@ -1184,12 +1193,19 @@ void CacheStorageCache::UpdateCacheSize() {
void CacheStorageCache::UpdateCacheSizeGotSize(
std::unique_ptr<CacheStorageCacheHandle> cache_handle,
int current_cache_size) {
+ DCHECK_NE(current_cache_size, CacheStorage::kSizeUnknown);
int64_t old_cache_size = cache_size_;
cache_size_ = current_cache_size;
+ int64_t size_delta = current_cache_size - old_cache_size;
+
quota_manager_proxy_->NotifyStorageModified(
storage::QuotaClient::kServiceWorkerCache, origin_,
- storage::kStorageTypeTemporary, current_cache_size - old_cache_size);
+ storage::kStorageTypeTemporary, size_delta);
+
+ if (cache_observer_)
+ cache_observer_->CacheSizeSet(
+ this, CacheStorageCacheObserver::Whence::DELTA, size_delta);
}
void CacheStorageCache::Delete(const CacheStorageBatchOperation& operation,
@@ -1374,6 +1390,11 @@ void CacheStorageCache::InitDidCreateBackend(
void CacheStorageCache::InitGotCacheSize(const base::Closure& callback,
CacheStorageError cache_create_error,
int cache_size) {
+ if (cache_size_ != CacheStorage::kSizeUnknown) {
+ // If this check fails, either there is a flaw in how Chrome remembers the
+ // cache size, or the files in the cache have been modified.
+ DCHECK_EQ(cache_size_, cache_size);
jkarlin 2016/11/11 18:24:57 Hmm, how about DCHECK(cache_size == CacheStorage::
cmumford 2016/11/22 17:45:03 Done.
+ }
cache_size_ = cache_size;
initializing_ = false;
backend_state_ = (cache_create_error == CACHE_STORAGE_OK && backend_ &&
@@ -1384,6 +1405,10 @@ void CacheStorageCache::InitGotCacheSize(const base::Closure& callback,
UMA_HISTOGRAM_ENUMERATION("ServiceWorkerCache.InitBackendResult",
cache_create_error, CACHE_STORAGE_ERROR_LAST + 1);
+ if (cache_observer_)
+ cache_observer_->CacheSizeSet(this, CacheStorageCacheObserver::Whence::SET,
+ cache_size_);
+
callback.Run();
}

Powered by Google App Engine
This is Rietveld 408576698