| 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" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 12 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 13 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
| 14 #include "base/task_runner_util.h" | 15 #include "base/task_runner_util.h" |
| 15 #include "chrome/browser/chromeos/drive/drive.pb.h" | 16 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 16 #include "chrome/browser/chromeos/drive/file_cache_metadata.h" | 17 #include "chrome/browser/chromeos/drive/file_cache_metadata.h" |
| 17 #include "chrome/browser/chromeos/drive/file_cache_observer.h" | 18 #include "chrome/browser/chromeos/drive/file_cache_observer.h" |
| 18 #include "chrome/browser/chromeos/drive/file_system_util.h" | 19 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 19 #include "chrome/browser/google_apis/task_util.h" | 20 #include "chrome/browser/google_apis/task_util.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 file_util::FILE_PERMISSION_EXECUTE_BY_GROUP | | 55 file_util::FILE_PERMISSION_EXECUTE_BY_GROUP | |
| 55 file_util::FILE_PERMISSION_EXECUTE_BY_OTHERS); | 56 file_util::FILE_PERMISSION_EXECUTE_BY_OTHERS); |
| 56 | 57 |
| 57 return true; | 58 return true; |
| 58 } | 59 } |
| 59 | 60 |
| 60 // Remove all files under the given directory, non-recursively. | 61 // Remove all files under the given directory, non-recursively. |
| 61 // 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, |
| 62 // which is used for user initiated downloads like "Save As" | 63 // which is used for user initiated downloads like "Save As" |
| 63 void RemoveAllFiles(const base::FilePath& directory) { | 64 void RemoveAllFiles(const base::FilePath& directory) { |
| 64 using file_util::FileEnumerator; | 65 base::FileEnumerator enumerator(directory, false /* recursive */, |
| 65 | 66 base::FileEnumerator::FILES); |
| 66 FileEnumerator enumerator(directory, false /* recursive */, | |
| 67 FileEnumerator::FILES); | |
| 68 for (base::FilePath file_path = enumerator.Next(); !file_path.empty(); | 67 for (base::FilePath file_path = enumerator.Next(); !file_path.empty(); |
| 69 file_path = enumerator.Next()) { | 68 file_path = enumerator.Next()) { |
| 70 DVLOG(1) << "Removing " << file_path.value(); | 69 DVLOG(1) << "Removing " << file_path.value(); |
| 71 if (!file_util::Delete(file_path, false /* recursive */)) | 70 if (!file_util::Delete(file_path, false /* recursive */)) |
| 72 LOG(WARNING) << "Failed to delete " << file_path.value(); | 71 LOG(WARNING) << "Failed to delete " << file_path.value(); |
| 73 } | 72 } |
| 74 } | 73 } |
| 75 | 74 |
| 76 // Moves the file. | 75 // Moves the file. |
| 77 bool MoveFile(const base::FilePath& source_path, | 76 bool MoveFile(const base::FilePath& source_path, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 100 // Deletes all files that match |path_to_delete_pattern| except for | 99 // Deletes all files that match |path_to_delete_pattern| except for |
| 101 // |path_to_keep| on blocking pool. | 100 // |path_to_keep| on blocking pool. |
| 102 // If |path_to_keep| is empty, all files in |path_to_delete_pattern| are | 101 // If |path_to_keep| is empty, all files in |path_to_delete_pattern| are |
| 103 // deleted. | 102 // deleted. |
| 104 void DeleteFilesSelectively(const base::FilePath& path_to_delete_pattern, | 103 void DeleteFilesSelectively(const base::FilePath& path_to_delete_pattern, |
| 105 const base::FilePath& path_to_keep) { | 104 const base::FilePath& path_to_keep) { |
| 106 // Enumerate all files in directory of |path_to_delete_pattern| that match | 105 // Enumerate all files in directory of |path_to_delete_pattern| that match |
| 107 // base name of |path_to_delete_pattern|. | 106 // base name of |path_to_delete_pattern|. |
| 108 // If a file is not |path_to_keep|, delete it. | 107 // If a file is not |path_to_keep|, delete it. |
| 109 bool success = true; | 108 bool success = true; |
| 110 file_util::FileEnumerator enumerator( | 109 base::FileEnumerator enumerator( |
| 111 path_to_delete_pattern.DirName(), | 110 path_to_delete_pattern.DirName(), |
| 112 false, // not recursive | 111 false, // not recursive |
| 113 file_util::FileEnumerator::FILES, | 112 base::FileEnumerator::FILES, |
| 114 path_to_delete_pattern.BaseName().value()); | 113 path_to_delete_pattern.BaseName().value()); |
| 115 for (base::FilePath current = enumerator.Next(); !current.empty(); | 114 for (base::FilePath current = enumerator.Next(); !current.empty(); |
| 116 current = enumerator.Next()) { | 115 current = enumerator.Next()) { |
| 117 // If |path_to_keep| is not empty and same as current, don't delete it. | 116 // If |path_to_keep| is not empty and same as current, don't delete it. |
| 118 if (!path_to_keep.empty() && current == path_to_keep) | 117 if (!path_to_keep.empty() && current == path_to_keep) |
| 119 continue; | 118 continue; |
| 120 | 119 |
| 121 success = file_util::Delete(current, false); | 120 success = file_util::Delete(current, false); |
| 122 if (!success) | 121 if (!success) |
| 123 DVLOG(1) << "Error deleting " << current.value(); | 122 DVLOG(1) << "Error deleting " << current.value(); |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 } | 1105 } |
| 1107 | 1106 |
| 1108 // static | 1107 // static |
| 1109 FileCache::CacheSubDirectoryType FileCache::GetSubDirectoryType( | 1108 FileCache::CacheSubDirectoryType FileCache::GetSubDirectoryType( |
| 1110 const FileCacheEntry& cache_entry) { | 1109 const FileCacheEntry& cache_entry) { |
| 1111 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1110 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
| 1112 } | 1111 } |
| 1113 | 1112 |
| 1114 } // namespace internal | 1113 } // namespace internal |
| 1115 } // namespace drive | 1114 } // namespace drive |
| OLD | NEW |