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

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: Remove an unnecessary parameter. 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..1e6c145d8124d6ff25c04a5f50d414ace9e35c8b 100644
--- a/components/drive/chromeos/file_cache.cc
+++ b/components/drive/chromeos/file_cache.cc
@@ -124,6 +124,13 @@ class CacheInfoLatestCompare {
}
};
+// Returns true if the cache file is present.
+bool IsPresent(const ResourceEntry& entry) {
+ return entry.has_file_specific_info() &&
+ entry.file_specific_info().has_cache_state() &&
+ entry.file_specific_info().cache_state().is_present();
+}
+
const size_t kMaxNumOfEvictedCacheFiles = 30000;
} // namespace
@@ -264,10 +271,32 @@ bool FileCache::FreeDiskSpaceIfNeededFor(int64_t num_bytes) {
return GetAvailableSpace() >= num_bytes;
}
-uint64_t FileCache::CalculateEvictableCacheSize() {
+int64_t FileCache::CalculateCacheSize() {
+ AssertOnSequencedWorkerPool();
+
+ 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 (IsPresent(it->GetValue()) &&
+ base::GetFileSize(GetCacheFilePath(it->GetID()), &cache_size)) {
+ DCHECK_GE(cache_size, 0);
+ total_cache_size += cache_size;
+ }
+ }
+
+ if (it->HasError())
+ return 0;
+
+ return total_cache_size;
+}
+
+int64_t FileCache::CalculateEvictableCacheSize() {
AssertOnSequencedWorkerPool();
- uint64_t evictable_cache_size = 0;
+ int64_t evictable_cache_size = 0;
int64_t cache_size = 0;
std::unique_ptr<ResourceMetadataStorage::Iterator> it =
@@ -875,7 +904,7 @@ void FileCache::CloseForWrite(const std::string& id) {
}
bool FileCache::IsEvictable(const std::string& id, const ResourceEntry& entry) {
- return entry.file_specific_info().has_cache_state() &&
+ return IsPresent(entry) &&
!entry.file_specific_info().cache_state().is_pinned() &&
!entry.file_specific_info().cache_state().is_dirty() &&
!mounted_files_.count(id);
« 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