diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-22 14:58:23 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-22 14:58:23 +0000 |
commit | f8b2ca3555497caedc341ec16f110e310c15562d (patch) | |
tree | e9d22ccd68a40201dc1bb9834efb7ed26ab49561 /chrome/installer | |
parent | d21a8a5fb4d3af19452149bdcf7f6855ba80a194 (diff) | |
download | chromium_src-f8b2ca3555497caedc341ec16f110e310c15562d.zip chromium_src-f8b2ca3555497caedc341ec16f110e310c15562d.tar.gz chromium_src-f8b2ca3555497caedc341ec16f110e310c15562d.tar.bz2 |
Add Windows desktop shortcut for multiple profiles.
BUG=87770
TEST=new unit tests added with this CL.
Review URL: http://codereview.chromium.org/8502033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111156 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer')
-rw-r--r-- | chrome/installer/setup/install.cc | 8 | ||||
-rw-r--r-- | chrome/installer/util/browser_distribution_unittest.cc | 15 | ||||
-rw-r--r-- | chrome/installer/util/shell_util.cc | 62 | ||||
-rw-r--r-- | chrome/installer/util/shell_util.h | 53 | ||||
-rw-r--r-- | chrome/installer/util/shell_util_unittest.cc | 86 |
5 files changed, 183 insertions, 41 deletions
diff --git a/chrome/installer/setup/install.cc b/chrome/installer/setup/install.cc index d817c48..36c24ca 100644 --- a/chrome/installer/setup/install.cc +++ b/chrome/installer/setup/install.cc @@ -131,12 +131,12 @@ bool CreateOrUpdateChromeShortcuts(const InstallerState& installer_state, VLOG(1) << "Creating shortcut to " << chrome_exe.value() << " at " << chrome_link.value(); ret = ShellUtil::UpdateChromeShortcut(browser_dist, chrome_exe.value(), - chrome_link.value(), product_desc, true); + chrome_link.value(), L"", product_desc, true); } else if (file_util::PathExists(chrome_link)) { VLOG(1) << "Updating shortcut at " << chrome_link.value() << " to point to " << chrome_exe.value(); ret = ShellUtil::UpdateChromeShortcut(browser_dist, chrome_exe.value(), - chrome_link.value(), product_desc, false); + chrome_link.value(), L"", product_desc, false); } else { VLOG(1) << "not first or repaired install, link file doesn't exist. status: " @@ -181,7 +181,7 @@ bool CreateOrUpdateChromeShortcuts(const InstallerState& installer_state, if (ret) { if (installer_state.system_install()) { ret = ShellUtil::CreateChromeDesktopShortcut(product.distribution(), - chrome_exe.value(), product_desc, ShellUtil::SYSTEM_LEVEL, + chrome_exe.value(), product_desc, L"", L"", ShellUtil::SYSTEM_LEVEL, alt_shortcut, create_all_shortcut); if (ret) { ret = ShellUtil::CreateChromeQuickLaunchShortcut( @@ -191,7 +191,7 @@ bool CreateOrUpdateChromeShortcuts(const InstallerState& installer_state, } } else { ret = ShellUtil::CreateChromeDesktopShortcut(product.distribution(), - chrome_exe.value(), product_desc, ShellUtil::CURRENT_USER, + chrome_exe.value(), product_desc, L"", L"", ShellUtil::CURRENT_USER, alt_shortcut, create_all_shortcut); if (ret) { ret = ShellUtil::CreateChromeQuickLaunchShortcut( diff --git a/chrome/installer/util/browser_distribution_unittest.cc b/chrome/installer/util/browser_distribution_unittest.cc index 942f62c..6a09443 100644 --- a/chrome/installer/util/browser_distribution_unittest.cc +++ b/chrome/installer/util/browser_distribution_unittest.cc @@ -43,10 +43,21 @@ TEST(BrowserDistributionTest, StringsTest) { TEST(BrowserDistributionTest, AlternateAndNormalShortcutName) { std::wstring normal_name; std::wstring alternate_name; + std::wstring appended_name_one; + std::wstring appended_name_two; BrowserDistribution* dist = BrowserDistribution::GetDistribution(); - EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, &normal_name, false)); - EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, &alternate_name, true)); + EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, false, L"", + &normal_name)); + EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, true, L"", + &alternate_name)); + EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, true, L"Sparky", + &appended_name_one)); + EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, true, L"Sparkles", + &appended_name_two)); EXPECT_NE(normal_name, alternate_name); + EXPECT_NE(appended_name_one, appended_name_two); EXPECT_FALSE(normal_name.empty()); EXPECT_FALSE(alternate_name.empty()); + EXPECT_FALSE(appended_name_one.empty()); + EXPECT_FALSE(appended_name_two.empty()); } diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc index 3b56f82..ab6622d 100644 --- a/chrome/installer/util/shell_util.cc +++ b/chrome/installer/util/shell_util.cc @@ -545,11 +545,14 @@ bool ShellUtil::AdminNeededForRegistryCleanup(BrowserDistribution* dist, bool ShellUtil::CreateChromeDesktopShortcut(BrowserDistribution* dist, const std::wstring& chrome_exe, const std::wstring& description, + const std::wstring& appended_name, + const std::wstring& arguments, ShellChange shell_change, bool alternate, bool create_new) { std::wstring shortcut_name; - if (!ShellUtil::GetChromeShortcutName(dist, &shortcut_name, alternate)) + if (!ShellUtil::GetChromeShortcutName(dist, alternate, appended_name, + &shortcut_name)) return false; bool ret = false; @@ -565,18 +568,24 @@ bool ShellUtil::CreateChromeDesktopShortcut(BrowserDistribution* dist, // nothing in it, so let's continue. if (ShellUtil::GetDesktopPath(false, &shortcut_path)) { shortcut = shortcut_path.Append(shortcut_name); - ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe, + ret = ShellUtil::UpdateChromeShortcut(dist, + chrome_exe, shortcut.value(), - description, create_new); + arguments, + description, + create_new); } } } else if (shell_change == ShellUtil::SYSTEM_LEVEL) { FilePath shortcut_path; if (ShellUtil::GetDesktopPath(true, &shortcut_path)) { FilePath shortcut = shortcut_path.Append(shortcut_name); - ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe, + ret = ShellUtil::UpdateChromeShortcut(dist, + chrome_exe, shortcut.value(), - description, create_new); + arguments, + description, + create_new); } } else { NOTREACHED(); @@ -589,7 +598,7 @@ bool ShellUtil::CreateChromeQuickLaunchShortcut(BrowserDistribution* dist, int shell_change, bool create_new) { std::wstring shortcut_name; - if (!ShellUtil::GetChromeShortcutName(dist, &shortcut_name, false)) + if (!ShellUtil::GetChromeShortcutName(dist, false, L"", &shortcut_name)) return false; bool ret = true; @@ -599,7 +608,7 @@ bool ShellUtil::CreateChromeQuickLaunchShortcut(BrowserDistribution* dist, if (ShellUtil::GetQuickLaunchPath(false, &user_ql_path)) { file_util::AppendToPath(&user_ql_path, shortcut_name); ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe, user_ql_path, - L"", create_new); + L"", L"", create_new); } else { ret = false; } @@ -612,7 +621,7 @@ bool ShellUtil::CreateChromeQuickLaunchShortcut(BrowserDistribution* dist, if (ShellUtil::GetQuickLaunchPath(true, &default_ql_path)) { file_util::AppendToPath(&default_ql_path, shortcut_name); ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe, default_ql_path, - L"", create_new) && ret; + L"", L"", create_new) && ret; } else { ret = false; } @@ -634,9 +643,16 @@ std::wstring ShellUtil::GetChromeShellOpenCmd(const std::wstring& chrome_exe) { } bool ShellUtil::GetChromeShortcutName(BrowserDistribution* dist, - std::wstring* shortcut, bool alternate) { + bool alternate, + const std::wstring& appended_name, + std::wstring* shortcut) { shortcut->assign(alternate ? dist->GetAlternateApplicationName() : dist->GetAppShortCutName()); + if (!appended_name.empty()) { + shortcut->append(L" ("); + shortcut->append(appended_name); + shortcut->append(L")"); + } shortcut->append(L".lnk"); return true; } @@ -954,7 +970,8 @@ bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist, bool ShellUtil::RemoveChromeDesktopShortcut(BrowserDistribution* dist, int shell_change, bool alternate) { std::wstring shortcut_name; - if (!ShellUtil::GetChromeShortcutName(dist, &shortcut_name, alternate)) + if (!ShellUtil::GetChromeShortcutName(dist, alternate, L"", + &shortcut_name)) return false; bool ret = true; @@ -980,10 +997,28 @@ bool ShellUtil::RemoveChromeDesktopShortcut(BrowserDistribution* dist, return ret; } +bool ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( + const std::vector<std::wstring>& appended_names) { + FilePath shortcut_path; + bool ret = true; + if (ShellUtil::GetDesktopPath(false, &shortcut_path)) { + for (std::vector<std::wstring>::const_iterator it = + appended_names.begin(); + it != appended_names.end(); + ++it) { + FilePath delete_shortcut = shortcut_path.Append(*it); + ret = ret && file_util::Delete(delete_shortcut, false); + } + } else { + ret = false; + } + return ret; +} + bool ShellUtil::RemoveChromeQuickLaunchShortcut(BrowserDistribution* dist, int shell_change) { std::wstring shortcut_name; - if (!ShellUtil::GetChromeShortcutName(dist, &shortcut_name, false)) + if (!ShellUtil::GetChromeShortcutName(dist, false, L"", &shortcut_name)) return false; bool ret = true; @@ -1015,6 +1050,7 @@ bool ShellUtil::RemoveChromeQuickLaunchShortcut(BrowserDistribution* dist, bool ShellUtil::UpdateChromeShortcut(BrowserDistribution* dist, const std::wstring& chrome_exe, const std::wstring& shortcut, + const std::wstring& arguments, const std::wstring& description, bool create_new) { std::wstring chrome_path = FilePath(chrome_exe).DirName().value(); @@ -1030,7 +1066,7 @@ bool ShellUtil::UpdateChromeShortcut(BrowserDistribution* dist, chrome_exe.c_str(), // target shortcut.c_str(), // shortcut chrome_path.c_str(), // working dir - NULL, // arguments + arguments.c_str(), // arguments description.c_str(), // description chrome_exe.c_str(), // icon file icon_index, // icon index @@ -1040,7 +1076,7 @@ bool ShellUtil::UpdateChromeShortcut(BrowserDistribution* dist, chrome_exe.c_str(), // target shortcut.c_str(), // shortcut chrome_path.c_str(), // working dir - NULL, // arguments + arguments.c_str(), // arguments description.c_str(), // description chrome_exe.c_str(), // icon file icon_index, // icon index diff --git a/chrome/installer/util/shell_util.h b/chrome/installer/util/shell_util.h index fcb0fb8..9b0524a 100644 --- a/chrome/installer/util/shell_util.h +++ b/chrome/installer/util/shell_util.h @@ -20,6 +20,10 @@ class BrowserDistribution; class FilePath; +namespace base { +class DictionaryValue; +} + // This is a utility class that provides common shell integration methods // that can be used by installer as well as Chrome. class ShellUtil { @@ -87,18 +91,26 @@ class ShellUtil { static bool AdminNeededForRegistryCleanup(BrowserDistribution* dist, const std::wstring& suffix); - // Create Chrome shortcut on Desktop - // If shell_change is CURRENT_USER, the shortcut is created in the - // Desktop folder of current user's profile. - // If shell_change is SYSTEM_LEVEL, the shortcut is created in the - // Desktop folder of "All Users" profile. - // If alternate is true, an alternate text for the shortcut is used. - // create_new: If false, will only update the shortcut. If true, the function - // will create a new shortcut if it doesn't exist already. + // Creates Chrome shortcut on the Desktop. + // |dist| gives the type of browser distribution currently in use. + // |chrome_exe| provides the target path information. + // |description| provides the shortcut's "comment" property. + // |appended_name| provides a string to be appended to the distribution name, + // and can be the empty string. + // |arguments| gives a set of arguments to be passed to the executable. + // If |shell_change| is CURRENT_USER, the shortcut is created in the + // Desktop folder of current user's profile. + // If |shell_change| is SYSTEM_LEVEL, the shortcut is created in the + // Desktop folder of the "All Users" profile. + // If |alternate| is true, an alternate text for the shortcut is used. + // If |create_new| is false, an existing shortcut will be updated, but if + // no shortcut exists, it will not be created. // Returns true iff the method causes a shortcut to be created / updated. static bool CreateChromeDesktopShortcut(BrowserDistribution* dist, const std::wstring& chrome_exe, const std::wstring& description, + const std::wstring& appended_name, + const std::wstring& arguments, ShellChange shell_change, bool alternate, bool create_new); @@ -129,11 +141,14 @@ class ShellUtil { // chrome_exe: the full path to chrome.exe static std::wstring GetChromeShellOpenCmd(const std::wstring& chrome_exe); - // Returns the localized name of Chrome shortcut. If |alternate| is true - // it returns a second localized text that is better suited for certain - // scenarios. + // Returns the localized name of Chrome shortcut in |shortcut|. If + // |appended_name| is not empty, it is included in the shortcut name. If + // |alternate| is true, a second localized text that is better suited for + // certain scenarios is used. static bool GetChromeShortcutName(BrowserDistribution* dist, - std::wstring* shortcut, bool alternate); + bool alternate, + const std::wstring& appended_name, + std::wstring* shortcut); // Gets the desktop path for the current user or all users (if system_level // is true) and returns it in 'path' argument. Return true if successful, @@ -250,7 +265,14 @@ class ShellUtil { // If alternate is true, the shortcut with the alternate name is removed. See // CreateChromeDesktopShortcut() for more information. static bool RemoveChromeDesktopShortcut(BrowserDistribution* dist, - int shell_change, bool alternate); + int shell_change, + bool alternate); + + // Removes a set of existing Chrome desktop shortcuts. |appended_names| is a + // list of shortcut file names as obtained from + // ShellUtil::GetChromeShortcutName. + static bool RemoveChromeDesktopShortcutsWithAppendedNames( + const std::vector<std::wstring>& appended_names); // Remove Chrome shortcut from Quick Launch Bar. // If shell_change is CURRENT_USER, the shortcut is removed from @@ -261,13 +283,14 @@ class ShellUtil { int shell_change); // Updates shortcut (or creates a new shortcut) at destination given by - // shortcut to a target given by chrome_exe. The arguments is left NULL - // for the target and icon is set as icon at index 0 from exe. + // shortcut to a target given by chrome_exe. The arguments are given by + // |arguments| for the target and icon is set as icon at index 0 from exe. // If create_new is set to true, the function will create a new shortcut if // if doesn't exist. static bool UpdateChromeShortcut(BrowserDistribution* dist, const std::wstring& chrome_exe, const std::wstring& shortcut, + const std::wstring& arguments, const std::wstring& description, bool create_new); diff --git a/chrome/installer/util/shell_util_unittest.cc b/chrome/installer/util/shell_util_unittest.cc index f6d3dd1..625010e 100644 --- a/chrome/installer/util/shell_util_unittest.cc +++ b/chrome/installer/util/shell_util_unittest.cc @@ -109,9 +109,12 @@ TEST_F(ShellUtilTest, UpdateChromeShortcutTest) { FilePath shortcut_path = temp_dir_.path().AppendASCII("shortcut.lnk"); const std::wstring description(L"dummy description"); - EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, exe_path.value(), + EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, + exe_path.value(), shortcut_path.value(), - description, true)); + L"", + description, + true)); EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), shortcut_path.value(), description, 0)); @@ -130,9 +133,12 @@ TEST_F(ShellUtilTest, UpdateChromeShortcutTest) { "}"; file.close(); ASSERT_TRUE(file_util::Delete(shortcut_path, false)); - EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, exe_path.value(), + EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, + exe_path.value(), shortcut_path.value(), - description, true)); + L"", + description, + true)); EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), shortcut_path.value(), description, 1)); @@ -140,9 +146,12 @@ TEST_F(ShellUtilTest, UpdateChromeShortcutTest) { // Now change only description to update shortcut and make sure icon index // doesn't change. const std::wstring description2(L"dummy description 2"); - EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, exe_path.value(), + EXPECT_TRUE(ShellUtil::UpdateChromeShortcut(dist, + exe_path.value(), shortcut_path.value(), - description2, false)); + L"", + description2, + false)); EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), shortcut_path.value(), description2, 1)); @@ -173,15 +182,34 @@ TEST_F(ShellUtilTest, CreateChromeDesktopShortcutTest) { EXPECT_TRUE(ShellUtil::GetDesktopPath(true, &system_desktop_path)); std::wstring shortcut_name; - EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, &shortcut_name, false)); + EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, false, L"", + &shortcut_name)); + + std::wstring default_profile_shortcut_name; + const std::wstring default_profile_user_name = L"Minsk"; + EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, false, + default_profile_user_name, + &default_profile_shortcut_name)); + + std::wstring second_profile_shortcut_name; + const std::wstring second_profile_user_name = L"Pinsk"; + EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, false, + second_profile_user_name, + &second_profile_shortcut_name)); FilePath user_shortcut_path = user_desktop_path.Append(shortcut_name); FilePath system_shortcut_path = system_desktop_path.Append(shortcut_name); + FilePath default_profile_shortcut_path = user_desktop_path.Append( + default_profile_shortcut_name); + FilePath second_profile_shortcut_path = user_desktop_path.Append( + second_profile_shortcut_name); // Test simple creation of a user-level shortcut. EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, exe_path.value(), description, + L"", + L"", ShellUtil::CURRENT_USER, false, true)); @@ -197,6 +225,8 @@ TEST_F(ShellUtilTest, CreateChromeDesktopShortcutTest) { EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, exe_path.value(), description, + L"", + L"", ShellUtil::SYSTEM_LEVEL, false, true)); @@ -213,12 +243,16 @@ TEST_F(ShellUtilTest, CreateChromeDesktopShortcutTest) { EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, exe_path.value(), description, + L"", + L"", ShellUtil::SYSTEM_LEVEL, false, true)); EXPECT_FALSE(ShellUtil::CreateChromeDesktopShortcut(dist, exe_path.value(), description, + L"", + L"", ShellUtil::CURRENT_USER, false, true)); @@ -236,12 +270,16 @@ TEST_F(ShellUtilTest, CreateChromeDesktopShortcutTest) { EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, exe_path.value(), description, + L"", + L"", ShellUtil::CURRENT_USER, false, true)); EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut(dist, exe_path.value(), description, + L"", + L"", ShellUtil::SYSTEM_LEVEL, false, true)); @@ -259,4 +297,38 @@ TEST_F(ShellUtilTest, CreateChromeDesktopShortcutTest) { EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcut(dist, ShellUtil::SYSTEM_LEVEL, false)); + + // Test creation of two profile-specific shortcuts (these are always + // user-level). + EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( + dist, + exe_path.value(), + description, + default_profile_user_name, + L"--profile-directory=\"Default\"", + ShellUtil::CURRENT_USER, + false, + true)); + EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), + default_profile_shortcut_path.value(), + description, + 0)); + EXPECT_TRUE(ShellUtil::CreateChromeDesktopShortcut( + dist, + exe_path.value(), + description, + second_profile_user_name, + L"--profile-directory=\"Profile 1\"", + ShellUtil::CURRENT_USER, + false, + true)); + EXPECT_TRUE(VerifyChromeShortcut(exe_path.value(), + second_profile_shortcut_path.value(), + description, + 0)); + std::vector<string16> profile_names; + profile_names.push_back(default_profile_shortcut_name); + profile_names.push_back(second_profile_shortcut_name); + EXPECT_TRUE(ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames( + profile_names)); } |