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

Side by Side Diff: content/browser/service_worker/service_worker_cache_storage.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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/service_worker/service_worker_cache_storage.h" 5 #include "content/browser/service_worker/service_worker_cache_storage.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/memory_mapped_file.h" 10 #include "base/files/memory_mapped_file.h"
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 493
494 if (!initialized_) 494 if (!initialized_)
495 return; 495 return;
496 496
497 for (auto& key_value : cache_map_) { 497 for (auto& key_value : cache_map_) {
498 if (key_value.second) 498 if (key_value.second)
499 key_value.second->Close(); 499 key_value.second->Close();
500 } 500 }
501 } 501 }
502 502
503 int64 ServiceWorkerCacheStorage::MemoryBackedSize() const {
504 DCHECK_CURRENTLY_ON(BrowserThread::IO);
505
506 if (!initialized_ || !memory_only_)
507 return 0;
508
509 int64 sum = 0;
510 for (auto& key_value : cache_map_) {
511 if (key_value.second)
512 sum += key_value.second->MemoryBackedSize();
513 }
514 return sum;
515 }
516
503 // Init is run lazily so that it is called on the proper MessageLoop. 517 // Init is run lazily so that it is called on the proper MessageLoop.
504 void ServiceWorkerCacheStorage::LazyInit(const base::Closure& callback) { 518 void ServiceWorkerCacheStorage::LazyInit(const base::Closure& callback) {
505 DCHECK_CURRENTLY_ON(BrowserThread::IO); 519 DCHECK_CURRENTLY_ON(BrowserThread::IO);
506 DCHECK(!initialized_); 520 DCHECK(!initialized_);
507 521
508 init_callbacks_.push_back(callback); 522 init_callbacks_.push_back(callback);
509 523
510 // If this isn't the first call to LazyInit then return as the initialization 524 // If this isn't the first call to LazyInit then return as the initialization
511 // has already started. 525 // has already started.
512 if (init_callbacks_.size() > 1u) 526 if (init_callbacks_.size() > 1u)
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 scoped_refptr<ServiceWorkerCache> new_cache = 630 scoped_refptr<ServiceWorkerCache> new_cache =
617 cache_loader_->CreateServiceWorkerCache(cache_name); 631 cache_loader_->CreateServiceWorkerCache(cache_name);
618 map_iter->second = new_cache->AsWeakPtr(); 632 map_iter->second = new_cache->AsWeakPtr();
619 return new_cache; 633 return new_cache;
620 } 634 }
621 635
622 return make_scoped_refptr(cache.get()); 636 return make_scoped_refptr(cache.get());
623 } 637 }
624 638
625 } // namespace content 639 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698