summaryrefslogtreecommitdiffstats
path: root/components/drive/remove_stale_cache_files.cc
diff options
context:
space:
mode:
authormsramek <msramek@chromium.org>2016-01-06 03:59:02 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-06 12:00:09 +0000
commit4cfdf21becf7b98e3d18d8edad269c90807dda6c (patch)
treecccac684998ab0e1676ef272334b1059529b3fb5 /components/drive/remove_stale_cache_files.cc
parent8e197f9b8c21c25be7fcda111f89e640162cc196 (diff)
downloadchromium_src-4cfdf21becf7b98e3d18d8edad269c90807dda6c.zip
chromium_src-4cfdf21becf7b98e3d18d8edad269c90807dda6c.tar.gz
chromium_src-4cfdf21becf7b98e3d18d8edad269c90807dda6c.tar.bz2
Revert "Compile FileCache related drive components only on Chrome OS."
This reverts commit 1409407a93075f8ef9e894455ca75059ee68f99b. See crbug.com/574709 for more details. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true TBR=yawano@chromium.org,thestig@chromium.org,hashimoto@chromium.org,satorux@chromium.org BUG=574709,533750 Review URL: https://codereview.chromium.org/1561103002 Cr-Commit-Position: refs/heads/master@{#367814}
Diffstat (limited to 'components/drive/remove_stale_cache_files.cc')
-rw-r--r--components/drive/remove_stale_cache_files.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/components/drive/remove_stale_cache_files.cc b/components/drive/remove_stale_cache_files.cc
new file mode 100644
index 0000000..93cab01
--- /dev/null
+++ b/components/drive/remove_stale_cache_files.cc
@@ -0,0 +1,34 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/drive/remove_stale_cache_files.h"
+
+#include "base/logging.h"
+#include "components/drive/drive.pb.h"
+#include "components/drive/file_cache.h"
+#include "components/drive/resource_metadata.h"
+
+namespace drive {
+namespace internal {
+
+void RemoveStaleCacheFiles(FileCache* cache,
+ ResourceMetadata* resource_metadata) {
+ scoped_ptr<ResourceMetadata::Iterator> it = resource_metadata->GetIterator();
+ for (; !it->IsAtEnd(); it->Advance()) {
+ const ResourceEntry& entry = it->GetValue();
+ const FileCacheEntry& cache_state =
+ entry.file_specific_info().cache_state();
+ // Stale = not dirty but the MD5 does not match.
+ if (!cache_state.is_dirty() &&
+ cache_state.md5() != entry.file_specific_info().md5()) {
+ FileError error = cache->Remove(it->GetID());
+ LOG_IF(WARNING, error != FILE_ERROR_OK)
+ << "Failed to remove a stale cache file. resource_id: "
+ << it->GetID();
+ }
+ }
+}
+
+} // namespace internal
+} // namespace drive