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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "components/drive/chromeos/file_cache.h" 5 #include "components/drive/chromeos/file_cache.h"
6 6
7 #include <linux/fs.h> 7 #include <linux/fs.h>
8 #include <sys/ioctl.h> 8 #include <sys/ioctl.h>
9 #include <sys/xattr.h> 9 #include <sys/xattr.h>
10 10
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 && SetExtendedFileAttributes(path, FileCache::kGCacheFilesAttribute, ""); 117 && SetExtendedFileAttributes(path, FileCache::kGCacheFilesAttribute, "");
118 } 118 }
119 119
120 class CacheInfoLatestCompare { 120 class CacheInfoLatestCompare {
121 public: 121 public:
122 bool operator()(const CacheInfo& info_a, const CacheInfo& info_b) { 122 bool operator()(const CacheInfo& info_a, const CacheInfo& info_b) {
123 return info_a.first.last_accessed < info_b.first.last_accessed; 123 return info_a.first.last_accessed < info_b.first.last_accessed;
124 } 124 }
125 }; 125 };
126 126
127 // Returns true if the cache file is present.
128 bool IsPresent(const ResourceEntry& entry) {
129 return entry.has_file_specific_info() &&
130 entry.file_specific_info().has_cache_state() &&
131 entry.file_specific_info().cache_state().is_present();
132 }
133
127 const size_t kMaxNumOfEvictedCacheFiles = 30000; 134 const size_t kMaxNumOfEvictedCacheFiles = 30000;
128 135
129 } // namespace 136 } // namespace
130 137
131 // static 138 // static
132 const char FileCache::kGCacheFilesAttribute[] = "user.GCacheFiles"; 139 const char FileCache::kGCacheFilesAttribute[] = "user.GCacheFiles";
133 140
134 FileCache::FileCache(ResourceMetadataStorage* storage, 141 FileCache::FileCache(ResourceMetadataStorage* storage,
135 const base::FilePath& cache_file_directory, 142 const base::FilePath& cache_file_directory,
136 base::SequencedTaskRunner* blocking_task_runner, 143 base::SequencedTaskRunner* blocking_task_runner,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 if (base::DeleteFile(path, false /* recursive */)) 264 if (base::DeleteFile(path, false /* recursive */))
258 evicted_cache_size += cache_info.first.size; 265 evicted_cache_size += cache_info.first.size;
259 266
260 ++iter; 267 ++iter;
261 } 268 }
262 269
263 // Check the disk space again. 270 // Check the disk space again.
264 return GetAvailableSpace() >= num_bytes; 271 return GetAvailableSpace() >= num_bytes;
265 } 272 }
266 273
267 uint64_t FileCache::CalculateEvictableCacheSize() { 274 int64_t FileCache::CalculateCacheSize() {
268 AssertOnSequencedWorkerPool(); 275 AssertOnSequencedWorkerPool();
269 276
270 uint64_t evictable_cache_size = 0; 277 int64_t total_cache_size = 0;
271 int64_t cache_size = 0; 278 int64_t cache_size = 0;
272 279
273 std::unique_ptr<ResourceMetadataStorage::Iterator> it = 280 std::unique_ptr<ResourceMetadataStorage::Iterator> it =
281 storage_->GetIterator();
282 for (; !it->IsAtEnd(); it->Advance()) {
283 if (IsPresent(it->GetValue()) &&
284 base::GetFileSize(GetCacheFilePath(it->GetID()), &cache_size)) {
285 DCHECK_GE(cache_size, 0);
286 total_cache_size += cache_size;
287 }
288 }
289
290 if (it->HasError())
291 return 0;
292
293 return total_cache_size;
294 }
295
296 int64_t FileCache::CalculateEvictableCacheSize() {
297 AssertOnSequencedWorkerPool();
298
299 int64_t evictable_cache_size = 0;
300 int64_t cache_size = 0;
301
302 std::unique_ptr<ResourceMetadataStorage::Iterator> it =
274 storage_->GetIterator(); 303 storage_->GetIterator();
275 for (; !it->IsAtEnd(); it->Advance()) { 304 for (; !it->IsAtEnd(); it->Advance()) {
276 if (IsEvictable(it->GetID(), it->GetValue()) && 305 if (IsEvictable(it->GetID(), it->GetValue()) &&
277 base::GetFileSize(GetCacheFilePath(it->GetID()), &cache_size)) { 306 base::GetFileSize(GetCacheFilePath(it->GetID()), &cache_size)) {
278 DCHECK_GE(cache_size, 0); 307 DCHECK_GE(cache_size, 0);
279 evictable_cache_size += cache_size; 308 evictable_cache_size += cache_size;
280 } 309 }
281 } 310 }
282 311
283 if (it->HasError()) 312 if (it->HasError())
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 entry.mutable_file_info()->set_last_modified( 897 entry.mutable_file_info()->set_last_modified(
869 base::Time::Now().ToInternalValue()); 898 base::Time::Now().ToInternalValue());
870 error = storage_->PutEntry(entry); 899 error = storage_->PutEntry(entry);
871 if (error != FILE_ERROR_OK) { 900 if (error != FILE_ERROR_OK) {
872 LOG(ERROR) << "Failed to put entry: " << id << ", " 901 LOG(ERROR) << "Failed to put entry: " << id << ", "
873 << FileErrorToString(error); 902 << FileErrorToString(error);
874 } 903 }
875 } 904 }
876 905
877 bool FileCache::IsEvictable(const std::string& id, const ResourceEntry& entry) { 906 bool FileCache::IsEvictable(const std::string& id, const ResourceEntry& entry) {
878 return entry.file_specific_info().has_cache_state() && 907 return IsPresent(entry) &&
879 !entry.file_specific_info().cache_state().is_pinned() && 908 !entry.file_specific_info().cache_state().is_pinned() &&
880 !entry.file_specific_info().cache_state().is_dirty() && 909 !entry.file_specific_info().cache_state().is_dirty() &&
881 !mounted_files_.count(id); 910 !mounted_files_.count(id);
882 } 911 }
883 912
884 } // namespace internal 913 } // namespace internal
885 } // namespace drive 914 } // namespace drive
OLDNEW
« 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