Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / remove_stale_cache_files.cc
blob56296ca0fc91aedca1ee26560f13e26653039892
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"
7 #include <string>
8 #include <vector>
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"
16 namespace drive {
17 namespace internal {
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()) {
25 ResourceEntry entry;
26 FileError error = resource_metadata->GetResourceEntryById(it->GetID(),
27 &entry);
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: "
35 << it->GetID();
40 } // namespace internal
41 } // namespace drive