summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-24 17:57:31 +0000
committerrobertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-24 17:57:31 +0000
commit5ae947c38fb3ddc694dc669f8bc5ef59ec3be2f9 (patch)
tree6a99d6eec83527384b913f8d8fe26aed7fa49a8f
parent80650eba537635f67578fa618f6b7134e215d4f1 (diff)
downloadchromium_src-5ae947c38fb3ddc694dc669f8bc5ef59ec3be2f9.zip
chromium_src-5ae947c38fb3ddc694dc669f8bc5ef59ec3be2f9.tar.gz
chromium_src-5ae947c38fb3ddc694dc669f8bc5ef59ec3be2f9.tar.bz2
Correct the duplicate creation of desktop shortcuts that can occur when system-level chrome creates a shortcut in the user's current desktop.
BUG=5073 TEST=Install system-level Chrome, observe a Chrome shortcut is created in the All Users desktop. Run Chrome, observe that no duplicate shortcut is created. Review URL: http://codereview.chromium.org/6731018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79297 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/installer/util/shell_util.cc63
-rw-r--r--chrome/installer/util/shell_util.h7
2 files changed, 40 insertions, 30 deletions
diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc
index 0f49ebc..db2c0e8 100644
--- a/chrome/installer/util/shell_util.cc
+++ b/chrome/installer/util/shell_util.cc
@@ -443,34 +443,41 @@ bool ShellUtil::AdminNeededForRegistryCleanup(BrowserDistribution* dist,
bool ShellUtil::CreateChromeDesktopShortcut(BrowserDistribution* dist,
const std::wstring& chrome_exe,
const std::wstring& description,
- int shell_change, bool alternate,
+ ShellChange shell_change,
+ bool alternate,
bool create_new) {
std::wstring shortcut_name;
if (!ShellUtil::GetChromeShortcutName(dist, &shortcut_name, alternate))
return false;
- bool ret = true;
- if (shell_change & ShellUtil::CURRENT_USER) {
- std::wstring shortcut_path;
- if (ShellUtil::GetDesktopPath(false, &shortcut_path)) {
- file_util::AppendToPath(&shortcut_path, shortcut_name);
- ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe, shortcut_path,
- description, create_new);
- } else {
- ret = false;
+ bool ret = false;
+ if (shell_change == ShellUtil::CURRENT_USER) {
+ FilePath shortcut_path;
+ // We do not want to create a desktop shortcut to Chrome in the current
+ // user's desktop folder if there is already one in the "All Users"
+ // desktop folder.
+ bool got_system_desktop = ShellUtil::GetDesktopPath(true, &shortcut_path);
+ FilePath shortcut = shortcut_path.Append(shortcut_name);
+ if (!got_system_desktop || !file_util::PathExists(shortcut_path)) {
+ // Either we couldn't query the "All Users" Desktop folder or there's
+ // 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,
+ shortcut.value(),
+ description, create_new);
+ }
}
- }
- if (shell_change & ShellUtil::SYSTEM_LEVEL) {
- std::wstring shortcut_path;
+ } else if (shell_change == ShellUtil::SYSTEM_LEVEL) {
+ FilePath shortcut_path;
if (ShellUtil::GetDesktopPath(true, &shortcut_path)) {
- file_util::AppendToPath(&shortcut_path, shortcut_name);
- // Note we need to call the create operation and then AND the result
- // with the create operation of user level shortcut.
- ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe, shortcut_path,
- description, create_new) && ret;
- } else {
- ret = false;
+ FilePath shortcut = shortcut_path.Append(shortcut_name);
+ ret = ShellUtil::UpdateChromeShortcut(dist, chrome_exe,
+ shortcut.value(),
+ description, create_new);
}
+ } else {
+ NOTREACHED();
}
return ret;
}
@@ -532,13 +539,13 @@ bool ShellUtil::GetChromeShortcutName(BrowserDistribution* dist,
return true;
}
-bool ShellUtil::GetDesktopPath(bool system_level, std::wstring* path) {
+bool ShellUtil::GetDesktopPath(bool system_level, FilePath* path) {
wchar_t desktop[MAX_PATH];
int dir = system_level ? CSIDL_COMMON_DESKTOPDIRECTORY :
CSIDL_DESKTOPDIRECTORY;
if (FAILED(SHGetFolderPath(NULL, dir, NULL, SHGFP_TYPE_CURRENT, desktop)))
return false;
- *path = desktop;
+ *path = FilePath(desktop);
return true;
}
@@ -728,20 +735,20 @@ bool ShellUtil::RemoveChromeDesktopShortcut(BrowserDistribution* dist,
bool ret = true;
if (shell_change & ShellUtil::CURRENT_USER) {
- std::wstring shortcut_path;
+ FilePath shortcut_path;
if (ShellUtil::GetDesktopPath(false, &shortcut_path)) {
- file_util::AppendToPath(&shortcut_path, shortcut_name);
- ret = file_util::Delete(shortcut_path, false);
+ FilePath shortcut = shortcut_path.Append(shortcut_name);
+ ret = file_util::Delete(shortcut, false);
} else {
ret = false;
}
}
if (shell_change & ShellUtil::SYSTEM_LEVEL) {
- std::wstring shortcut_path;
+ FilePath shortcut_path;
if (ShellUtil::GetDesktopPath(true, &shortcut_path)) {
- file_util::AppendToPath(&shortcut_path, shortcut_name);
- ret = file_util::Delete(shortcut_path, false) && ret;
+ FilePath shortcut = shortcut_path.Append(shortcut_name);
+ ret = file_util::Delete(shortcut, false) && ret;
} else {
ret = false;
}
diff --git a/chrome/installer/util/shell_util.h b/chrome/installer/util/shell_util.h
index 5df73c6..b34f4f6 100644
--- a/chrome/installer/util/shell_util.h
+++ b/chrome/installer/util/shell_util.h
@@ -18,6 +18,7 @@
#include "chrome/installer/util/work_item_list.h"
class BrowserDistribution;
+class FilePath;
// This is a utility class that provides common shell integration methods
// that can be used by installer as well as Chrome.
@@ -87,10 +88,12 @@ class ShellUtil {
// 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.
+ // 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,
- int shell_change, bool alternate,
+ ShellChange shell_change,
+ bool alternate,
bool create_new);
// Create Chrome shortcut on Quick Launch Bar.
@@ -128,7 +131,7 @@ class ShellUtil {
// 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,
// otherwise returns false.
- static bool GetDesktopPath(bool system_level, std::wstring* path);
+ static bool GetDesktopPath(bool system_level, FilePath* path);
// Gets the Quick Launch shortcuts path for the current user and
// returns it in 'path' argument. Return true if successful, otherwise