Chromium Code Reviews| 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 d8f13cc8b92c3e8ba814a1b5eea791c7375cba41..1fbabfda3365b10cb4dce23df1a1d40bff9c9c08 100644 |
| --- a/content/browser/service_worker/service_worker_cache.cc |
| +++ b/content/browser/service_worker/service_worker_cache.cc |
| @@ -960,6 +960,38 @@ void ServiceWorkerCache::Close() { |
| backend_.reset(); |
| } |
| +void NotReachedCompletionCallback(int rv) { |
|
falken
2014/10/24 03:14:15
can you move this helper into the nameless namespa
jkarlin
2014/10/24 11:53:48
Done. Thanks for catching that!
|
| + NOTREACHED(); |
| +} |
| + |
| +int64 ServiceWorkerCache::MemoryBackedSize() const { |
| + if (!backend_ || !memory_only_) |
| + return 0; |
| + |
| + scoped_ptr<disk_cache::Backend::Iterator> backend_iter = |
| + backend_->CreateIterator(); |
| + disk_cache::Entry* entry = NULL; |
|
falken
2014/10/24 02:24:34
nullptr
jkarlin
2014/10/24 11:53:49
Done.
|
| + |
| + 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. |
|
falken
2014/10/24 02:24:34
can you just add the entry's size here instead of
jkarlin
2014/10/24 11:53:49
Sadly, no. Getting the size mutates the ordering o
|
| + } |
| + 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, |
| @@ -972,6 +1004,7 @@ ServiceWorkerCache::ServiceWorkerCache( |
| quota_manager_proxy_(quota_manager_proxy), |
| blob_storage_context_(blob_context), |
| initialized_(false), |
| + memory_only_(path.empty()), |
| weak_ptr_factory_(this) { |
| } |
| @@ -1106,8 +1139,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()); |