Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4041)

Unified Diff: chrome/browser/win/jumplist_file_util.h

Issue 2752063002: Remove JumpListIconsOld directory and set upper limit for delete attempts (Closed)
Patch Set: Add jumplist_util_file* and unit tests, plus address other comments. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/win/jumplist_file_util.h
diff --git a/chrome/browser/win/jumplist_file_util.h b/chrome/browser/win/jumplist_file_util.h
new file mode 100644
index 0000000000000000000000000000000000000000..b1b6c56774afc976c6ebc5f5c191d8e8aa3266aa
--- /dev/null
+++ b/chrome/browser/win/jumplist_file_util.h
@@ -0,0 +1,93 @@
+// Copyright (c) 2017 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.
+
+#ifndef CHROME_BROWSER_WIN_JUMPLIST_FILE_UTIL_H_
+#define CHROME_BROWSER_WIN_JUMPLIST_FILE_UTIL_H_
+
+#include "base/files/file_path.h"
+
+// Maximum number of icon files allowed to delete per jumplist update
+const int kMaxIconFilesDeletedPerUpdate = 100;
+
+// Folder delete status enumeration, used in Delete* methods below.
+// This is used for UMA. Do not delete entries, and keep in sync with
+// histograms.xml.
+enum FolderDeleteResult {
+ SUCCEED = 0,
+ // File name's length exceeds MAX_PATH. This won't happen.
+ FAIL_INVALID_FILE_PATH,
+ // JumpListIcons{,Old} directories are read-only. This may heppen.
+ FAIL_READ_ONLY_DIRECTORY,
+ // Since JumpListIcons{,Old} are directories, this won't happen.
+ FAIL_DELETE_SINGLE_FILE,
+ // JumpListIcons{,Old} should not have sub-directories, so this won't happen.
+ // If this happens, the root cause must be found.
+ FAIL_SUBDIRECTORY_EXISTS,
+ // Delete maximum files allowed succeeds. However, in the process of deleting
+ // these files, it fails to delete some other files. This may happen.
+ FAIL_DELETE_MAX_FILE_PERFECTLY,
+ // Fail to delete maximum files allowed when the maximum attempts allowed
+ // have been used. This may heppen.
+ FAIL_DELETE_MAX_FILES_ANYWAY,
+ // Add new items before this one, always keep this one at the end.
+ END
+};
+
+// This method is similar to base::DeleteFileRecursive in
+// file_util_win.cc with the following differences.
+// 1) It just deletes the files in |path|. All sub-directories in |path| are
+// untouched.
+// 2) It has a boolean input parameter |has_upper_limit|.
+// i) When it is set to true, this method returns false when:
+// - the files deleted exceeds |kMaxIconFilesDeletedPerUpdate| in |path|;
+// - the files failed to delete plus the number of sub-directories found
+// exceeds |kMaxIconFilesDeletedPerUpdate| in |path|.
+// ii) When it is set to false, all files under |path| are deleted. No
+// sub-directories are deleted though.
+// 3) Failure cause is recored in |delete_status|.
+bool DeleteFiles(const base::FilePath& path,
+ const base::FilePath::StringType& pattern,
+ 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.
+ FolderDeleteResult* delete_status);
+
+// This method is similar to base::DeleteFile in file_util_win.cc
+// with the following differences.
+// 1) It just deletes the files in |path| if it is a directory. All
+// sub-directories in |path| are untouched.
+// 2) If |path| is a directory, it won't be deleted even if all its contents are
+// deleted successfully.
+// 3) It has a boolean input parameter |has_upper_limit|.
+// i) When it is set to true, this method returns false when:
+// - the files deleted exceeds |kMaxIconFilesDeletedPerUpdate| in |path|;
+// - the files failed to delete plus the number of sub-directories found
+// exceeds |kMaxIconFilesDeletedPerUpdate| in |path|.
+// ii) When it is set to false, all files under |path| are deleted. No
+// sub-directories are deleted though.
+// 4) Failure cause is recored in |delete_status|.
+bool DeleteDirectoryContent(const base::FilePath& path,
+ bool has_upper_limit,
+ FolderDeleteResult* delete_status);
+
+// This method is similar to base::DeleteFile in file_util_win.cc
+// with the following differences.
+// 1) It just deletes the files in |path|. All sub-directories in |path| are
+// untouched.
+// 2) It runs in the asynchronous manner, so there is no return value.
+// 3) It has a boolean input parameter |has_upper_limit|.
+// i) When it is set to true, this method returns false when:
+// - the files deleted exceeds |kMaxIconFilesDeletedPerUpdate| in |path|;
+// - the files failed to delete plus the number of sub-directories found
+// exceeds |kMaxIconFilesDeletedPerUpdate| in |path|.
+// ii) When it is set to false, all files under |path| are deleted. No
+// sub-directories are deleted though.
+// 4) Failure cause is recored in |delete_status|.
+void DeleteDirectory(const base::FilePath& path,
+ bool has_upper_limit,
+ FolderDeleteResult* delete_status);
+
+// Deletes the directory at |path| and records the result to UMA.
+void DeleteDirectoryAndLogResults(const base::FilePath& path,
+ bool has_upper_limit);
+
+#endif // CHROME_BROWSER_WIN_JUMPLIST_FILE_UTIL_H_

Powered by Google App Engine
This is Rietveld 408576698