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 "chrome/browser/chromeos/drive/remove_stale_cache_files.h" | 5 #include "chrome/browser/chromeos/drive/remove_stale_cache_files.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "chrome/browser/chromeos/drive/drive.pb.h" | 12 #include "chrome/browser/chromeos/drive/drive.pb.h" |
13 #include "chrome/browser/chromeos/drive/file_cache.h" | 13 #include "chrome/browser/chromeos/drive/file_cache.h" |
14 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 14 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
15 | 15 |
16 namespace drive { | 16 namespace drive { |
17 namespace internal { | 17 namespace internal { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // Collects resource IDs of stale cache files. | 21 // Collects resource IDs of stale cache files. |
22 void CollectStaleCacheFiles( | 22 void CollectStaleCacheFiles( |
23 ResourceMetadata* resource_metadata, | 23 ResourceMetadata* resource_metadata, |
24 std::vector<std::string>* out_resource_ids_to_be_removed, | 24 std::vector<std::string>* out_resource_ids_to_be_removed, |
25 const std::string& resource_id, | 25 const std::string& resource_id, |
26 const FileCacheEntry& cache_entry) { | 26 const FileCacheEntry& cache_entry) { |
27 ResourceEntry entry; | 27 ResourceEntry entry; |
28 FileError error = resource_metadata->GetResourceEntryById( | 28 FileError error = resource_metadata->GetResourceEntryById( |
29 resource_id, NULL, &entry); | 29 resource_id, &entry); |
30 | 30 |
31 // The entry is not found or the MD5 does not match. | 31 // The entry is not found or the MD5 does not match. |
32 if (error != FILE_ERROR_OK || | 32 if (error != FILE_ERROR_OK || |
33 cache_entry.md5() != entry.file_specific_info().file_md5()) | 33 cache_entry.md5() != entry.file_specific_info().file_md5()) |
34 out_resource_ids_to_be_removed->push_back(resource_id); | 34 out_resource_ids_to_be_removed->push_back(resource_id); |
35 } | 35 } |
36 | 36 |
37 } // namespace | 37 } // namespace |
38 | 38 |
39 void RemoveStaleCacheFiles(FileCache* cache, | 39 void RemoveStaleCacheFiles(FileCache* cache, |
40 ResourceMetadata* resource_metadata) { | 40 ResourceMetadata* resource_metadata) { |
41 std::vector<std::string> resource_ids_to_be_removed; | 41 std::vector<std::string> resource_ids_to_be_removed; |
42 cache->Iterate(base::Bind(&CollectStaleCacheFiles, | 42 cache->Iterate(base::Bind(&CollectStaleCacheFiles, |
43 resource_metadata, | 43 resource_metadata, |
44 &resource_ids_to_be_removed)); | 44 &resource_ids_to_be_removed)); |
45 | 45 |
46 for (size_t i = 0; i < resource_ids_to_be_removed.size(); ++i) { | 46 for (size_t i = 0; i < resource_ids_to_be_removed.size(); ++i) { |
47 const std::string& resource_id = resource_ids_to_be_removed[i]; | 47 const std::string& resource_id = resource_ids_to_be_removed[i]; |
48 FileError error = cache->Remove(resource_id); | 48 FileError error = cache->Remove(resource_id); |
49 LOG_IF(WARNING, error != FILE_ERROR_OK) | 49 LOG_IF(WARNING, error != FILE_ERROR_OK) |
50 << "Failed to remove a stale cache file. resource_id: " << resource_id; | 50 << "Failed to remove a stale cache file. resource_id: " << resource_id; |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 } // namespace internal | 54 } // namespace internal |
55 } // namespace drive | 55 } // namespace drive |
OLD | NEW |