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

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

Issue 672943002: [ServiceWorkerCache] Return the real size of the cache in GetOriginUsage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@quota_modified
Patch Set: Address comments from PS5 Created 6 years, 2 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 bde3918bf79f218bcd424675cd41323b9486e013..6146de7dbe4113612e946647e929278aab457e63 100644
--- a/content/browser/service_worker/service_worker_cache.cc
+++ b/content/browser/service_worker/service_worker_cache.cc
@@ -42,6 +42,10 @@ const int kMaxCacheBytes = 512 * 1024 * 1024;
// Buffer size for cache and blob reading/writing.
const int kBufferSize = 1024 * 512;
+void NotReachedCompletionCallback(int rv) {
+ NOTREACHED();
+}
+
blink::WebServiceWorkerResponseType ProtoResponseTypeToWebResponseType(
ServiceWorkerRequestResponseHeaders_ResponseType response_type) {
switch (response_type) {
@@ -966,6 +970,34 @@ void ServiceWorkerCache::Close() {
backend_.reset();
}
+int64 ServiceWorkerCache::MemoryBackedSize() const {
+ if (!backend_ || !memory_only_)
+ return 0;
+
+ scoped_ptr<disk_cache::Backend::Iterator> backend_iter =
+ backend_->CreateIterator();
+ disk_cache::Entry* entry = nullptr;
+
+ int64 sum = 0;
+
+ std::vector<disk_cache::Entry*> entries;
+ int rv = net::OK;
+ while ((rv = backend_iter->OpenNextEntry(
+ &entry, base::Bind(NotReachedCompletionCallback))) == net::OK) {
+ entries.push_back(entry); // Open the entries without mutating them.
+ }
+ DCHECK(rv !=
+ net::ERR_IO_PENDING); // Expect all memory ops to be synchronous.
+
+ for (disk_cache::Entry* entry : entries) {
+ sum += entry->GetDataSize(INDEX_HEADERS) +
+ entry->GetDataSize(INDEX_RESPONSE_BODY);
+ entry->Close();
+ }
+
+ return sum;
+}
+
ServiceWorkerCache::ServiceWorkerCache(
const GURL& origin,
const base::FilePath& path,
@@ -978,6 +1010,7 @@ ServiceWorkerCache::ServiceWorkerCache(
quota_manager_proxy_(quota_manager_proxy),
blob_storage_context_(blob_context),
initialized_(false),
+ memory_only_(path.empty()),
weak_ptr_factory_(this) {
}
@@ -1112,8 +1145,7 @@ void ServiceWorkerCache::CreateBackend(const ErrorCallback& callback) {
DCHECK(!backend_);
// Use APP_CACHE as opposed to DISK_CACHE to prevent cache eviction.
- net::CacheType cache_type =
- path_.empty() ? net::MEMORY_CACHE : net::APP_CACHE;
+ net::CacheType cache_type = memory_only_ ? net::MEMORY_CACHE : net::APP_CACHE;
scoped_ptr<ScopedBackendPtr> backend_ptr(new ScopedBackendPtr());
« no previous file with comments | « content/browser/service_worker/service_worker_cache.h ('k') | content/browser/service_worker/service_worker_cache_storage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698