| OLD | NEW |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 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 | 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/win/jumplist_file_util.h" | 5 #include "chrome/browser/win/jumplist_file_util.h" |
| 6 | 6 |
| 7 #include <Shlwapi.h> | |
| 8 #include <windows.h> | 7 #include <windows.h> |
| 9 | 8 |
| 10 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
| 10 #include "base/files/file_util.h" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 13 | 13 |
| 14 FolderDeleteResult DeleteFiles(const base::FilePath& path, | 14 FolderDeleteResult DeleteFiles(const base::FilePath& path, |
| 15 const base::FilePath::StringType& pattern, | 15 const base::FilePath::StringType& pattern, |
| 16 int max_file_deleted) { | 16 int max_file_deleted) { |
| 17 int success_count = 0; | 17 int success_count = 0; |
| 18 int failure_count = 0; | 18 int failure_count = 0; |
| 19 FolderDeleteResult delete_status = SUCCEED; | 19 FolderDeleteResult delete_status = SUCCEED; |
| 20 | 20 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 FolderDeleteResult DeleteDirectory(const base::FilePath& path, | 93 FolderDeleteResult DeleteDirectory(const base::FilePath& path, |
| 94 int max_file_deleted) { | 94 int max_file_deleted) { |
| 95 base::ThreadRestrictions::AssertIOAllowed(); | 95 base::ThreadRestrictions::AssertIOAllowed(); |
| 96 // Delete at most |max_file_deleted| files in |path|. | 96 // Delete at most |max_file_deleted| files in |path|. |
| 97 FolderDeleteResult delete_status = | 97 FolderDeleteResult delete_status = |
| 98 DeleteDirectoryContent(path, max_file_deleted); | 98 DeleteDirectoryContent(path, max_file_deleted); |
| 99 // Since DeleteDirectoryContent() can only delete at most |max_file_deleted| | 99 // Since DeleteDirectoryContent() can only delete at most |max_file_deleted| |
| 100 // files, its return value cannot indicate if |path| is empty or not. | 100 // files, its return value cannot indicate if |path| is empty or not. |
| 101 // Instead, use PathIsDirectoryEmpty to check if |path| is empty and remove it | 101 // Instead, use PathIsDirectoryEmpty to check if |path| is empty and remove it |
| 102 // if it is. | 102 // if it is. |
| 103 if (::PathIsDirectoryEmpty(path.value().c_str()) && | 103 if (base::IsDirectoryEmpty(path) && |
| 104 !::RemoveDirectory(path.value().c_str())) { | 104 !::RemoveDirectory(path.value().c_str())) { |
| 105 delete_status = FAIL_REMOVE_RAW_DIRECTORY; | 105 delete_status = FAIL_REMOVE_RAW_DIRECTORY; |
| 106 } | 106 } |
| 107 return delete_status; | 107 return delete_status; |
| 108 } | 108 } |
| 109 | 109 |
| 110 void DeleteDirectoryAndLogResults(const base::FilePath& path, | 110 void DeleteDirectoryAndLogResults(const base::FilePath& path, |
| 111 int max_file_deleted) { | 111 int max_file_deleted) { |
| 112 FolderDeleteResult delete_status = DeleteDirectory(path, max_file_deleted); | 112 FolderDeleteResult delete_status = DeleteDirectory(path, max_file_deleted); |
| 113 UMA_HISTOGRAM_ENUMERATION("WinJumplist.DeleteStatusJumpListIconsOld", | 113 UMA_HISTOGRAM_ENUMERATION("WinJumplist.DeleteStatusJumpListIconsOld", |
| 114 delete_status, END); | 114 delete_status, END); |
| 115 |
| 116 DirectoryStatus dir_status = NON_EXIST; |
| 117 if (base::DirectoryExists(path)) |
| 118 dir_status = base::IsDirectoryEmpty(path) ? EMPTY : NON_EMPTY; |
| 119 |
| 120 UMA_HISTOGRAM_ENUMERATION("WinJumplist.DirectoryStatusJumpListIconsOld", |
| 121 dir_status, DIRECTORY_STATUS_END); |
| 115 } | 122 } |
| OLD | NEW |