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/file_cache.h" | 5 #include "chrome/browser/chromeos/drive/file_cache.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_enumerator.h" | |
11 #include "base/logging.h" | 10 #include "base/logging.h" |
12 #include "base/string_util.h" | 11 #include "base/string_util.h" |
13 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
14 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
15 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
16 #include "chrome/browser/chromeos/drive/drive.pb.h" | 15 #include "chrome/browser/chromeos/drive/drive.pb.h" |
17 #include "chrome/browser/chromeos/drive/file_cache_metadata.h" | 16 #include "chrome/browser/chromeos/drive/file_cache_metadata.h" |
18 #include "chrome/browser/chromeos/drive/file_cache_observer.h" | 17 #include "chrome/browser/chromeos/drive/file_cache_observer.h" |
19 #include "chrome/browser/chromeos/drive/file_system_util.h" | 18 #include "chrome/browser/chromeos/drive/file_system_util.h" |
20 #include "chrome/browser/google_apis/task_util.h" | 19 #include "chrome/browser/google_apis/task_util.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 file_util::FILE_PERMISSION_EXECUTE_BY_GROUP | | 55 file_util::FILE_PERMISSION_EXECUTE_BY_GROUP | |
57 file_util::FILE_PERMISSION_EXECUTE_BY_OTHERS); | 56 file_util::FILE_PERMISSION_EXECUTE_BY_OTHERS); |
58 | 57 |
59 return true; | 58 return true; |
60 } | 59 } |
61 | 60 |
62 // Remove all files under the given directory, non-recursively. | 61 // Remove all files under the given directory, non-recursively. |
63 // Do not remove recursively as we don't want to touch <gcache>/tmp/downloads, | 62 // Do not remove recursively as we don't want to touch <gcache>/tmp/downloads, |
64 // which is used for user initiated downloads like "Save As" | 63 // which is used for user initiated downloads like "Save As" |
65 void RemoveAllFiles(const base::FilePath& directory) { | 64 void RemoveAllFiles(const base::FilePath& directory) { |
66 base::FileEnumerator enumerator(directory, false /* recursive */, | 65 using file_util::FileEnumerator; |
67 base::FileEnumerator::FILES); | 66 |
| 67 FileEnumerator enumerator(directory, false /* recursive */, |
| 68 FileEnumerator::FILES); |
68 for (base::FilePath file_path = enumerator.Next(); !file_path.empty(); | 69 for (base::FilePath file_path = enumerator.Next(); !file_path.empty(); |
69 file_path = enumerator.Next()) { | 70 file_path = enumerator.Next()) { |
70 DVLOG(1) << "Removing " << file_path.value(); | 71 DVLOG(1) << "Removing " << file_path.value(); |
71 if (!file_util::Delete(file_path, false /* recursive */)) | 72 if (!file_util::Delete(file_path, false /* recursive */)) |
72 LOG(WARNING) << "Failed to delete " << file_path.value(); | 73 LOG(WARNING) << "Failed to delete " << file_path.value(); |
73 } | 74 } |
74 } | 75 } |
75 | 76 |
76 // Deletes the symlink. | 77 // Deletes the symlink. |
77 void DeleteSymlink(const base::FilePath& symlink_path) { | 78 void DeleteSymlink(const base::FilePath& symlink_path) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // Deletes all files that match |path_to_delete_pattern| except for | 124 // Deletes all files that match |path_to_delete_pattern| except for |
124 // |path_to_keep| on blocking pool. | 125 // |path_to_keep| on blocking pool. |
125 // If |path_to_keep| is empty, all files in |path_to_delete_pattern| are | 126 // If |path_to_keep| is empty, all files in |path_to_delete_pattern| are |
126 // deleted. | 127 // deleted. |
127 void DeleteFilesSelectively(const base::FilePath& path_to_delete_pattern, | 128 void DeleteFilesSelectively(const base::FilePath& path_to_delete_pattern, |
128 const base::FilePath& path_to_keep) { | 129 const base::FilePath& path_to_keep) { |
129 // Enumerate all files in directory of |path_to_delete_pattern| that match | 130 // Enumerate all files in directory of |path_to_delete_pattern| that match |
130 // base name of |path_to_delete_pattern|. | 131 // base name of |path_to_delete_pattern|. |
131 // If a file is not |path_to_keep|, delete it. | 132 // If a file is not |path_to_keep|, delete it. |
132 bool success = true; | 133 bool success = true; |
133 base::FileEnumerator enumerator(path_to_delete_pattern.DirName(), | 134 file_util::FileEnumerator enumerator( |
| 135 path_to_delete_pattern.DirName(), |
134 false, // not recursive | 136 false, // not recursive |
135 base::FileEnumerator::FILES | base::FileEnumerator::SHOW_SYM_LINKS, | 137 file_util::FileEnumerator::FILES | |
| 138 file_util::FileEnumerator::SHOW_SYM_LINKS, |
136 path_to_delete_pattern.BaseName().value()); | 139 path_to_delete_pattern.BaseName().value()); |
137 for (base::FilePath current = enumerator.Next(); !current.empty(); | 140 for (base::FilePath current = enumerator.Next(); !current.empty(); |
138 current = enumerator.Next()) { | 141 current = enumerator.Next()) { |
139 // If |path_to_keep| is not empty and same as current, don't delete it. | 142 // If |path_to_keep| is not empty and same as current, don't delete it. |
140 if (!path_to_keep.empty() && current == path_to_keep) | 143 if (!path_to_keep.empty() && current == path_to_keep) |
141 continue; | 144 continue; |
142 | 145 |
143 success = file_util::Delete(current, false); | 146 success = file_util::Delete(current, false); |
144 if (!success) | 147 if (!success) |
145 DVLOG(1) << "Error deleting " << current.value(); | 148 DVLOG(1) << "Error deleting " << current.value(); |
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 } | 1232 } |
1230 | 1233 |
1231 // static | 1234 // static |
1232 FileCache::CacheSubDirectoryType FileCache::GetSubDirectoryType( | 1235 FileCache::CacheSubDirectoryType FileCache::GetSubDirectoryType( |
1233 const FileCacheEntry& cache_entry) { | 1236 const FileCacheEntry& cache_entry) { |
1234 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1237 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
1235 } | 1238 } |
1236 | 1239 |
1237 } // namespace internal | 1240 } // namespace internal |
1238 } // namespace drive | 1241 } // namespace drive |
OLD | NEW |