diff options
author | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-31 18:51:24 +0000 |
---|---|---|
committer | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-31 18:51:24 +0000 |
commit | 41be73b07e066fb4eba93baabfb1ef8dbe7b0aeb (patch) | |
tree | 62aa5c0816caf6038d7bb7aeedfc74dc5844212d | |
parent | 923fe9d51fe0d139a66f9ba8e77a7f8ebcdb1e55 (diff) | |
download | chromium_src-41be73b07e066fb4eba93baabfb1ef8dbe7b0aeb.zip chromium_src-41be73b07e066fb4eba93baabfb1ef8dbe7b0aeb.tar.gz chromium_src-41be73b07e066fb4eba93baabfb1ef8dbe7b0aeb.tar.bz2 |
Merge 79297 - 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
TBR=robertshield@chromium.org
Review URL: http://codereview.chromium.org/6780034
git-svn-id: svn://svn.chromium.org/chrome/branches/696/src@80035 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/installer/util/shell_util.cc | 63 | ||||
-rw-r--r-- | chrome/installer/util/shell_util.h | 7 |
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 |