summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-06 22:27:01 +0000
committergab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-06 22:27:01 +0000
commite5f9d821d0071b3b2c9d9e5ecddaa4c874e8ad97 (patch)
tree08f7a1cfe67f8feca929c5c3e1acaa1b9188f0ad
parente994aa4003ecc2b370667d29d1e765a1fbf3e77b (diff)
downloadchromium_src-e5f9d821d0071b3b2c9d9e5ecddaa4c874e8ad97.zip
chromium_src-e5f9d821d0071b3b2c9d9e5ecddaa4c874e8ad97.tar.gz
chromium_src-e5f9d821d0071b3b2c9d9e5ecddaa4c874e8ad97.tar.bz2
Re-commit: Introduce RemoveChromeTaskbarShortcuts() to delete all pinned-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
-rw-r--r--base/base_paths_win.cc6
-rw-r--r--base/base_paths_win.h2
-rw-r--r--base/path_service_unittest.cc35
-rw-r--r--chrome/browser/shell_integration_win.cc4
-rw-r--r--chrome/installer/setup/uninstall.cc7
-rw-r--r--chrome/installer/util/shell_util.cc31
-rw-r--r--chrome/installer/util/shell_util.h7
7 files changed, 77 insertions, 15 deletions
diff --git a/base/base_paths_win.cc b/base/base_paths_win.cc
index 58c3ea5..a06d908 100644
--- a/base/base_paths_win.cc
+++ b/base/base_paths_win.cc
@@ -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;
}
diff --git a/base/base_paths_win.h b/base/base_paths_win.h
index 6cbcb2c..11bc111 100644
--- a/base/base_paths_win.h
+++ b/base/base_paths_win.h
@@ -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
};
diff --git a/base/path_service_unittest.cc b/base/path_service_unittest.cc
index d3110f9..eef334b 100644
--- a/base/path_service_unittest.cc
+++ b/base/path_service_unittest.cc
@@ -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)
diff --git a/chrome/browser/shell_integration_win.cc b/chrome/browser/shell_integration_win.cc
index d671ff2..3279075 100644
--- a/chrome/browser/shell_integration_win.cc
+++ b/chrome/browser/shell_integration_win.cc
@@ -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
diff --git a/chrome/installer/setup/uninstall.cc b/chrome/installer/setup/uninstall.cc
index 2fb193b..5c6e6c5 100644
--- a/chrome/installer/setup/uninstall.cc
+++ b/chrome/installer/setup/uninstall.cc
@@ -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);
}
diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc
index 6891fcd..8bd98ce 100644
--- a/chrome/installer/util/shell_util.cc
+++ b/chrome/installer/util/shell_util.cc
@@ -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)
diff --git a/chrome/installer/util/shell_util.h b/chrome/installer/util/shell_util.h
index 4e121c5..5a4786c 100644
--- a/chrome/installer/util/shell_util.h
+++ b/chrome/installer/util/shell_util.h
@@ -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);