Commit 99e0618b authored by huangs@chromium.org's avatar huangs@chromium.org

On uninstall, delete shortcuts first, and then remove directory only if empty.

Previously, ShellUtil::RemoveShortcuts() simply wipes out the entire directory if |location| is SHORTCUT_LOCATION_START_MENU or SHORTCUT_LOCATION_APP_SHORTCUTS, for efficiency. But we're now writing code to migrate shortcuts on the self-destruct flow. In this case, wiping out the directory would destroy our results. Therefore the new logic for deletion of these directories are:
- Use same code to remove Chrome-specific shortcuts (this is what's done for other diretories, e.g., Start Menu).
- If the directory becomes empty, then remove it; otherwise do nothing.

The side effect is that if user creates any non-Chrome shortcuts in these directories, then these shortcuts (and the containing directory) will persist after Chrome uninstall. I think this is a pretty normal behavior.

BUG=235857

Review URL: https://chromiumcodereview.appspot.com/22870004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217130 0039d316-1c4b-4281-b951-d872f2087c98
parent e1738e48
...@@ -1289,10 +1289,12 @@ bool BatchShortcutAction(const ShortcutFilterCallback& shortcut_filter, ...@@ -1289,10 +1289,12 @@ bool BatchShortcutAction(const ShortcutFilterCallback& shortcut_filter,
return success; return success;
} }
// Removes folder spsecified by {|location|, |dist|, |level|}. // If the folder specified by {|location|, |dist|, |level|} is empty, remove it.
bool RemoveShortcutFolder(ShellUtil::ShortcutLocation location, // Otherwise do nothing. Returns true on success, including the vacuous case
BrowserDistribution* dist, // where no deletion occurred because the directory is non-empty.
ShellUtil::ShellChange level) { bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location,
BrowserDistribution* dist,
ShellUtil::ShellChange level) {
// Explicitly whitelist locations, since accidental calls can be very harmful. // Explicitly whitelist locations, since accidental calls can be very harmful.
if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU && if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU &&
...@@ -1306,7 +1308,8 @@ bool RemoveShortcutFolder(ShellUtil::ShortcutLocation location, ...@@ -1306,7 +1308,8 @@ bool RemoveShortcutFolder(ShellUtil::ShortcutLocation location,
LOG(WARNING) << "Cannot find path at location " << location; LOG(WARNING) << "Cannot find path at location " << location;
return false; return false;
} }
if (!base::DeleteFile(shortcut_folder, true)) { if (file_util::IsDirectoryEmpty(shortcut_folder) &&
!base::DeleteFile(shortcut_folder, true)) {
LOG(ERROR) << "Cannot remove folder " << shortcut_folder.value(); LOG(ERROR) << "Cannot remove folder " << shortcut_folder.value();
return false; return false;
} }
...@@ -2029,8 +2032,13 @@ bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location, ...@@ -2029,8 +2032,13 @@ bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location,
switch (location) { switch (location) {
case SHORTCUT_LOCATION_START_MENU: // Falls through. case SHORTCUT_LOCATION_START_MENU: // Falls through.
case SHORTCUT_LOCATION_APP_SHORTCUTS: case SHORTCUT_LOCATION_APP_SHORTCUTS: {
return RemoveShortcutFolder(location, dist, level); bool delete_success =
BatchShortcutAction(base::Bind(&ShortcutOpDelete), location,
dist, level, target_exe);
bool rmdir_success = RemoveShortcutFolderIfEmpty(location, dist, level);
return delete_success && rmdir_success;
}
case SHORTCUT_LOCATION_TASKBAR_PINS: case SHORTCUT_LOCATION_TASKBAR_PINS:
return BatchShortcutAction(FilterTargetEq(target_exe). return BatchShortcutAction(FilterTargetEq(target_exe).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment