Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2017 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_WIN_JUMPLIST_FILE_UTIL_H_ | |
| 6 #define CHROME_BROWSER_WIN_JUMPLIST_FILE_UTIL_H_ | |
| 7 | |
| 8 #include "base/files/file_path.h" | |
| 9 | |
| 10 // Maximum number of icon files allowed to delete per jumplist update | |
| 11 const int kMaxIconFilesDeletedPerUpdate = 100; | |
| 12 | |
| 13 // Folder delete status enumeration, used in Delete* methods below. | |
| 14 // This is used for UMA. Do not delete entries, and keep in sync with | |
| 15 // histograms.xml. | |
| 16 enum FolderDeleteResult { | |
| 17 SUCCEED = 0, | |
| 18 // File name's length exceeds MAX_PATH. This won't happen. | |
| 19 FAIL_INVALID_FILE_PATH, | |
| 20 // JumpListIcons{,Old} directories are read-only. This may heppen. | |
| 21 FAIL_READ_ONLY_DIRECTORY, | |
| 22 // Since JumpListIcons{,Old} are directories, this won't happen. | |
| 23 FAIL_DELETE_SINGLE_FILE, | |
| 24 // JumpListIcons{,Old} should not have sub-directories, so this won't happen. | |
| 25 // If this happens, the root cause must be found. | |
| 26 FAIL_SUBDIRECTORY_EXISTS, | |
| 27 // Delete maximum files allowed succeeds. However, in the process of deleting | |
| 28 // these files, it fails to delete some other files. This may happen. | |
| 29 FAIL_DELETE_MAX_FILE_PERFECTLY, | |
| 30 // Fail to delete maximum files allowed when the maximum attempts allowed | |
| 31 // have been used. This may heppen. | |
| 32 FAIL_DELETE_MAX_FILES_ANYWAY, | |
| 33 // Add new items before this one, always keep this one at the end. | |
| 34 END | |
| 35 }; | |
| 36 | |
| 37 // This method is similar to base::DeleteFileRecursive in | |
| 38 // file_util_win.cc with the following differences. | |
| 39 // 1) It just deletes the files in |path|. All sub-directories in |path| are | |
| 40 // untouched. | |
| 41 // 2) It has a boolean input parameter |has_upper_limit|. | |
| 42 // i) When it is set to true, this method returns false when: | |
| 43 // - the files deleted exceeds |kMaxIconFilesDeletedPerUpdate| in |path|; | |
| 44 // - the files failed to delete plus the number of sub-directories found | |
| 45 // exceeds |kMaxIconFilesDeletedPerUpdate| in |path|. | |
| 46 // ii) When it is set to false, all files under |path| are deleted. No | |
| 47 // sub-directories are deleted though. | |
| 48 // 3) Failure cause is recored in |delete_status|. | |
| 49 bool DeleteFiles(const base::FilePath& path, | |
| 50 const base::FilePath::StringType& pattern, | |
| 51 bool has_upper_limit, | |
|
grt (UTC plus 2)
2017/03/22 12:07:22
it doesn't look like any callers pass false for ha
chengx
2017/03/22 21:16:36
It is not needed and has been removed.
| |
| 52 FolderDeleteResult* delete_status); | |
| 53 | |
| 54 // This method is similar to base::DeleteFile in file_util_win.cc | |
| 55 // with the following differences. | |
| 56 // 1) It just deletes the files in |path| if it is a directory. All | |
| 57 // sub-directories in |path| are untouched. | |
| 58 // 2) If |path| is a directory, it won't be deleted even if all its contents are | |
| 59 // deleted successfully. | |
| 60 // 3) It has a boolean input parameter |has_upper_limit|. | |
| 61 // i) When it is set to true, this method returns false when: | |
| 62 // - the files deleted exceeds |kMaxIconFilesDeletedPerUpdate| in |path|; | |
| 63 // - the files failed to delete plus the number of sub-directories found | |
| 64 // exceeds |kMaxIconFilesDeletedPerUpdate| in |path|. | |
| 65 // ii) When it is set to false, all files under |path| are deleted. No | |
| 66 // sub-directories are deleted though. | |
| 67 // 4) Failure cause is recored in |delete_status|. | |
| 68 bool DeleteDirectoryContent(const base::FilePath& path, | |
| 69 bool has_upper_limit, | |
| 70 FolderDeleteResult* delete_status); | |
| 71 | |
| 72 // This method is similar to base::DeleteFile in file_util_win.cc | |
| 73 // with the following differences. | |
| 74 // 1) It just deletes the files in |path|. All sub-directories in |path| are | |
| 75 // untouched. | |
| 76 // 2) It runs in the asynchronous manner, so there is no return value. | |
| 77 // 3) It has a boolean input parameter |has_upper_limit|. | |
| 78 // i) When it is set to true, this method returns false when: | |
| 79 // - the files deleted exceeds |kMaxIconFilesDeletedPerUpdate| in |path|; | |
| 80 // - the files failed to delete plus the number of sub-directories found | |
| 81 // exceeds |kMaxIconFilesDeletedPerUpdate| in |path|. | |
| 82 // ii) When it is set to false, all files under |path| are deleted. No | |
| 83 // sub-directories are deleted though. | |
| 84 // 4) Failure cause is recored in |delete_status|. | |
| 85 void DeleteDirectory(const base::FilePath& path, | |
| 86 bool has_upper_limit, | |
| 87 FolderDeleteResult* delete_status); | |
| 88 | |
| 89 // Deletes the directory at |path| and records the result to UMA. | |
| 90 void DeleteDirectoryAndLogResults(const base::FilePath& path, | |
| 91 bool has_upper_limit); | |
| 92 | |
| 93 #endif // CHROME_BROWSER_WIN_JUMPLIST_FILE_UTIL_H_ | |
| OLD | NEW |