summaryrefslogtreecommitdiffstats
path: root/chrome/browser/profiles
diff options
context:
space:
mode:
authorgab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-05 01:34:05 +0000
committergab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-05 01:34:05 +0000
commit126f4623cb88b29c875795b61b3fdec2b9452462 (patch)
treedcf1d78d5c8f90481fc3d4351d56b1b1734f5e1f /chrome/browser/profiles
parent5f3da203452e182901053f07b33ddfa0a22e337c (diff)
downloadchromium_src-126f4623cb88b29c875795b61b3fdec2b9452462.zip
chromium_src-126f4623cb88b29c875795b61b3fdec2b9452462.tar.gz
chromium_src-126f4623cb88b29c875795b61b3fdec2b9452462.tar.bz2
Refactor ShellUtil shortcut code -- single multi-purpose methods as opposed to many slighlty different methods.
Merge Quick Launch + Desktop logic into same call and add start menu shortcut logic in the mix too. Make properties based API (like the one introduced in base/win/shortcut.h) with default values to simplify call sites who just want to create a basic Chrome shortcut. shell_util.h: (CreateChromeDesktopShortcut, CreateChromeQuickLaunchShortcut, UpdateChromeShortcut) => CreateOrUpdateChromeShortcut (GetDesktopPath, GetQuickLaunchPath) => GetShortcutPath (GetChromeShortcutName) => ChromeShortcutProperties::set_shortcut_name() (i.e. default name is GetAppShortcutName() unless set otherwise... special profile shortcut appending logic moved to ProfileShortcutManager::GetShortcutNameForProfile). (RemoveChromeDesktopShortcut, RemoveChromeDesktopShortcutsWithAppendedNames) => RemoveChromeShortcut install.h: (CreateOrUpdateStartMenuAndTaskbarShortcuts, CreateOrUpdateDesktopAndQuickLaunchShortcuts) => CreateOrUpdateShortcuts (and incorporate some of the logic previously handled directly in InstallOrUpdateProduct()). Finally thoroughly tests shell_util and install shortcut methods! BUG=148539 TEST=Install chrome at user and system level with and without create_all_shortcuts master pref and make sure it works as intended in all scenarios. installer_util_unittests.exe --gtest_filter=ShellUtilShortcutTest* setup_unittests.exe --gtest_filter=InstallShortcutTest* unit_tests.exe --gtest_filter=ProfileShortcutManagerTest* Review URL: https://chromiumcodereview.appspot.com/10836247 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160284 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/profiles')
-rw-r--r--chrome/browser/profiles/profile_shortcut_manager.h3
-rw-r--r--chrome/browser/profiles/profile_shortcut_manager_stub.cc7
-rw-r--r--chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc9
-rw-r--r--chrome/browser/profiles/profile_shortcut_manager_win.cc87
4 files changed, 59 insertions, 47 deletions
diff --git a/chrome/browser/profiles/profile_shortcut_manager.h b/chrome/browser/profiles/profile_shortcut_manager.h
index 171fa5c..29ae7ba 100644
--- a/chrome/browser/profiles/profile_shortcut_manager.h
+++ b/chrome/browser/profiles/profile_shortcut_manager.h
@@ -6,8 +6,8 @@
#define CHROME_BROWSER_PROFILES_PROFILE_SHORTCUT_MANAGER_H_
#include "base/file_path.h"
+#include "base/string16.h"
#include "chrome/browser/profiles/profile_info_cache.h"
-#include "ui/gfx/image/image.h"
class ProfileManager;
@@ -22,6 +22,7 @@ class ProfileShortcutManager {
static bool IsFeatureEnabled();
static ProfileShortcutManager* Create(ProfileManager* manager);
+ static string16 GetShortcutNameForProfile(const string16& profile_name);
protected:
ProfileShortcutManager();
diff --git a/chrome/browser/profiles/profile_shortcut_manager_stub.cc b/chrome/browser/profiles/profile_shortcut_manager_stub.cc
index b1a0a0e..858251e 100644
--- a/chrome/browser/profiles/profile_shortcut_manager_stub.cc
+++ b/chrome/browser/profiles/profile_shortcut_manager_stub.cc
@@ -14,3 +14,10 @@ ProfileShortcutManager* ProfileShortcutManager::Create(
ProfileManager* manager) {
return NULL;
}
+
+// static
+string16 ProfileShortcutManager::GetShortcutNameForProfile(
+ const string16& profile_name) {
+ NOTREACHED();
+ return string16();
+}
diff --git a/chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc b/chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc
index 1950d18e..c7531d7 100644
--- a/chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc
+++ b/chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc
@@ -6,6 +6,7 @@
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/scoped_temp_dir.h"
+#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "base/test/test_shortcut_win.h"
#include "base/win/shortcut.h"
@@ -32,10 +33,10 @@ namespace {
void GetShortcutPathForProfile(BrowserDistribution* dist,
const string16& profile_name,
FilePath* path) {
- string16 shortcut_name;
- EXPECT_TRUE(ShellUtil::GetDesktopPath(false, path));
- EXPECT_TRUE(ShellUtil::GetChromeShortcutName(dist, false, profile_name,
- &shortcut_name));
+ EXPECT_TRUE(ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_DESKTOP, dist,
+ ShellUtil::CURRENT_USER, path));
+ string16 shortcut_name(
+ ProfileShortcutManager::GetShortcutNameForProfile(profile_name));
*path = path->Append(shortcut_name);
}
diff --git a/chrome/browser/profiles/profile_shortcut_manager_win.cc b/chrome/browser/profiles/profile_shortcut_manager_win.cc
index 2619449..25d34a6 100644
--- a/chrome/browser/profiles/profile_shortcut_manager_win.cc
+++ b/chrome/browser/profiles/profile_shortcut_manager_win.cc
@@ -32,6 +32,7 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/icon_util.h"
+#include "ui/gfx/image/image.h"
using content::BrowserThread;
@@ -120,9 +121,10 @@ void RenameChromeDesktopShortcutForProfile(
const string16& old_shortcut_file,
const string16& new_shortcut_file) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ BrowserDistribution* dist = BrowserDistribution::GetDistribution();
FilePath shortcut_path;
- if (ShellUtil::GetDesktopPath(false, // User's directory instead of system.
- &shortcut_path)) {
+ if (ShellUtil::GetShortcutPath(ShellUtil::SHORTCUT_DESKTOP, dist,
+ ShellUtil::CURRENT_USER, &shortcut_path)) {
FilePath old_shortcut_path = shortcut_path.Append(old_shortcut_file);
FilePath new_shortcut_path = shortcut_path.Append(new_shortcut_file);
if (!file_util::Move(old_shortcut_path, new_shortcut_path))
@@ -142,25 +144,24 @@ void CreateOrUpdateProfileDesktopShortcut(
CreateChromeDesktopShortcutIconForProfile(profile_path, avatar_image);
FilePath chrome_exe;
- if (!PathService::Get(base::FILE_EXE, &chrome_exe))
+ if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
+ NOTREACHED();
return;
+ }
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
- if (!dist)
- return;
- string16 description(dist->GetAppDescription());
-
- uint32 options = create ? ShellUtil::SHORTCUT_CREATE_ALWAYS :
- ShellUtil::SHORTCUT_NO_OPTIONS;
- ShellUtil::CreateChromeDesktopShortcut(
- dist,
- chrome_exe.value(),
- description,
- profile_name,
- CreateProfileShortcutFlags(profile_path),
- shortcut_icon.empty() ? chrome_exe.value() : shortcut_icon.value(),
- shortcut_icon.empty() ? dist->GetIconIndex() : 0,
- ShellUtil::CURRENT_USER,
- options);
+
+ ShellUtil::ChromeShortcutProperties properties(ShellUtil::CURRENT_USER);
+ properties.set_chrome_exe(chrome_exe);
+ properties.set_arguments(CreateProfileShortcutFlags(profile_path));
+ if (!shortcut_icon.empty())
+ properties.set_icon(shortcut_icon);
+ properties.set_shortcut_name(
+ ProfileShortcutManager::GetShortcutNameForProfile(profile_name));
+ ShellUtil::ChromeShortcutOperation operation =
+ create ? ShellUtil::SHORTCUT_CREATE_ALWAYS :
+ ShellUtil::SHORTCUT_REPLACE_EXISTING;
+ ShellUtil::CreateOrUpdateChromeShortcut(
+ ShellUtil::SHORTCUT_DESKTOP, dist, properties, operation);
}
} // namespace
@@ -207,6 +208,17 @@ ProfileShortcutManager* ProfileShortcutManager::Create(
return new ProfileShortcutManagerWin(manager);
}
+// static
+string16 ProfileShortcutManager::GetShortcutNameForProfile(
+ const string16& profile_name) {
+ BrowserDistribution* dist = BrowserDistribution::GetDistribution();
+ string16 shortcut_name(dist->GetAppShortCutName());
+ shortcut_name.append(L" (");
+ shortcut_name.append(profile_name);
+ shortcut_name.append(L")");
+ return shortcut_name;
+}
+
ProfileShortcutManagerWin::ProfileShortcutManagerWin(ProfileManager* manager)
: profile_manager_(manager) {
profile_manager_->GetProfileInfoCache().AddObserver(this);
@@ -251,17 +263,13 @@ void ProfileShortcutManagerWin::OnProfileWasRemoved(
profile_name_updated = profile_name;
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
- string16 shortcut;
- // If we can find the shortcut, delete it
- if (ShellUtil::GetChromeShortcutName(dist, false,
- profile_name_updated, &shortcut)) {
- std::vector<string16> appended_names(1, shortcut);
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&CallBoolFunction, base::Bind(
- &ShellUtil::RemoveChromeDesktopShortcutsWithAppendedNames,
- appended_names)));
- }
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&CallBoolFunction, base::Bind(
+ &ShellUtil::RemoveChromeShortcut, ShellUtil::SHORTCUT_DESKTOP,
+ dist, ShellUtil::CURRENT_USER,
+ &GetShortcutNameForProfile(profile_name_updated))));
+
FilePath icon_path = profile_path.AppendASCII(kProfileIconFileName);
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
@@ -294,19 +302,14 @@ void ProfileShortcutManagerWin::StartProfileShortcutNameChange(
profile_manager_->GetProfileInfoCache().
GetNameOfProfileAtIndex(profile_index);
- string16 old_shortcut_file;
- string16 new_shortcut_file;
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
- if (ShellUtil::GetChromeShortcutName(
- dist, false, old_profile_name, &old_shortcut_file) &&
- ShellUtil::GetChromeShortcutName(
- dist, false, new_profile_name, &new_shortcut_file)) {
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&RenameChromeDesktopShortcutForProfile,
- old_shortcut_file,
- new_shortcut_file));
- }
+ string16 old_shortcut_file(GetShortcutNameForProfile(old_profile_name));
+ string16 new_shortcut_file(GetShortcutNameForProfile(new_profile_name));
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&RenameChromeDesktopShortcutForProfile,
+ old_shortcut_file,
+ new_shortcut_file));
}
FilePath ProfileShortcutManagerWin::GetOtherProfilePath(