Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / remove_stale_cache_files.cc
blob533e9fb42428d0fc777b340c027cb4ba2873ec8d
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 "base/logging.h"
8 #include "chrome/browser/chromeos/drive/drive.pb.h"
9 #include "chrome/browser/chromeos/drive/file_cache.h"
10 #include "chrome/browser/chromeos/drive/resource_metadata.h"
12 namespace drive {
13 namespace internal {
15 void RemoveStaleCacheFiles(FileCache* cache,
16 ResourceMetadata* resource_metadata) {
17 scoped_ptr<ResourceMetadata::Iterator> it = resource_metadata->GetIterator();
18 for (; !it->IsAtEnd(); it->Advance()) {
19 const ResourceEntry& entry = it->GetValue();
20 const FileCacheEntry& cache_state =
21 entry.file_specific_info().cache_state();
22 // Stale = not dirty but the MD5 does not match.
23 if (!cache_state.is_dirty() &&
24 cache_state.md5() != entry.file_specific_info().md5()) {
25 FileError error = cache->Remove(it->GetID());
26 LOG_IF(WARNING, error != FILE_ERROR_OK)
27 << "Failed to remove a stale cache file. resource_id: "
28 << it->GetID();
33 } // namespace internal
34 } // namespace drive