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 | |
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
28 files changed, 232 insertions, 152 deletions
diff --git a/base/base.gypi b/base/base.gypi index 0652249..c4e14ad 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -63,6 +63,7 @@ 'base_paths_mac.h', 'base_paths_mac.mm', 'base_paths_posix.cc', + 'base_paths_posix.h', 'base_paths_win.cc', 'base_paths_win.h', 'base_switches.h', diff --git a/base/base_paths.cc b/base/base_paths.cc index 1beb9c7..80105b6 100644 --- a/base/base_paths.cc +++ b/base/base_paths.cc @@ -11,7 +11,7 @@ namespace base { bool PathProvider(int key, FilePath* result) { - // NOTE: DIR_CURRENT is a special cased in PathService::Get + // NOTE: DIR_CURRENT is a special case in PathService::Get FilePath cur; switch (key) { diff --git a/base/base_paths.h b/base/base_paths.h index 39edd16..3251a84 100644 --- a/base/base_paths.h +++ b/base/base_paths.h @@ -18,6 +18,10 @@ #include "base/base_paths_android.h" #endif +#if defined(OS_POSIX) +#include "base/base_paths_posix.h" +#endif + namespace base { enum BasePathKey { @@ -34,17 +38,7 @@ enum BasePathKey { DIR_SOURCE_ROOT, // Returns the root of the source tree. This key is useful // for tests that need to locate various resources. It // should not be used outside of test code. -#if defined(OS_POSIX) - DIR_CACHE, // Directory where to put cache data. Note this is - // *not* where the browser cache lives, but the - // browser cache can be a subdirectory. - // This is $XDG_CACHE_HOME on Linux and - // ~/Library/Caches on Mac. - DIR_HOME, // $HOME on POSIX-like systems. -#endif -#if defined(OS_ANDROID) - DIR_ANDROID_EXTERNAL_STORAGE, // Android external storage directory. -#endif + DIR_USER_DESKTOP, // The current user's Desktop. PATH_END }; diff --git a/base/base_paths_android.cc b/base/base_paths_android.cc index f631c61..ab14ee3 100644 --- a/base/base_paths_android.cc +++ b/base/base_paths_android.cc @@ -2,12 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/base_paths.h" +// Defines base::PathProviderAndroid which replaces base::PathProviderPosix for +// Android in base/path_service.cc. #include <unistd.h> #include "base/android/jni_android.h" #include "base/android/path_utils.h" +#include "base/base_paths.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/logging.h" @@ -28,42 +30,38 @@ bool PathProviderAndroid(int key, FilePath* result) { *result = FilePath(bin_dir); return true; } - case base::FILE_MODULE: { + case base::FILE_MODULE: // dladdr didn't work in Android as only the file name was returned. NOTIMPLEMENTED(); return false; - } - case base::DIR_MODULE: { + case base::DIR_MODULE: *result = FilePath(base::android::GetNativeLibraryDirectory()); return true; - } - case base::DIR_SOURCE_ROOT: { + case base::DIR_SOURCE_ROOT: // This const is only used for tests. *result = FilePath(base::android::GetExternalStorageDirectory()); return true; - } - case base::DIR_CACHE: { + case base::DIR_USER_DESKTOP: + // Android doesn't support GetUserDesktop. + NOTIMPLEMENTED(); + return false; + case base::DIR_CACHE: *result = FilePath(base::android::GetCacheDirectory()); return true; - } - case base::DIR_ANDROID_APP_DATA: { + case base::DIR_ANDROID_APP_DATA: *result = FilePath(base::android::GetDataDirectory()); return true; - } - case base::DIR_HOME: { + case base::DIR_HOME: *result = file_util::GetHomeDir(); return true; - } - case base::DIR_ANDROID_EXTERNAL_STORAGE: { + case base::DIR_ANDROID_EXTERNAL_STORAGE: *result = FilePath(base::android::GetExternalStorageDirectory()); return true; - } - default: { + default: // Note: the path system expects this function to override the default // behavior. So no need to log an error if we don't support a given // path. The system will just use the default. return false; - } } } diff --git a/base/base_paths_android.h b/base/base_paths_android.h index 8e59b87..7a9ac4a 100644 --- a/base/base_paths_android.h +++ b/base/base_paths_android.h @@ -15,6 +15,7 @@ enum { PATH_ANDROID_START = 300, DIR_ANDROID_APP_DATA, // Directory where to put Android app's data. + DIR_ANDROID_EXTERNAL_STORAGE, // Android external storage directory. PATH_ANDROID_END }; diff --git a/base/base_paths_mac.mm b/base/base_paths_mac.mm index 14d1c20..2227d7d 100644 --- a/base/base_paths_mac.mm +++ b/base/base_paths_mac.mm @@ -2,12 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/base_paths_mac.h" +// Defines base::PathProviderMac which replaces base::PathProviderPosix for Mac +// in base/path_service.cc. #include <dlfcn.h> #import <Foundation/Foundation.h> #include <mach-o/dyld.h> +#include "base/base_paths.h" #include "base/compiler_specific.h" #include "base/file_path.h" #include "base/file_util.h" @@ -15,6 +17,7 @@ #include "base/mac/foundation_util.h" #include "base/path_service.h" #include "base/string_util.h" +#include "build/build_config.h" namespace { @@ -57,8 +60,6 @@ bool PathProviderMac(int key, FilePath* result) { case base::FILE_MODULE: return GetModulePathForAddress(result, reinterpret_cast<const void*>(&base::PathProviderMac)); - case base::DIR_CACHE: - return base::mac::GetUserDirectory(NSCachesDirectory, result); case base::DIR_APP_DATA: { bool success = base::mac::GetUserDirectory(NSApplicationSupportDirectory, result); @@ -69,7 +70,7 @@ bool PathProviderMac(int key, FilePath* result) { #endif // defined(OS_IOS) return success; } - case base::DIR_SOURCE_ROOT: { + case base::DIR_SOURCE_ROOT: // Go through PathService to catch overrides. if (!PathService::Get(base::FILE_EXE, result)) return false; @@ -90,11 +91,13 @@ bool PathProviderMac(int key, FilePath* result) { } #endif return true; - } - case base::DIR_HOME: { + case base::DIR_USER_DESKTOP: + return base::mac::GetUserDirectory(NSDesktopDirectory, result); + case base::DIR_CACHE: + return base::mac::GetUserDirectory(NSCachesDirectory, result); + case base::DIR_HOME: *result = base::mac::NSStringToFilePath(NSHomeDirectory()); return true; - } default: return false; } diff --git a/base/base_paths_posix.cc b/base/base_paths_posix.cc index 95e7585..834dee3 100644 --- a/base/base_paths_posix.cc +++ b/base/base_paths_posix.cc @@ -2,12 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/base_paths.h" +// Defines base::PathProviderPosix, default path provider on POSIX OSes that +// don't have their own base_paths_OS.cc implementation (i.e. all but Mac and +// Android). #include <ostream> #include <string> -#include "build/build_config.h" +#include "base/base_paths.h" #include "base/environment.h" #include "base/file_path.h" #include "base/file_util.h" @@ -16,6 +18,7 @@ #include "base/path_service.h" #include "base/process_util.h" #include "base/nix/xdg_util.h" +#include "build/build_config.h" #if defined(OS_FREEBSD) #include <sys/param.h> @@ -96,6 +99,9 @@ bool PathProviderPosix(int key, FilePath* result) { << "Try running from your chromium/src directory."; return false; } + case base::DIR_USER_DESKTOP: + *result = base::nix::GetXDGUserDirectory("DESKTOP", "Desktop"); + return true; case base::DIR_CACHE: { scoped_ptr<base::Environment> env(base::Environment::Create()); FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", @@ -103,10 +109,9 @@ bool PathProviderPosix(int key, FilePath* result) { *result = cache_dir; return true; } - case base::DIR_HOME: { + case base::DIR_HOME: *result = file_util::GetHomeDir(); return true; - } } return false; } diff --git a/base/base_paths_posix.h b/base/base_paths_posix.h new file mode 100644 index 0000000..811c8cb --- /dev/null +++ b/base/base_paths_posix.h @@ -0,0 +1,29 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_BASE_PATHS_POSIX_H_ +#define BASE_BASE_PATHS_POSIX_H_ + +// This file declares windows-specific path keys for the base module. +// These can be used with the PathService to access various special +// directories and files. + +namespace base { + +enum { + PATH_POSIX_START = 400, + + DIR_CACHE, // Directory where to put cache data. Note this is + // *not* where the browser cache lives, but the + // browser cache can be a subdirectory. + // This is $XDG_CACHE_HOME on Linux and + // ~/Library/Caches on Mac. + DIR_HOME, // $HOME on POSIX-like systems. + + PATH_POSIX_END +}; + +} // namespace base + +#endif // BASE_BASE_PATHS_POSIX_H_ 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; } diff --git a/base/base_paths_win.h b/base/base_paths_win.h index 707a6a6..6cbcb2c 100644 --- a/base/base_paths_win.h +++ b/base/base_paths_win.h @@ -35,6 +35,12 @@ enum { DIR_APP_SHORTCUTS, // Where tiles on the start screen are stored, only // for Windows 8. Maps to "Local\AppData\Microsoft\ // Windows\Application Shortcuts\". + DIR_COMMON_DESKTOP, // Directory for the common desktop (visible + // on all user's Desktop). + DIR_USER_QUICK_LAUNCH, // Directory for the quick launch shortcuts. + DIR_DEFAULT_USER_QUICK_LAUNCH, // Directory for the quick launch shortcuts + // of the Default user. + PATH_WIN_END }; diff --git a/base/path_service.cc b/base/path_service.cc index a3b882c..7a696e9 100644 --- a/base/path_service.cc +++ b/base/path_service.cc @@ -26,6 +26,8 @@ namespace base { #elif defined(OS_ANDROID) bool PathProviderAndroid(int key, FilePath* result); #elif defined(OS_POSIX) + // PathProviderPosix is the default path provider on POSIX OSes other than + // Mac and Android. bool PathProviderPosix(int key, FilePath* result); #endif } @@ -85,8 +87,8 @@ Provider base_provider_android = { base::PathProviderAndroid, &base_provider, #ifndef NDEBUG - 0, - 0, + base::PATH_ANDROID_START, + base::PATH_ANDROID_END, #endif true }; @@ -97,8 +99,8 @@ Provider base_provider_posix = { base::PathProviderPosix, &base_provider, #ifndef NDEBUG - 0, - 0, + base::PATH_POSIX_START, + base::PATH_POSIX_END, #endif true }; diff --git a/base/path_service_unittest.cc b/base/path_service_unittest.cc index 81d1fef..158b745 100644 --- a/base/path_service_unittest.cc +++ b/base/path_service_unittest.cc @@ -8,13 +8,19 @@ #include "base/file_util.h" #include "base/file_path.h" #include "base/scoped_temp_dir.h" -#if defined(OS_WIN) -#include "base/win/windows_version.h" -#endif +#include "base/string_util.h" +#include "build/build_config.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest-spi.h" #include "testing/platform_test.h" +#if defined(OS_WIN) +#include <userenv.h> +#include "base/win/windows_version.h" +// userenv.dll is required for GetDefaultUserProfileDirectory(). +#pragma comment(lib, "userenv.lib") +#endif + namespace { // Returns true if PathService::Get returns true and sets the path parameter @@ -26,9 +32,28 @@ bool ReturnsValidPath(int dir_type) { // If chromium has never been started on this account, the cache path may not // exist. if (dir_type == base::DIR_CACHE) - return result && !path.value().empty(); + return result && !path.empty(); +#endif +#if defined(OS_LINUX) + // On the linux try-bots: a path is returned (e.g. /home/chrome-bot/Desktop), + // but it doesn't exist. + if (dir_type == base::DIR_USER_DESKTOP) + return result && !path.empty(); #endif - return result && !path.value().empty() && file_util::PathExists(path); +#if defined(OS_WIN) + // On Windows XP, the Quick Launch folder for the "Default User" doesn't exist + // by default. At least confirm that the path returned begins with the + // Default User's profile path. + if (dir_type == base::DIR_DEFAULT_USER_QUICK_LAUNCH && + base::win::GetVersion() < base::win::VERSION_VISTA) { + wchar_t default_profile_path[MAX_PATH]; + DWORD size = arraysize(default_profile_path); + return (result && + ::GetDefaultUserProfileDirectory(default_profile_path, &size) && + StartsWith(path.value(), default_profile_path, false)); + } +#endif + return result && !path.empty() && file_util::PathExists(path); } #if defined(OS_WIN) @@ -53,10 +78,10 @@ typedef PlatformTest PathServiceTest; // later changes to Get broke the semantics of the function and yielded the // correct value while returning false.) TEST_F(PathServiceTest, Get) { - for (int key = base::DIR_CURRENT; key < base::PATH_END; ++key) { + for (int key = base::PATH_START + 1; key < base::PATH_END; ++key) { #if defined(OS_ANDROID) - if (key == base::FILE_MODULE) - continue; // Android doesn't implement FILE_MODULE; + if (key == base::FILE_MODULE || key == base::DIR_USER_DESKTOP) + continue; // Android doesn't implement FILE_MODULE and DIR_USER_DESKTOP; #endif EXPECT_PRED1(ReturnsValidPath, key); } @@ -83,7 +108,17 @@ TEST_F(PathServiceTest, Get) { } #elif defined(OS_MACOSX) for (int key = base::PATH_MAC_START + 1; key < base::PATH_MAC_END; ++key) { - EXPECT_PRED1(ReturnsValidPath, key); + EXPECT_PRED1(ReturnsValidPath, key); + } +#elif defined(OS_ANDROID) + for (int key = base::PATH_ANDROID_START + 1; key < base::PATH_ANDROID_END; + ++key) { + EXPECT_PRED1(ReturnsValidPath, key); + } +#elif defined(OS_POSIX) + for (int key = base::PATH_POSIX_START + 1; key < base::PATH_POSIX_END; + ++key) { + EXPECT_PRED1(ReturnsValidPath, key); } #endif } diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index 3dd5840..d18d876 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -138,7 +138,7 @@ bool DownloadPathIsDangerous(const FilePath& download_path) { return false; #else FilePath desktop_dir; - if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_dir)) { + if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop_dir)) { NOTREACHED(); return false; } diff --git a/chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc b/chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc index 6625964..81be184 100644 --- a/chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc +++ b/chrome/browser/profiles/profile_shortcut_manager_unittest_win.cc @@ -61,7 +61,12 @@ class ProfileShortcutManagerTest : public testing::Test { file_thread_(BrowserThread::FILE, &message_loop_) { } - virtual void SetUp() { + virtual void SetUp() OVERRIDE { + // Mock the user's Desktop into a temp directory. + ASSERT_TRUE(fake_user_desktop_.CreateUniqueTempDir()); + ASSERT_TRUE(PathService::Override(base::DIR_USER_DESKTOP, + fake_user_desktop_.path())); + TestingBrowserProcess* browser_process = static_cast<TestingBrowserProcess*>(g_browser_process); profile_manager_.reset(new TestingProfileManager(browser_process)); @@ -80,7 +85,7 @@ class ProfileShortcutManagerTest : public testing::Test { second_profile_name_ = ASCIIToUTF16("My profile 2"); } - virtual void TearDown() { + virtual void TearDown() OVERRIDE { message_loop_.RunAllPending(); int num_profiles = @@ -148,6 +153,7 @@ class ProfileShortcutManagerTest : public testing::Test { content::TestBrowserThread ui_thread_; content::TestBrowserThread file_thread_; scoped_ptr<TestingProfileManager> profile_manager_; + ScopedTempDir fake_user_desktop_; FilePath dest_path_; string16 profile_name_; FilePath second_dest_path_; diff --git a/chrome/browser/shell_integration_linux.cc b/chrome/browser/shell_integration_linux.cc index b4f7942..e478893 100644 --- a/chrome/browser/shell_integration_linux.cc +++ b/chrome/browser/shell_integration_linux.cc @@ -32,7 +32,6 @@ #include "build/build_config.h" #include "chrome/browser/web_applications/web_app.h" #include "chrome/common/chrome_constants.h" -#include "chrome/common/chrome_paths.h" #include "content/public/browser/browser_thread.h" #include "googleurl/src/gurl.h" #include "ui/gfx/codec/png_codec.h" @@ -119,7 +118,7 @@ bool CreateShortcutOnDesktop(const FilePath& shortcut_filename, DCHECK_EQ(shortcut_filename.BaseName().value(), shortcut_filename.value()); FilePath desktop_path; - if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_path)) + if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop_path)) return false; int desktop_fd = open(desktop_path.value().c_str(), O_RDONLY | O_DIRECTORY); @@ -156,7 +155,7 @@ bool CreateShortcutOnDesktop(const FilePath& shortcut_filename, void DeleteShortcutOnDesktop(const FilePath& shortcut_filename) { FilePath desktop_path; - if (PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_path)) + if (PathService::Get(base::DIR_USER_DESKTOP, &desktop_path)) file_util::Delete(desktop_path.Append(shortcut_filename), false); } @@ -484,7 +483,7 @@ FilePath GetWebShortcutFilename(const GURL& url) { file_util::ReplaceIllegalCharactersInPath(&filename, '_'); FilePath desktop_path; - if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_path)) + if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop_path)) return FilePath(); FilePath filepath = desktop_path.Append(filename); diff --git a/chrome/browser/shell_integration_win.cc b/chrome/browser/shell_integration_win.cc index 08b9885..4782a3c 100644 --- a/chrome/browser/shell_integration_win.cc +++ b/chrome/browser/shell_integration_win.cc @@ -25,7 +25,6 @@ #include "base/win/windows_version.h" #include "chrome/browser/web_applications/web_app.h" #include "chrome/common/chrome_constants.h" -#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths_internal.h" #include "chrome/common/chrome_switches.h" #include "chrome/installer/setup/setup_util.h" @@ -364,7 +363,7 @@ void MigrateChromiumShortcutsCallback() { base::DIR_APP_DATA, L"Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar" }, { - chrome::DIR_USER_DESKTOP, + base::DIR_USER_DESKTOP, NULL }, { base::DIR_START_MENU, diff --git a/chrome/browser/ui/views/test/ui_test_utils_win.cc b/chrome/browser/ui/views/test/ui_test_utils_win.cc index 81460a4..cad080b 100644 --- a/chrome/browser/ui/views/test/ui_test_utils_win.cc +++ b/chrome/browser/ui/views/test/ui_test_utils_win.cc @@ -15,7 +15,6 @@ #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/window_snapshot/window_snapshot.h" -#include "chrome/common/chrome_paths.h" #include "ui/base/win/foreground_helper.h" #include "ui/ui_controls/ui_controls.h" #include "ui/views/focus/focus_manager.h" @@ -144,7 +143,7 @@ bool SaveScreenSnapshotToDirectory(const FilePath& directory, bool SaveScreenSnapshotToDesktop(FilePath* screenshot_path) { FilePath desktop; - return PathService::Get(chrome::DIR_USER_DESKTOP, &desktop) && + return PathService::Get(base::DIR_USER_DESKTOP, &desktop) && SaveScreenSnapshotToDirectory(desktop, screenshot_path); } diff --git a/chrome/browser/ui/web_applications/web_app_ui.cc b/chrome/browser/ui/web_applications/web_app_ui.cc index 48ab162..6b764be 100644 --- a/chrome/browser/ui/web_applications/web_app_ui.cc +++ b/chrome/browser/ui/web_applications/web_app_ui.cc @@ -16,7 +16,6 @@ #include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/browser/web_applications/web_app.h" #include "chrome/common/chrome_notification_types.h" -#include "chrome/common/chrome_paths.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_registrar.h" @@ -191,7 +190,7 @@ void UpdateShortcutWorker::CheckExistingShortcuts() { } locations[] = { { shortcut_info_.create_on_desktop, - chrome::DIR_USER_DESKTOP, + base::DIR_USER_DESKTOP, NULL }, { shortcut_info_.create_in_applications_menu, diff --git a/chrome/browser/web_applications/web_app_win.cc b/chrome/browser/web_applications/web_app_win.cc index cfc68e1..d1d5634 100644 --- a/chrome/browser/web_applications/web_app_win.cc +++ b/chrome/browser/web_applications/web_app_win.cc @@ -15,7 +15,6 @@ #include "base/utf_string_conversions.h" #include "base/win/shortcut.h" #include "base/win/windows_version.h" -#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "content/public/browser/browser_thread.h" #include "ui/gfx/icon_util.h" @@ -82,7 +81,7 @@ std::vector<FilePath> GetShortcutPaths( } locations[] = { { shortcut_info.create_on_desktop, - chrome::DIR_USER_DESKTOP, + base::DIR_USER_DESKTOP, NULL }, { shortcut_info.create_in_applications_menu, diff --git a/chrome/common/chrome_paths.cc b/chrome/common/chrome_paths.cc index 62c5b37..dd098ab 100644 --- a/chrome/common/chrome_paths.cc +++ b/chrome/common/chrome_paths.cc @@ -208,10 +208,6 @@ bool PathProvider(int key, FilePath* result) { cur = cur.Append(FILE_PATH_LITERAL("Crash Reports")); create_dir = true; break; - case chrome::DIR_USER_DESKTOP: - if (!GetUserDesktop(&cur)) - return false; - break; case chrome::DIR_RESOURCES: #if defined(OS_MACOSX) cur = base::mac::FrameworkBundlePath(); diff --git a/chrome/common/chrome_paths.h b/chrome/common/chrome_paths.h index ef8e95d..64813a7 100644 --- a/chrome/common/chrome_paths.h +++ b/chrome/common/chrome_paths.h @@ -23,7 +23,6 @@ enum { // (the one that isn't in use). #endif DIR_CRASH_DUMPS, // Directory where crash dumps are written. - DIR_USER_DESKTOP, // Directory that correspond to the desktop. DIR_RESOURCES, // Directory containing separate file resources // used by Chrome at runtime. DIR_INSPECTOR, // Directory where web inspector is located. diff --git a/chrome/common/chrome_paths_android.cc b/chrome/common/chrome_paths_android.cc index d647806..6a7d9ea 100644 --- a/chrome/common/chrome_paths_android.cc +++ b/chrome/common/chrome_paths_android.cc @@ -48,11 +48,6 @@ bool GetUserVideosDirectory(FilePath* result) { return false; } -bool GetUserDesktop(FilePath* result) { - NOTIMPLEMENTED() << "Android doesn't support GetUserDesktop"; - return false; -} - bool ProcessNeedsProfileDir(const std::string& process_type) { return true; } diff --git a/chrome/common/chrome_paths_internal.h b/chrome/common/chrome_paths_internal.h index 40e9742..60fab11 100644 --- a/chrome/common/chrome_paths_internal.h +++ b/chrome/common/chrome_paths_internal.h @@ -65,9 +65,6 @@ bool GetUserPicturesDirectory(FilePath* result); // Gets the path to the user's videos directory. bool GetUserVideosDirectory(FilePath* result); -// The path to the user's desktop. -bool GetUserDesktop(FilePath* result); - #if defined(OS_MACOSX) // The "versioned directory" is a directory in the browser .app bundle. It // contains the bulk of the application, except for the things that the system diff --git a/chrome/common/chrome_paths_linux.cc b/chrome/common/chrome_paths_linux.cc index 321032f..babb501 100644 --- a/chrome/common/chrome_paths_linux.cc +++ b/chrome/common/chrome_paths_linux.cc @@ -37,7 +37,8 @@ bool GetUserMediaDirectory(const std::string& xdg_name, FilePath home = file_util::GetHomeDir(); if (*result != home) { FilePath desktop; - GetUserDesktop(&desktop); + if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop)) + return false; if (*result != desktop) { return true; } @@ -142,11 +143,6 @@ bool GetUserVideosDirectory(FilePath* result) { return GetUserMediaDirectory("VIDEOS", kVideosDir, result); } -bool GetUserDesktop(FilePath* result) { - *result = GetXDGUserDirectory("DESKTOP", "Desktop"); - return true; -} - bool ProcessNeedsProfileDir(const std::string& process_type) { // For now we have no reason to forbid this on Linux as we don't // have the roaming profile troubles there. Moreover the Linux breakpad needs diff --git a/chrome/common/chrome_paths_mac.mm b/chrome/common/chrome_paths_mac.mm index f933796..5b63f47 100644 --- a/chrome/common/chrome_paths_mac.mm +++ b/chrome/common/chrome_paths_mac.mm @@ -147,10 +147,6 @@ bool GetUserVideosDirectory(FilePath* result) { return base::mac::GetUserDirectory(NSMoviesDirectory, result); } -bool GetUserDesktop(FilePath* result) { - return base::mac::GetUserDirectory(NSDesktopDirectory, result); -} - FilePath GetVersionedDirectory() { if (g_override_versioned_directory) return *g_override_versioned_directory; diff --git a/chrome/common/chrome_paths_win.cc b/chrome/common/chrome_paths_win.cc index f0319a2..bb4036d 100644 --- a/chrome/common/chrome_paths_win.cc +++ b/chrome/common/chrome_paths_win.cc @@ -131,10 +131,6 @@ bool GetUserVideosDirectory(FilePath* result) { return GetUserDirectory(CSIDL_MYVIDEO, result); } -bool GetUserDesktop(FilePath* result) { - return GetUserDirectory(CSIDL_DESKTOPDIRECTORY, result); -} - bool ProcessNeedsProfileDir(const std::string& process_type) { // On windows we don't want subprocesses other than the browser process and // service processes to be able to use the profile directory because if it diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc index f6e696c..3e2d19a 100644 --- a/chrome/installer/util/shell_util.cc +++ b/chrome/installer/util/shell_util.cc @@ -1098,43 +1098,15 @@ bool ShellUtil::GetChromeShortcutName(BrowserDistribution* dist, } 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 = FilePath(desktop); - return true; + int dir_key = system_level ? base::DIR_COMMON_DESKTOP : + base::DIR_USER_DESKTOP; + return PathService::Get(dir_key, path); } bool ShellUtil::GetQuickLaunchPath(bool system_level, FilePath* path) { - if (system_level) { - wchar_t qlaunch[MAX_PATH]; - // We are accessing GetDefaultUserProfileDirectory this way so that we do - // not have to declare dependency to Userenv.lib for chrome.exe - typedef BOOL (WINAPI *PROFILE_FUNC)(LPWSTR, LPDWORD); - HMODULE module = LoadLibrary(L"Userenv.dll"); - PROFILE_FUNC p = reinterpret_cast<PROFILE_FUNC>(GetProcAddress(module, - "GetDefaultUserProfileDirectoryW")); - DWORD size = _countof(qlaunch); - if ((p == NULL) || ((p)(qlaunch, &size) != TRUE)) - return false; - *path = FilePath(qlaunch); - if (base::win::GetVersion() >= base::win::VERSION_VISTA) { - *path = path->AppendASCII("AppData"); - *path = path->AppendASCII("Roaming"); - } else { - *path = path->AppendASCII("Application Data"); - } - } else { - if (!PathService::Get(base::DIR_APP_DATA, path)) { - return false; - } - } - *path = path->AppendASCII("Microsoft"); - *path = path->AppendASCII("Internet Explorer"); - *path = path->AppendASCII("Quick Launch"); - return true; + int dir_key = system_level ? base::DIR_DEFAULT_USER_QUICK_LAUNCH : + base::DIR_USER_QUICK_LAUNCH; + return PathService::Get(dir_key, path); } void ShellUtil::GetRegisteredBrowsers( diff --git a/chrome/installer/util/shell_util_unittest.cc b/chrome/installer/util/shell_util_unittest.cc index 298a9a4..1bbe661 100644 --- a/chrome/installer/util/shell_util_unittest.cc +++ b/chrome/installer/util/shell_util_unittest.cc @@ -2,14 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <shlobj.h> - #include <fstream> #include <vector> #include "base/file_util.h" -#include "base/path_service.h" #include "base/md5.h" +#include "base/path_service.h" #include "base/scoped_temp_dir.h" #include "base/string16.h" #include "base/string_util.h" @@ -24,17 +22,27 @@ namespace { -class ShellUtilTestWithDirAndDist : public testing::Test { +class ShellUtilShortcutTest : public testing::Test { protected: - virtual void SetUp() { - ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); + virtual void SetUp() OVERRIDE { dist_ = BrowserDistribution::GetDistribution(); ASSERT_TRUE(dist_ != NULL); + + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); + ASSERT_TRUE(fake_user_desktop_.CreateUniqueTempDir()); + ASSERT_TRUE(fake_common_desktop_.CreateUniqueTempDir()); + ASSERT_TRUE(PathService::Override(base::DIR_USER_DESKTOP, + fake_user_desktop_.path())); + ASSERT_TRUE(PathService::Override(base::DIR_COMMON_DESKTOP, + fake_common_desktop_.path())); } BrowserDistribution* dist_; ScopedTempDir temp_dir_; + + ScopedTempDir fake_user_desktop_; + ScopedTempDir fake_common_desktop_; }; // Returns the status of a call to base::win::VerifyShorcut for the properties @@ -58,7 +66,7 @@ base::win::VerifyShortcutStatus VerifyChromeShortcut( } // Test that we can open archives successfully. -TEST_F(ShellUtilTestWithDirAndDist, UpdateChromeShortcutTest) { +TEST_F(ShellUtilShortcutTest, UpdateChromeShortcut) { // Create an executable in test path by copying ourself to it. wchar_t exe_full_path_str[MAX_PATH]; EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); @@ -122,13 +130,7 @@ TEST_F(ShellUtilTestWithDirAndDist, UpdateChromeShortcutTest) { VerifyChromeShortcut(exe_path, shortcut_path, description2, 1)); } -TEST_F(ShellUtilTestWithDirAndDist, CreateChromeDesktopShortcutTest) { - // Run this test on Vista+ only if we are running elevated. - if (base::win::GetVersion() > base::win::VERSION_XP && !IsUserAnAdmin()) { - LOG(ERROR) << "Must be admin to run this test on Vista+"; - return; - } - +TEST_F(ShellUtilShortcutTest, CreateChromeDesktopShortcut) { // Create an executable in test path by copying ourself to it. wchar_t exe_full_path_str[MAX_PATH]; EXPECT_FALSE(::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH) == 0); @@ -306,16 +308,18 @@ TEST_F(ShellUtilTestWithDirAndDist, CreateChromeDesktopShortcutTest) { profile_names)); } -TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdBasic) { +TEST(ShellUtilTest, BuildAppModelIdBasic) { std::vector<string16> components; - const string16 base_app_id(dist_->GetBaseAppId()); + BrowserDistribution* dist = BrowserDistribution::GetDistribution(); + const string16 base_app_id(dist->GetBaseAppId()); components.push_back(base_app_id); ASSERT_EQ(base_app_id, ShellUtil::BuildAppModelId(components)); } -TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdManySmall) { +TEST(ShellUtilTest, BuildAppModelIdManySmall) { std::vector<string16> components; - const string16 suffixed_app_id(dist_->GetBaseAppId().append(L".gab")); + BrowserDistribution* dist = BrowserDistribution::GetDistribution(); + const string16 suffixed_app_id(dist->GetBaseAppId().append(L".gab")); components.push_back(suffixed_app_id); components.push_back(L"Default"); components.push_back(L"Test"); @@ -323,7 +327,7 @@ TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdManySmall) { ShellUtil::BuildAppModelId(components)); } -TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdLongUsernameNormalProfile) { +TEST(ShellUtilTest, BuildAppModelIdLongUsernameNormalProfile) { std::vector<string16> components; const string16 long_appname( L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" @@ -334,7 +338,7 @@ TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdLongUsernameNormalProfile) { ShellUtil::BuildAppModelId(components)); } -TEST_F(ShellUtilTestWithDirAndDist, BuildAppModelIdLongEverything) { +TEST(ShellUtilTest, BuildAppModelIdLongEverything) { std::vector<string16> components; const string16 long_appname( L"Chrome.a_user_who_has_a_crazy_long_name_with_some_weird@symbols_in_it_" |