Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 if (base::DeleteFile(path, false /* recursive */)) | 257 if (base::DeleteFile(path, false /* recursive */)) |
| 258 evicted_cache_size += cache_info.first.size; | 258 evicted_cache_size += cache_info.first.size; |
| 259 | 259 |
| 260 ++iter; | 260 ++iter; |
| 261 } | 261 } |
| 262 | 262 |
| 263 // Check the disk space again. | 263 // Check the disk space again. |
| 264 return GetAvailableSpace() >= num_bytes; | 264 return GetAvailableSpace() >= num_bytes; |
| 265 } | 265 } |
| 266 | 266 |
| 267 uint64_t FileCache::CalculateEvictableCacheSize() { | 267 int64_t FileCache::CalculateCacheSize() { |
| 268 AssertOnSequencedWorkerPool(); | 268 AssertOnSequencedWorkerPool(); |
| 269 | 269 |
| 270 uint64_t evictable_cache_size = 0; | 270 int64_t total_cache_size = 0; |
| 271 int64_t cache_size = 0; | 271 int64_t cache_size = 0; |
| 272 | 272 |
| 273 std::unique_ptr<ResourceMetadataStorage::Iterator> it = | 273 std::unique_ptr<ResourceMetadataStorage::Iterator> it = |
| 274 storage_->GetIterator(); | |
| 275 for (; !it->IsAtEnd(); it->Advance()) { | |
| 276 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.
| |
| 277 DCHECK_GE(cache_size, 0); | |
| 278 total_cache_size += cache_size; | |
| 279 } | |
| 280 } | |
| 281 | |
| 282 if (it->HasError()) | |
| 283 return 0; | |
| 284 | |
| 285 return total_cache_size; | |
| 286 } | |
| 287 | |
| 288 int64_t FileCache::CalculateEvictableCacheSize() { | |
| 289 AssertOnSequencedWorkerPool(); | |
| 290 | |
| 291 int64_t evictable_cache_size = 0; | |
| 292 int64_t cache_size = 0; | |
| 293 | |
| 294 std::unique_ptr<ResourceMetadataStorage::Iterator> it = | |
| 274 storage_->GetIterator(); | 295 storage_->GetIterator(); |
| 275 for (; !it->IsAtEnd(); it->Advance()) { | 296 for (; !it->IsAtEnd(); it->Advance()) { |
| 276 if (IsEvictable(it->GetID(), it->GetValue()) && | 297 if (IsEvictable(it->GetID(), it->GetValue()) && |
| 277 base::GetFileSize(GetCacheFilePath(it->GetID()), &cache_size)) { | 298 base::GetFileSize(GetCacheFilePath(it->GetID()), &cache_size)) { |
| 278 DCHECK_GE(cache_size, 0); | 299 DCHECK_GE(cache_size, 0); |
| 279 evictable_cache_size += cache_size; | 300 evictable_cache_size += cache_size; |
| 280 } | 301 } |
| 281 } | 302 } |
| 282 | 303 |
| 283 if (it->HasError()) | 304 if (it->HasError()) |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 876 | 897 |
| 877 bool FileCache::IsEvictable(const std::string& id, const ResourceEntry& entry) { | 898 bool FileCache::IsEvictable(const std::string& id, const ResourceEntry& entry) { |
| 878 return entry.file_specific_info().has_cache_state() && | 899 return entry.file_specific_info().has_cache_state() && |
| 879 !entry.file_specific_info().cache_state().is_pinned() && | 900 !entry.file_specific_info().cache_state().is_pinned() && |
| 880 !entry.file_specific_info().cache_state().is_dirty() && | 901 !entry.file_specific_info().cache_state().is_dirty() && |
| 881 !mounted_files_.count(id); | 902 !mounted_files_.count(id); |
| 882 } | 903 } |
| 883 | 904 |
| 884 } // namespace internal | 905 } // namespace internal |
| 885 } // namespace drive | 906 } // namespace drive |
| OLD | NEW |