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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/drive/remove_stale_cache_files.h"
10 #include "base/bind.h"
11 #include "base/logging.h"
12 #include "chrome/browser/chromeos/drive/drive.pb.h"
13 #include "chrome/browser/chromeos/drive/file_cache.h"
14 #include "chrome/browser/chromeos/drive/resource_metadata.h"
19 void RemoveStaleCacheFiles(FileCache* cache,
20 ResourceMetadata* resource_metadata) {
21 std::vector<std::string> resource_ids_to_be_removed;
23 scoped_ptr<FileCache::Iterator> it = cache->GetIterator();
24 for (; !it->IsAtEnd(); it->Advance()) {
26 FileError error = resource_metadata->GetResourceEntryById(it->GetID(),
28 // Stale = the entry is not found, or not dirty but the MD5 does not match.
29 if (error != FILE_ERROR_OK ||
30 (!it->GetValue().is_dirty() &&
31 it->GetValue().md5() != entry.file_specific_info().md5())) {
32 FileError error = cache->Remove(it->GetID());
33 LOG_IF(WARNING, error != FILE_ERROR_OK)
34 << "Failed to remove a stale cache file. resource_id: "
40 } // namespace internal