diff options
author | gab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-20 16:24:52 +0000 |
---|---|---|
committer | gab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-20 16:24:52 +0000 |
commit | dea1d7d21976d078a41b2d321e8d626379c7a1fd (patch) | |
tree | 02587faedfbf8242cc8b557874d3c37a435739de /base/base_paths_win.cc | |
parent | 6c2e391ce50adde6f5080245b1256838656063d3 (diff) | |
download | chromium_src-dea1d7d21976d078a41b2d321e8d626379c7a1fd.zip chromium_src-dea1d7d21976d078a41b2d321e8d626379c7a1fd.tar.gz chromium_src-dea1d7d21976d078a41b2d321e8d626379c7a1fd.tar.bz2 |
Add new PathService paths for Windows' All Users Desktop and Quick Launch folders.
Re-commit, reverted in http://crrev.com/157680 (original commit in http://crrev.com/157667).
This allows usage of PathService to cache the shortcut install paths and more importantly to mock them in shortcut tests!
Also move chrome::DIR_USER_DESKTOP to base::DIR_USER_DESKTOP; this is really where it belongs. In fact it is only in chrome_paths.h because it used to be called DIR_DEFAULT_DOWNLOAD and cpu@ renamed it to DIR_USER_DESKTOP in http://crrev.com/1753 (early days!) after that it started to be used all over the place as the Desktop path. Finally bringing it to base_paths.h, beside DIR_START_MENU and friends, is the right thing to do imo.
TBR=brettw@chromium.org
BUG=148539
TEST=Quick Launch shortcut installed in the right place on XP (both Default and current user)
Desktop shortcuts installed in the right place (both All Users and per-user installs).
installer_util_unittests.exe --gtest_filter=ShellUtilShortcutTest*
unit_tests.exe --gtest_filter=ProfileShortcutManagerTest*
base_unittests --gtest_filter=PathServiceTest*
Review URL: https://chromiumcodereview.appspot.com/10964007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157779 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/base_paths_win.cc')
-rw-r--r-- | base/base_paths_win.cc | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/base/base_paths_win.cc b/base/base_paths_win.cc index 48238a4..58c3ea5 100644 --- a/base/base_paths_win.cc +++ b/base/base_paths_win.cc @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/base_paths_win.h" #include <windows.h> #include <shlobj.h> +#include "base/base_paths.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/path_service.h" @@ -16,6 +16,38 @@ // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx extern "C" IMAGE_DOS_HEADER __ImageBase; +namespace { + +bool GetQuickLaunchPath(bool default_user, FilePath* result) { + if (default_user) { + wchar_t system_buffer[MAX_PATH]; + system_buffer[0] = 0; + // As per MSDN, passing -1 for |hToken| indicates the Default user: + // http://msdn.microsoft.com/library/windows/desktop/bb762181.aspx + if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, + reinterpret_cast<HANDLE>(-1), SHGFP_TYPE_CURRENT, + system_buffer))) { + return false; + } + *result = FilePath(system_buffer); + } else if (!PathService::Get(base::DIR_APP_DATA, result)) { + // For the current user, grab the APPDATA directory directly from the + // PathService cache. + return false; + } + // According to various sources, appending + // "Microsoft\Internet Explorer\Quick Launch" to %appdata% is the only + // reliable way to get the quick launch folder across all versions of Windows. + // http://stackoverflow.com/questions/76080/how-do-you-reliably-get-the-quick- + // http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept05/hey0901.mspx + *result = result->AppendASCII("Microsoft"); + *result = result->AppendASCII("Internet Explorer"); + *result = result->AppendASCII("Quick Launch"); + return true; +} + +} // namespace + namespace base { bool PathProviderWin(int key, FilePath* result) { @@ -103,9 +135,9 @@ bool PathProviderWin(int key, FilePath* result) { cur = FilePath(system_buffer); break; case base::DIR_LOCAL_APP_DATA_LOW: - if (win::GetVersion() < win::VERSION_VISTA) { + if (win::GetVersion() < win::VERSION_VISTA) return false; - } + // TODO(nsylvain): We should use SHGetKnownFolderPath instead. Bug 1281128 if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, system_buffer))) @@ -138,6 +170,28 @@ bool PathProviderWin(int key, FilePath* result) { cur = FilePath(string16(path_buf)); break; } + case base::DIR_USER_DESKTOP: + if (FAILED(SHGetFolderPath(NULL, CSIDL_DESKTOPDIRECTORY, NULL, + SHGFP_TYPE_CURRENT, system_buffer))) { + return false; + } + cur = FilePath(system_buffer); + break; + case base::DIR_COMMON_DESKTOP: + if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_DESKTOPDIRECTORY, NULL, + SHGFP_TYPE_CURRENT, system_buffer))) { + return false; + } + cur = FilePath(system_buffer); + break; + case base::DIR_USER_QUICK_LAUNCH: + if (!GetQuickLaunchPath(false, &cur)) + return false; + break; + case base::DIR_DEFAULT_USER_QUICK_LAUNCH: + if (!GetQuickLaunchPath(true, &cur)) + return false; + break; default: return false; } |