summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbcwhite <bcwhite@chromium.org>2015-10-27 12:39:55 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-27 19:40:42 +0000
commitc5bab94fdde60b2bc9ed93822f35c5ce50202d26 (patch)
tree32340822915fb2ad4a94a736d9bad2ed01c6f30f
parent76aca1e99edcfeadb8061ac15dbefee31c89ab7c (diff)
downloadchromium_src-c5bab94fdde60b2bc9ed93822f35c5ce50202d26.zip
chromium_src-c5bab94fdde60b2bc9ed93822f35c5ce50202d26.tar.gz
chromium_src-c5bab94fdde60b2bc9ed93822f35c5ce50202d26.tar.bz2
Change shortcut install location to non-subdir.
BUG=169669 Review URL: https://codereview.chromium.org/1289333005 Cr-Commit-Position: refs/heads/master@{#356371}
-rw-r--r--chrome/browser/chrome_browser_main_win.cc9
-rw-r--r--chrome/browser/ui/views/app_list/win/app_list_service_win.cc2
-rw-r--r--chrome/browser/web_applications/web_app.h2
-rw-r--r--chrome/browser/web_applications/web_app_win.cc4
-rw-r--r--chrome/installer/setup/install.cc23
-rw-r--r--chrome/installer/setup/install_unittest.cc84
-rw-r--r--chrome/installer/setup/setup_main.cc2
-rw-r--r--chrome/installer/util/shell_util.cc84
-rw-r--r--chrome/installer/util/shell_util.h28
-rw-r--r--chrome/installer/util/shell_util_unittest.cc93
10 files changed, 249 insertions, 82 deletions
diff --git a/chrome/browser/chrome_browser_main_win.cc b/chrome/browser/chrome_browser_main_win.cc
index 5c90b54..0e2e53a 100644
--- a/chrome/browser/chrome_browser_main_win.cc
+++ b/chrome/browser/chrome_browser_main_win.cc
@@ -252,10 +252,11 @@ int DoUninstallTasks(bool chrome_still_running) {
base::FilePath chrome_exe;
if (PathService::Get(base::FILE_EXE, &chrome_exe)) {
ShellUtil::ShortcutLocation user_shortcut_locations[] = {
- ShellUtil::SHORTCUT_LOCATION_DESKTOP,
- ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH,
- ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
- ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
+ ShellUtil::SHORTCUT_LOCATION_DESKTOP,
+ ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH,
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT,
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
};
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
for (size_t i = 0; i < arraysize(user_shortcut_locations); ++i) {
diff --git a/chrome/browser/ui/views/app_list/win/app_list_service_win.cc b/chrome/browser/ui/views/app_list/win/app_list_service_win.cc
index dd9b7e5..6692e3f 100644
--- a/chrome/browser/ui/views/app_list/win/app_list_service_win.cc
+++ b/chrome/browser/ui/views/app_list/win/app_list_service_win.cc
@@ -306,7 +306,7 @@ void AppListServiceWin::CreateShortcut() {
shortcut_locations.on_desktop = true;
shortcut_locations.in_quick_launch_bar = true;
shortcut_locations.applications_menu_location =
- web_app::APP_MENU_LOCATION_SUBDIR_CHROME;
+ web_app::APP_MENU_LOCATION_SUBDIR_CHROME_DEPRECATED;
base::FilePath user_data_dir(
g_browser_process->profile_manager()->user_data_dir());
diff --git a/chrome/browser/web_applications/web_app.h b/chrome/browser/web_applications/web_app.h
index fee38de..1bf4bbb 100644
--- a/chrome/browser/web_applications/web_app.h
+++ b/chrome/browser/web_applications/web_app.h
@@ -78,7 +78,7 @@ struct ShortcutInfo {
enum ApplicationsMenuLocation {
APP_MENU_LOCATION_NONE,
APP_MENU_LOCATION_ROOT,
- APP_MENU_LOCATION_SUBDIR_CHROME,
+ APP_MENU_LOCATION_SUBDIR_CHROME_DEPRECATED, // TODO(bcwhite) remove this
APP_MENU_LOCATION_SUBDIR_CHROMEAPPS,
APP_MENU_LOCATION_HIDDEN,
};
diff --git a/chrome/browser/web_applications/web_app_win.cc b/chrome/browser/web_applications/web_app_win.cc
index a5078b0..18772be 100644
--- a/chrome/browser/web_applications/web_app_win.cc
+++ b/chrome/browser/web_applications/web_app_win.cc
@@ -573,8 +573,8 @@ std::vector<base::FilePath> GetShortcutPaths(
ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT
}, {
creation_locations.applications_menu_location ==
- APP_MENU_LOCATION_SUBDIR_CHROME,
- ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR
+ APP_MENU_LOCATION_SUBDIR_CHROME_DEPRECATED,
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED
}, {
creation_locations.applications_menu_location ==
APP_MENU_LOCATION_SUBDIR_CHROMEAPPS,
diff --git a/chrome/installer/setup/install.cc b/chrome/installer/setup/install.cc
index 978646f..b472cb7 100644
--- a/chrome/installer/setup/install.cc
+++ b/chrome/installer/setup/install.cc
@@ -70,7 +70,10 @@ void LogShortcutOperation(ShellUtil::ShortcutLocation location,
case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH:
message.append("Quick Launch ");
break;
- case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR:
+ case ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT:
+ message.append("Start menu ");
+ break;
+ case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED:
message.append("Start menu/" +
base::UTF16ToUTF8(dist->GetStartMenuShortcutSubfolder(
BrowserDistribution::SUBFOLDER_CHROME)) +
@@ -423,8 +426,24 @@ void CreateOrUpdateShortcuts(
ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL) {
start_menu_properties.set_pin_to_taskbar(!do_not_create_taskbar_shortcut);
}
+
+ // The attempt below to update the stortcut will fail if it does not already
+ // exist at the expected location on disk. First check if it exists in the
+ // previous location (under a subdirectory) and, if so, move it to the new
+ // location.
+ base::FilePath old_shortcut_path;
+ ShellUtil::GetShortcutPath(
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED, dist,
+ shortcut_level, &old_shortcut_path);
+ if (base::PathExists(old_shortcut_path)) {
+ ShellUtil::MoveExistingShortcut(
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT,
+ dist, start_menu_properties);
+ }
+
ExecuteAndLogShortcutOperation(
- ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, dist,
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT, dist,
start_menu_properties, shortcut_operation);
}
diff --git a/chrome/installer/setup/install_unittest.cc b/chrome/installer/setup/install_unittest.cc
index 6f8b9c0..0cb3e8f 100644
--- a/chrome/installer/setup/install_unittest.cc
+++ b/chrome/installer/setup/install_unittest.cc
@@ -125,18 +125,21 @@ class InstallShortcutTest : public testing::Test {
fake_user_desktop_.path().Append(shortcut_name);
user_quick_launch_shortcut_ =
fake_user_quick_launch_.path().Append(shortcut_name);
- user_start_menu_shortcut_ =
- fake_start_menu_.path().Append(
- dist_->GetStartMenuShortcutSubfolder(
+ user_start_menu_shortcut_ = fake_start_menu_.path().Append(shortcut_name);
+ user_start_menu_subdir_shortcut_ =
+ fake_start_menu_.path()
+ .Append(dist_->GetStartMenuShortcutSubfolder(
BrowserDistribution::SUBFOLDER_CHROME))
- .Append(shortcut_name);
+ .Append(shortcut_name);
system_desktop_shortcut_ =
fake_common_desktop_.path().Append(shortcut_name);
system_start_menu_shortcut_ =
- fake_common_start_menu_.path().Append(
- dist_->GetStartMenuShortcutSubfolder(
+ fake_common_start_menu_.path().Append(shortcut_name);
+ system_start_menu_subdir_shortcut_ =
+ fake_common_start_menu_.path()
+ .Append(dist_->GetStartMenuShortcutSubfolder(
BrowserDistribution::SUBFOLDER_CHROME))
- .Append(shortcut_name);
+ .Append(shortcut_name);
user_alternate_desktop_shortcut_ =
fake_user_desktop_.path().Append(alternate_shortcut_name);
}
@@ -145,7 +148,9 @@ class InstallShortcutTest : public testing::Test {
// Try to unpin potentially pinned shortcuts (although pinning isn't tested,
// the call itself might still have pinned the Start Menu shortcuts).
base::win::UnpinShortcutFromTaskbar(user_start_menu_shortcut_);
+ base::win::UnpinShortcutFromTaskbar(user_start_menu_subdir_shortcut_);
base::win::UnpinShortcutFromTaskbar(system_start_menu_shortcut_);
+ base::win::UnpinShortcutFromTaskbar(system_start_menu_subdir_shortcut_);
CoUninitialize();
}
@@ -200,8 +205,10 @@ class InstallShortcutTest : public testing::Test {
base::FilePath user_desktop_shortcut_;
base::FilePath user_quick_launch_shortcut_;
base::FilePath user_start_menu_shortcut_;
+ base::FilePath user_start_menu_subdir_shortcut_;
base::FilePath system_desktop_shortcut_;
base::FilePath system_start_menu_shortcut_;
+ base::FilePath system_start_menu_subdir_shortcut_;
base::FilePath user_alternate_desktop_shortcut_;
};
@@ -375,6 +382,69 @@ TEST_F(InstallShortcutTest, ReplaceExisting) {
ASSERT_FALSE(base::PathExists(user_start_menu_shortcut_));
}
+class MigrateShortcutTest : public InstallShortcutTest,
+ public testing::WithParamInterface<
+ testing::tuple<
+ installer::InstallShortcutOperation,
+ installer::InstallShortcutLevel>> {
+ public:
+ MigrateShortcutTest() : shortcut_operation_(testing::get<0>(GetParam())),
+ shortcut_level_(testing::get<1>(GetParam())) {}
+
+ protected:
+ const installer::InstallShortcutOperation shortcut_operation_;
+ const installer::InstallShortcutLevel shortcut_level_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MigrateShortcutTest);
+};
+
+TEST_P(MigrateShortcutTest, MigrateAwayFromDeprecatedStartMenuTest) {
+ base::win::ShortcutProperties dummy_properties;
+ base::FilePath dummy_target;
+ ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_target));
+ dummy_properties.set_target(expected_properties_.target);
+ dummy_properties.set_working_dir(fake_user_desktop_.path());
+ dummy_properties.set_arguments(L"--dummy --args");
+ dummy_properties.set_app_id(L"El.Dummiest");
+
+ base::FilePath start_menu_shortcut;
+ base::FilePath start_menu_subdir_shortcut;
+ if (shortcut_level_ == installer::CURRENT_USER) {
+ start_menu_shortcut = user_start_menu_shortcut_;
+ start_menu_subdir_shortcut = user_start_menu_subdir_shortcut_;
+ } else {
+ start_menu_shortcut = system_start_menu_shortcut_;
+ start_menu_subdir_shortcut = system_start_menu_subdir_shortcut_;
+ }
+
+ ASSERT_TRUE(base::CreateDirectory(start_menu_subdir_shortcut.DirName()));
+ ASSERT_FALSE(base::PathExists(start_menu_subdir_shortcut));
+ ASSERT_TRUE(base::win::CreateOrUpdateShortcutLink(
+ start_menu_subdir_shortcut, dummy_properties,
+ base::win::SHORTCUT_CREATE_ALWAYS));
+ ASSERT_TRUE(base::PathExists(start_menu_subdir_shortcut));
+ ASSERT_FALSE(base::PathExists(start_menu_shortcut));
+
+ installer::CreateOrUpdateShortcuts(chrome_exe_, *product_, *prefs_,
+ shortcut_level_, shortcut_operation_);
+ ASSERT_FALSE(base::PathExists(start_menu_subdir_shortcut));
+ ASSERT_TRUE(base::PathExists(start_menu_shortcut));
+}
+
+// Verify that any installer operation for any installation level triggers
+// the migration from sub-folder to root of start-menu.
+INSTANTIATE_TEST_CASE_P(
+ MigrateShortcutTests, MigrateShortcutTest,
+ testing::Combine(
+ testing::Values(
+ installer::INSTALL_SHORTCUT_REPLACE_EXISTING,
+ installer::INSTALL_SHORTCUT_CREATE_EACH_IF_NO_SYSTEM_LEVEL,
+ installer::INSTALL_SHORTCUT_CREATE_ALL),
+ testing::Values(
+ installer::CURRENT_USER,
+ installer::ALL_USERS)));
+
TEST_F(InstallShortcutTest, CreateIfNoSystemLevelAllSystemShortcutsExist) {
base::win::ShortcutProperties dummy_properties;
base::FilePath dummy_target;
diff --git a/chrome/installer/setup/setup_main.cc b/chrome/installer/setup/setup_main.cc
index 94cab45..e7e9a05 100644
--- a/chrome/installer/setup/setup_main.cc
+++ b/chrome/installer/setup/setup_main.cc
@@ -992,7 +992,7 @@ installer::InstallStatus RegisterDevChrome(
shortcut_properties.set_dual_mode(true);
shortcut_properties.set_pin_to_taskbar(true);
ShellUtil::CreateOrUpdateShortcut(
- ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, chrome_dist,
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT, chrome_dist,
shortcut_properties, ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS);
// Register Chrome at user-level and make it default.
diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc
index 0c2de30..f69c9d6 100644
--- a/chrome/installer/util/shell_util.cc
+++ b/chrome/installer/util/shell_util.cc
@@ -1544,7 +1544,8 @@ bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location,
BrowserDistribution* dist,
ShellUtil::ShellChange level) {
// Explicitly whitelist locations, since accidental calls can be very harmful.
- if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR &&
+ if (location !=
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED &&
location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR &&
location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) {
NOTREACHED();
@@ -1623,13 +1624,12 @@ bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist,
CONFIRM_SHELL_REGISTRATION_IN_HKLM);
}
-bool ShellUtil::ShortcutLocationIsSupported(
- ShellUtil::ShortcutLocation location) {
+bool ShellUtil::ShortcutLocationIsSupported(ShortcutLocation location) {
switch (location) {
case SHORTCUT_LOCATION_DESKTOP: // Falls through.
case SHORTCUT_LOCATION_QUICK_LAUNCH: // Falls through.
case SHORTCUT_LOCATION_START_MENU_ROOT: // Falls through.
- case SHORTCUT_LOCATION_START_MENU_CHROME_DIR: // Falls through.
+ case SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED: // Falls through.
case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR:
return true;
case SHORTCUT_LOCATION_TASKBAR_PINS:
@@ -1642,7 +1642,7 @@ bool ShellUtil::ShortcutLocationIsSupported(
}
}
-bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location,
+bool ShellUtil::GetShortcutPath(ShortcutLocation location,
BrowserDistribution* dist,
ShellChange level,
base::FilePath* path) {
@@ -1663,7 +1663,7 @@ bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location,
dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU :
base::DIR_COMMON_START_MENU;
break;
- case SHORTCUT_LOCATION_START_MENU_CHROME_DIR:
+ case SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED:
dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU :
base::DIR_COMMON_START_MENU;
folder_to_append = dist->GetStartMenuShortcutSubfolder(
@@ -1698,16 +1698,42 @@ bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location,
return true;
}
+bool ShellUtil::MoveExistingShortcut(ShortcutLocation old_location,
+ ShortcutLocation new_location,
+ BrowserDistribution* dist,
+ const ShortcutProperties& properties) {
+ // Explicitly whitelist locations to which this is applicable.
+ if (old_location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED ||
+ new_location != SHORTCUT_LOCATION_START_MENU_ROOT) {
+ NOTREACHED();
+ return false;
+ }
+
+ base::string16 shortcut_name(
+ ExtractShortcutNameFromProperties(dist, properties));
+
+ base::FilePath old_shortcut_path;
+ base::FilePath new_shortcut_path;
+ GetShortcutPath(old_location, dist, properties.level, &old_shortcut_path);
+ GetShortcutPath(new_location, dist, properties.level, &new_shortcut_path);
+ old_shortcut_path = old_shortcut_path.Append(shortcut_name);
+ new_shortcut_path = new_shortcut_path.Append(shortcut_name);
+
+ bool result = base::Move(old_shortcut_path, new_shortcut_path);
+ RemoveShortcutFolderIfEmpty(old_location, dist, properties.level);
+ return result;
+}
+
bool ShellUtil::CreateOrUpdateShortcut(
- ShellUtil::ShortcutLocation location,
+ ShortcutLocation location,
BrowserDistribution* dist,
- const ShellUtil::ShortcutProperties& properties,
- ShellUtil::ShortcutOperation operation) {
+ const ShortcutProperties& properties,
+ ShortcutOperation operation) {
// Explicitly whitelist locations to which this is applicable.
if (location != SHORTCUT_LOCATION_DESKTOP &&
location != SHORTCUT_LOCATION_QUICK_LAUNCH &&
location != SHORTCUT_LOCATION_START_MENU_ROOT &&
- location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR &&
+ location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED &&
location != SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR) {
NOTREACHED();
return false;
@@ -1816,7 +1842,7 @@ void ShellUtil::GetRegisteredBrowsers(
DCHECK(dist);
DCHECK(browsers);
- const base::string16 base_key(ShellUtil::kRegStartMenuInternet);
+ const base::string16 base_key(kRegStartMenuInternet);
base::string16 client_path;
RegKey key;
base::string16 name;
@@ -1956,7 +1982,7 @@ ShellUtil::DefaultState ShellUtil::GetChromeDefaultState() {
base::FilePath app_path;
if (!PathService::Get(base::FILE_EXE, &app_path)) {
NOTREACHED();
- return ShellUtil::UNKNOWN_DEFAULT;
+ return UNKNOWN_DEFAULT;
}
return GetChromeDefaultStateFromPath(app_path);
@@ -1999,7 +2025,7 @@ ShellUtil::DefaultState ShellUtil::GetChromeDefaultProtocolClientState(
base::FilePath chrome_exe;
if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
NOTREACHED();
- return ShellUtil::UNKNOWN_DEFAULT;
+ return UNKNOWN_DEFAULT;
}
const wchar_t* const protocols[] = { protocol.c_str() };
@@ -2017,7 +2043,7 @@ bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist,
int shell_change,
const base::FilePath& chrome_exe,
bool elevate_if_not_admin) {
- DCHECK(!(shell_change & ShellUtil::SYSTEM_LEVEL) || IsUserAnAdmin());
+ DCHECK(!(shell_change & SYSTEM_LEVEL) || IsUserAnAdmin());
BrowserDistribution* distribution = BrowserDistribution::GetDistribution();
if (distribution->GetDefaultBrowserControlPolicy() !=
@@ -2032,7 +2058,7 @@ bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist,
return false;
}
- if (!ShellUtil::RegisterChromeBrowser(
+ if (!RegisterChromeBrowser(
dist, chrome_exe, base::string16(), elevate_if_not_admin)) {
return false;
}
@@ -2050,24 +2076,24 @@ bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist,
HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration,
NULL, CLSCTX_INPROC);
if (SUCCEEDED(hr)) {
- for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) {
+ for (int i = 0; kBrowserProtocolAssociations[i] != NULL; i++) {
hr = pAAR->SetAppAsDefault(app_name.c_str(),
- ShellUtil::kBrowserProtocolAssociations[i], AT_URLPROTOCOL);
+ kBrowserProtocolAssociations[i], AT_URLPROTOCOL);
if (!SUCCEEDED(hr)) {
ret = false;
LOG(ERROR) << "Failed to register as default for protocol "
- << ShellUtil::kBrowserProtocolAssociations[i]
+ << kBrowserProtocolAssociations[i]
<< " (" << hr << ")";
}
}
- for (int i = 0; ShellUtil::kDefaultFileAssociations[i] != NULL; i++) {
+ for (int i = 0; kDefaultFileAssociations[i] != NULL; i++) {
hr = pAAR->SetAppAsDefault(app_name.c_str(),
- ShellUtil::kDefaultFileAssociations[i], AT_FILEEXTENSION);
+ kDefaultFileAssociations[i], AT_FILEEXTENSION);
if (!SUCCEEDED(hr)) {
ret = false;
LOG(ERROR) << "Failed to register as default for file extension "
- << ShellUtil::kDefaultFileAssociations[i]
+ << kDefaultFileAssociations[i]
<< " (" << hr << ")";
}
}
@@ -2350,11 +2376,11 @@ bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist,
}
// static
-bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location,
+bool ShellUtil::RemoveShortcuts(ShortcutLocation location,
BrowserDistribution* dist,
ShellChange level,
const base::FilePath& target_exe) {
- if (!ShellUtil::ShortcutLocationIsSupported(location))
+ if (!ShortcutLocationIsSupported(location))
return true; // Vacuous success.
FilterTargetEq shortcut_filter(target_exe, false);
@@ -2368,7 +2394,7 @@ bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location,
NULL);
// Remove chrome-specific shortcut folders if they are now empty.
if (success &&
- (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR ||
+ (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED ||
location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR ||
location == SHORTCUT_LOCATION_APP_SHORTCUTS)) {
success = RemoveShortcutFolderIfEmpty(location, dist, level);
@@ -2378,12 +2404,12 @@ bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location,
// static
bool ShellUtil::RetargetShortcutsWithArgs(
- ShellUtil::ShortcutLocation location,
+ ShortcutLocation location,
BrowserDistribution* dist,
ShellChange level,
const base::FilePath& old_target_exe,
const base::FilePath& new_target_exe) {
- if (!ShellUtil::ShortcutLocationIsSupported(location))
+ if (!ShortcutLocationIsSupported(location))
return true; // Vacuous success.
FilterTargetEq shortcut_filter(old_target_exe, true);
@@ -2395,14 +2421,14 @@ bool ShellUtil::RetargetShortcutsWithArgs(
// static
bool ShellUtil::ShortcutListMaybeRemoveUnknownArgs(
- ShellUtil::ShortcutLocation location,
+ ShortcutLocation location,
BrowserDistribution* dist,
ShellChange level,
const base::FilePath& chrome_exe,
bool do_removal,
const scoped_refptr<SharedCancellationFlag>& cancel,
std::vector<std::pair<base::FilePath, base::string16> >* shortcuts) {
- if (!ShellUtil::ShortcutLocationIsSupported(location))
+ if (!ShortcutLocationIsSupported(location))
return false;
DCHECK(dist);
FilterTargetEq shortcut_filter(chrome_exe, true);
@@ -2524,7 +2550,7 @@ bool ShellUtil::AddFileAssociations(
// static
bool ShellUtil::DeleteFileAssociations(const base::string16& prog_id) {
// Delete the key HKEY_CURRENT_USER\Software\Classes\PROGID.
- base::string16 key_path(ShellUtil::kRegClasses);
+ base::string16 key_path(kRegClasses);
key_path.push_back(base::FilePath::kSeparators[0]);
key_path.append(prog_id);
return InstallUtil::DeleteRegistryKey(
diff --git a/chrome/installer/util/shell_util.h b/chrome/installer/util/shell_util.h
index f13e2bb..1c34c5d 100644
--- a/chrome/installer/util/shell_util.h
+++ b/chrome/installer/util/shell_util.h
@@ -54,9 +54,9 @@ class ShellUtil {
SHORTCUT_LOCATION_DESKTOP = SHORTCUT_LOCATION_FIRST,
SHORTCUT_LOCATION_QUICK_LAUNCH,
SHORTCUT_LOCATION_START_MENU_ROOT,
- SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
+ SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED, // now placed in root
SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR,
- SHORTCUT_LOCATION_TASKBAR_PINS, // base::win::VERSION_WIN7 +
+ SHORTCUT_LOCATION_TASKBAR_PINS, // base::win::VERSION_WIN7 +
SHORTCUT_LOCATION_APP_SHORTCUTS, // base::win::VERSION_WIN8 +
NUM_SHORTCUT_LOCATIONS
};
@@ -311,17 +311,25 @@ class ShellUtil {
// Returns true if the current Windows version supports the presence of
// shortcuts at |location|.
- static bool ShortcutLocationIsSupported(ShellUtil::ShortcutLocation location);
+ static bool ShortcutLocationIsSupported(ShortcutLocation location);
// Sets |path| to the path for a shortcut at the |location| desired for the
// given |level| (CURRENT_USER for per-user path and SYSTEM_LEVEL for
// all-users path).
// Returns false on failure.
- static bool GetShortcutPath(ShellUtil::ShortcutLocation location,
+ static bool GetShortcutPath(ShortcutLocation location,
BrowserDistribution* dist,
ShellChange level,
base::FilePath* path);
+ // Move an existing shortcut from |old_location| to |new_location| for the
+ // set |shortcut_level|. If the folder containing |old_location| is then
+ // empty, it will be removed.
+ static bool MoveExistingShortcut(ShortcutLocation old_location,
+ ShortcutLocation new_location,
+ BrowserDistribution* dist,
+ const ShortcutProperties& properties);
+
// Updates shortcut in |location| (or creates it if |options| specify
// SHELL_SHORTCUT_CREATE_ALWAYS).
// |dist| gives the type of browser distribution currently in use.
@@ -332,10 +340,10 @@ class ShellUtil {
// SHORTCUT_LOCATION_START_MENU_CHROME_DIR, or
// SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR.
static bool CreateOrUpdateShortcut(
- ShellUtil::ShortcutLocation location,
+ ShortcutLocation location,
BrowserDistribution* dist,
- const ShellUtil::ShortcutProperties& properties,
- ShellUtil::ShortcutOperation operation);
+ const ShortcutProperties& properties,
+ ShortcutOperation operation);
// Returns the string "|icon_path|,|icon_index|" (see, for example,
// http://msdn.microsoft.com/library/windows/desktop/dd391573.aspx).
@@ -543,7 +551,7 @@ class ShellUtil {
// If |location| is a Chrome-specific folder, it will be deleted as well.
// Returns true if all shortcuts pointing to |target_exe| are successfully
// deleted, including the case where no such shortcuts are found.
- static bool RemoveShortcuts(ShellUtil::ShortcutLocation location,
+ static bool RemoveShortcuts(ShortcutLocation location,
BrowserDistribution* dist,
ShellChange level,
const base::FilePath& target_exe);
@@ -557,7 +565,7 @@ class ShellUtil {
// Returns true if all updates to matching shortcuts are successful, including
// the vacuous case where no matching shortcuts are found.
static bool RetargetShortcutsWithArgs(
- ShellUtil::ShortcutLocation location,
+ ShortcutLocation location,
BrowserDistribution* dist,
ShellChange level,
const base::FilePath& old_target_exe,
@@ -570,7 +578,7 @@ class ShellUtil {
// those shortcuts. This method will abort and return false if |cancel| is
// non-NULL and gets set at any point during this call.
static bool ShortcutListMaybeRemoveUnknownArgs(
- ShellUtil::ShortcutLocation location,
+ ShortcutLocation location,
BrowserDistribution* dist,
ShellChange level,
const base::FilePath& chrome_exe,
diff --git a/chrome/installer/util/shell_util_unittest.cc b/chrome/installer/util/shell_util_unittest.cc
index 3b97dd0..e581064 100644
--- a/chrome/installer/util/shell_util_unittest.cc
+++ b/chrome/installer/util/shell_util_unittest.cc
@@ -117,7 +117,11 @@ class ShellUtilShortcutTest : public testing::Test {
case ShellUtil::SHORTCUT_LOCATION_QUICK_LAUNCH:
expected_path = fake_user_quick_launch_.path();
break;
- case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR:
+ case ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT:
+ expected_path = (properties.level == ShellUtil::CURRENT_USER) ?
+ fake_start_menu_.path() : fake_common_start_menu_.path();
+ break;
+ case ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED:
expected_path = (properties.level == ShellUtil::CURRENT_USER) ?
fake_start_menu_.path() : fake_common_start_menu_.path();
expected_path = expected_path.Append(
@@ -233,17 +237,50 @@ TEST_F(ShellUtilShortcutTest, GetShortcutPath) {
base::string16 start_menu_subfolder =
dist_->GetStartMenuShortcutSubfolder(
BrowserDistribution::SUBFOLDER_CHROME);
- ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
- dist_, ShellUtil::CURRENT_USER, &path);
+ ShellUtil::GetShortcutPath(
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
+ dist_, ShellUtil::CURRENT_USER, &path);
EXPECT_EQ(fake_start_menu_.path().Append(start_menu_subfolder),
path);
- ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
- dist_, ShellUtil::SYSTEM_LEVEL, &path);
+ ShellUtil::GetShortcutPath(
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
+ dist_, ShellUtil::SYSTEM_LEVEL, &path);
EXPECT_EQ(fake_common_start_menu_.path().Append(start_menu_subfolder),
path);
}
+TEST_F(ShellUtilShortcutTest, MoveExistingShortcut) {
+ test_properties_.set_shortcut_name(L"Bobo le shortcut");
+ test_properties_.level = ShellUtil::SYSTEM_LEVEL;
+ base::FilePath old_shortcut_path(GetExpectedShortcutPath(
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
+ dist_, test_properties_));
+
+ ASSERT_TRUE(
+ ShellUtil::CreateOrUpdateShortcut(
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
+ dist_, test_properties_,
+ ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
+ ValidateChromeShortcut(
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
+ dist_, test_properties_);
+ ASSERT_TRUE(base::PathExists(old_shortcut_path.DirName()));
+ ASSERT_TRUE(base::PathExists(old_shortcut_path));
+
+ ASSERT_TRUE(
+ ShellUtil::MoveExistingShortcut(
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT,
+ dist_, test_properties_));
+
+ ValidateChromeShortcut(
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_ROOT,
+ dist_, test_properties_);
+ ASSERT_FALSE(base::PathExists(old_shortcut_path));
+ ASSERT_FALSE(base::PathExists(old_shortcut_path.DirName()));
+}
+
TEST_F(ShellUtilShortcutTest, CreateChromeExeShortcutWithDefaultProperties) {
ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER);
product_->AddDefaultShortcutProperties(chrome_exe_, &properties);
@@ -257,12 +294,14 @@ TEST_F(ShellUtilShortcutTest, CreateChromeExeShortcutWithDefaultProperties) {
TEST_F(ShellUtilShortcutTest, CreateStartMenuShortcutWithAllProperties) {
test_properties_.set_shortcut_name(L"Bobo le shortcut");
test_properties_.level = ShellUtil::SYSTEM_LEVEL;
- ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
- ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
- dist_, test_properties_,
- ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
- ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
- dist_, test_properties_);
+ ASSERT_TRUE(
+ ShellUtil::CreateOrUpdateShortcut(
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
+ dist_, test_properties_,
+ ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
+ ValidateChromeShortcut(
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
+ dist_, test_properties_);
}
TEST_F(ShellUtilShortcutTest, ReplaceSystemLevelDesktopShortcut) {
@@ -317,21 +356,24 @@ TEST_F(ShellUtilShortcutTest, UpdateQuickLaunchShortcutArguments) {
TEST_F(ShellUtilShortcutTest, UpdateAddDualModeToStartMenuShortcut) {
ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER);
product_->AddDefaultShortcutProperties(chrome_exe_, &properties);
- ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
- ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, dist_,
- properties, ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
+ ASSERT_TRUE(
+ ShellUtil::CreateOrUpdateShortcut(
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED, dist_,
+ properties, ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
ShellUtil::ShortcutProperties added_properties(ShellUtil::CURRENT_USER);
added_properties.set_dual_mode(true);
- ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
- ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, dist_,
- added_properties, ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING));
+ ASSERT_TRUE(
+ ShellUtil::CreateOrUpdateShortcut(
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED, dist_,
+ added_properties, ShellUtil::SHELL_SHORTCUT_UPDATE_EXISTING));
ShellUtil::ShortcutProperties expected_properties(properties);
expected_properties.set_dual_mode(true);
- ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
- dist_, expected_properties);
+ ValidateChromeShortcut(
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
+ dist_, expected_properties);
}
TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevel) {
@@ -364,11 +406,12 @@ TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelWithSystemLevelPresent) {
TEST_F(ShellUtilShortcutTest, CreateIfNoSystemLevelStartMenu) {
ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
- ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
dist_, test_properties_,
ShellUtil::SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL));
- ValidateChromeShortcut(ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
- dist_, test_properties_);
+ ValidateChromeShortcut(
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
+ dist_, test_properties_);
}
TEST_F(ShellUtilShortcutTest, CreateAlwaysUserWithSystemLevelPresent) {
@@ -700,7 +743,7 @@ TEST_F(ShellUtilShortcutTest, ClearShortcutArguments) {
TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) {
ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
- ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
dist_, test_properties_,
ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
@@ -709,7 +752,7 @@ TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) {
ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
test_properties_.set_shortcut_name(L"A second shortcut");
ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
- ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR,
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED,
dist_, test_properties_,
ShellUtil::SHELL_SHORTCUT_CREATE_ALWAYS));
ASSERT_TRUE(ShellUtil::CreateOrUpdateShortcut(
@@ -743,7 +786,7 @@ TEST_F(ShellUtilShortcutTest, CreateMultipleStartMenuShortcutsAndRemoveFolder) {
ASSERT_TRUE(base::PathExists(chrome_shortcut_folder));
ASSERT_TRUE(ShellUtil::RemoveShortcuts(
- ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR, dist_,
+ ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED, dist_,
ShellUtil::CURRENT_USER, chrome_exe_));
ASSERT_FALSE(base::PathExists(chrome_shortcut_folder));