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

Unified Diff: components/drive/chromeos/file_cache.cc

Issue 2048993002: Add an API to get total size of Drive cache including non-evictable ones. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « components/drive/chromeos/file_cache.h ('k') | components/drive/chromeos/file_system.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/drive/chromeos/file_cache.cc
diff --git a/components/drive/chromeos/file_cache.cc b/components/drive/chromeos/file_cache.cc
index 37c0e87ff9e96ba26a55fcd178ce18cae960bb68..5b554b839797750afb8bde4647ef441ba73cf068 100644
--- a/components/drive/chromeos/file_cache.cc
+++ b/components/drive/chromeos/file_cache.cc
@@ -264,10 +264,31 @@ bool FileCache::FreeDiskSpaceIfNeededFor(int64_t num_bytes) {
return GetAvailableSpace() >= num_bytes;
}
-uint64_t FileCache::CalculateEvictableCacheSize() {
+int64_t FileCache::CalculateCacheSize() {
AssertOnSequencedWorkerPool();
- uint64_t evictable_cache_size = 0;
+ int64_t total_cache_size = 0;
+ int64_t cache_size = 0;
+
+ std::unique_ptr<ResourceMetadataStorage::Iterator> it =
+ storage_->GetIterator();
+ for (; !it->IsAtEnd(); it->Advance()) {
+ if (base::GetFileSize(GetCacheFilePath(it->GetID()), &cache_size)) {
yawano 2016/06/08 11:53:44 We should check the existence of cache by checking
fukino 2016/06/09 04:36:47 Nice catch! Done.
yawano 2016/06/09 05:19:19 You also need to check is_present to know whether
fukino 2016/06/09 06:38:21 Done.
+ DCHECK_GE(cache_size, 0);
+ total_cache_size += cache_size;
+ }
+ }
+
+ if (it->HasError())
+ return 0;
+
+ return total_cache_size;
+}
+
+int64_t FileCache::CalculateEvictableCacheSize() {
+ AssertOnSequencedWorkerPool();
+
+ int64_t evictable_cache_size = 0;
int64_t cache_size = 0;
std::unique_ptr<ResourceMetadataStorage::Iterator> it =
« no previous file with comments | « components/drive/chromeos/file_cache.h ('k') | components/drive/chromeos/file_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698