Skip to content

Commit

Permalink
Re-commit: Introduce RemoveChromeTaskbarShortcuts() to delete all pin…
Browse files Browse the repository at this point in the history
…ned-to-taskbar shortcuts owned by the uninstalled Chrome.

Original commit http://crrev.com/165505
Reverted in http://crrev.com/165524

BUG=158632
TEST=No user-level shortcut Chrome left behind in taskbar post user-level self-destruct.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166285 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
gab@chromium.org committed Nov 6, 2012
1 parent e994aa4 commit e5f9d82
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 15 deletions.
6 changes: 6 additions & 0 deletions base/base_paths_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ bool PathProviderWin(int key, FilePath* result) {
if (!GetQuickLaunchPath(true, &cur))
return false;
break;
case base::DIR_TASKBAR_PINS:
if (!PathService::Get(base::DIR_USER_QUICK_LAUNCH, &cur))
return false;
cur = cur.AppendASCII("User Pinned");
cur = cur.AppendASCII("TaskBar");
break;
default:
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions base/base_paths_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ enum {
DIR_USER_QUICK_LAUNCH, // Directory for the quick launch shortcuts.
DIR_DEFAULT_USER_QUICK_LAUNCH, // Directory for the quick launch shortcuts
// of the Default user.
DIR_TASKBAR_PINS, // Directory for the shortcuts pinned to taskbar via
// base::win::TaskbarPinShortcutLink().

PATH_WIN_END
};
Expand Down
35 changes: 22 additions & 13 deletions base/path_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,41 @@ namespace {
bool ReturnsValidPath(int dir_type) {
FilePath path;
bool result = PathService::Get(dir_type, &path);
// Some paths might not exist on some platforms in which case confirming
// |result| is true and !path.empty() is the best we can do.
bool check_path_exists = true;
#if defined(OS_POSIX)
// If chromium has never been started on this account, the cache path may not
// exist.
if (dir_type == base::DIR_CACHE)
return result && !path.empty();
check_path_exists = false;
#endif
#if defined(OS_LINUX)
// On the linux try-bots: a path is returned (e.g. /home/chrome-bot/Desktop),
// but it doesn't exist.
if (dir_type == base::DIR_USER_DESKTOP)
return result && !path.empty();
check_path_exists = false;
#endif
#if defined(OS_WIN)
// On Windows XP, the Quick Launch folder for the "Default User" doesn't exist
// by default. At least confirm that the path returned begins with the
// Default User's profile path.
if (dir_type == base::DIR_DEFAULT_USER_QUICK_LAUNCH &&
base::win::GetVersion() < base::win::VERSION_VISTA) {
wchar_t default_profile_path[MAX_PATH];
DWORD size = arraysize(default_profile_path);
return (result &&
::GetDefaultUserProfileDirectory(default_profile_path, &size) &&
StartsWith(path.value(), default_profile_path, false));
if (dir_type == base::DIR_DEFAULT_USER_QUICK_LAUNCH) {
// On Windows XP, the Quick Launch folder for the "Default User" doesn't
// exist by default. At least confirm that the path returned begins with the
// Default User's profile path.
if (base::win::GetVersion() < base::win::VERSION_VISTA) {
wchar_t default_profile_path[MAX_PATH];
DWORD size = arraysize(default_profile_path);
return (result &&
::GetDefaultUserProfileDirectory(default_profile_path, &size) &&
StartsWith(path.value(), default_profile_path, false));
}
} else if (dir_type == base::DIR_TASKBAR_PINS) {
// There is no pinned-to-taskbar shortcuts prior to Win7.
if(base::win::GetVersion() < base::win::VERSION_WIN7)
check_path_exists = false;
}
#endif
return result && !path.empty() && file_util::PathExists(path);
return result && !path.empty() && (!check_path_exists ||
file_util::PathExists(path));
}

#if defined(OS_WIN)
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/shell_integration_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ void MigrateChromiumShortcutsCallback() {
const wchar_t* sub_dir;
} kLocations[] = {
{
base::DIR_APP_DATA,
L"Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar"
base::DIR_TASKBAR_PINS,
NULL
}, {
base::DIR_USER_DESKTOP,
NULL
Expand Down
7 changes: 7 additions & 0 deletions chrome/installer/setup/uninstall.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ void DeleteChromeShortcuts(const InstallerState& installer_state,
LOG(WARNING) << "Failed to delete Start Menu shortcuts.";
}

// Although the shortcut removal calls above will unpin their shortcut if they
// result in a deletion (i.e. shortcut existed and pointed to |chrome_exe|),
// it is possible for shortcuts to remain pinned while their parent shortcut
// has been deleted or changed to point to another |chrome_exe|. Make sure all
// pinned-to-taskbar shortcuts that point to |chrome_exe| are unpinned.
ShellUtil::RemoveChromeTaskbarShortcuts(chrome_exe);

ShellUtil::RemoveChromeStartScreenShortcuts(product.distribution(),
chrome_exe);
}
Expand Down
31 changes: 31 additions & 0 deletions chrome/installer/util/shell_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,37 @@ bool ShellUtil::RemoveChromeShortcut(
return true;
}

void ShellUtil::RemoveChromeTaskbarShortcuts(const string16& chrome_exe) {
if (base::win::GetVersion() < base::win::VERSION_WIN7)
return;

FilePath taskbar_pins_path;
if (!PathService::Get(base::DIR_TASKBAR_PINS, &taskbar_pins_path) ||
!file_util::PathExists(taskbar_pins_path)) {
LOG(ERROR) << "Couldn't find path to taskbar pins.";
return;
}

file_util::FileEnumerator shortcuts_enum(
taskbar_pins_path, false,
file_util::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk"));

FilePath chrome_path(chrome_exe);
InstallUtil::ProgramCompare chrome_compare(chrome_path);
for (FilePath shortcut_path = shortcuts_enum.Next(); !shortcut_path.empty();
shortcut_path = shortcuts_enum.Next()) {
FilePath read_target;
if (!base::win::ResolveShortcut(shortcut_path, &read_target, NULL)) {
LOG(ERROR) << "Couldn't resolve shortcut at " << shortcut_path.value();
continue;
}
if (chrome_compare.Evaluate(read_target.value())) {
// Unpin this shortcut if it points to |chrome_exe|.
base::win::TaskbarUnpinShortcutLink(shortcut_path.value().c_str());
}
}
}

void ShellUtil::RemoveChromeStartScreenShortcuts(BrowserDistribution* dist,
const string16& chrome_exe) {
if (base::win::GetVersion() < base::win::VERSION_WIN8)
Expand Down
7 changes: 7 additions & 0 deletions chrome/installer/util/shell_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,13 @@ class ShellUtil {
ShellChange level,
const string16* shortcut_name);

// Enumerates all shortcuts pinned to the taskbar and deletes those pointing
// to |chrome_exe|.
// base::win::TaskbarUnpinShortcutLink() should be prefered, but this is
// useful on uninstall as the parent shortcut of a pin might no longer exist
// (thus making it impossible to unpin it via that API).
static void RemoveChromeTaskbarShortcuts(const string16& chrome_exe);

// This will remove all secondary tiles from the start screen for |dist|.
static void RemoveChromeStartScreenShortcuts(BrowserDistribution* dist,
const string16& chrome_exe);
Expand Down

0 comments on commit e5f9d82

Please sign in to comment.