summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorwjia@chromium.org <wjia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-20 01:59:36 +0000
committerwjia@chromium.org <wjia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-20 01:59:36 +0000
commit1f4ae1659132f11a99e4425efdc517838e21b7ae (patch)
treed5839b4906f43c1dff10e96f6eaa453d4334f0ae /base
parent5e63aededfd66dd694e68619051153439f0016b1 (diff)
downloadchromium_src-1f4ae1659132f11a99e4425efdc517838e21b7ae.zip
chromium_src-1f4ae1659132f11a99e4425efdc517838e21b7ae.tar.gz
chromium_src-1f4ae1659132f11a99e4425efdc517838e21b7ae.tar.bz2
Revert 157667 - Add new PathService paths for Windows' All Users Desktop and Quick Launch folders.
The previous patch failed PathServiceTest.Get. This allows usage of PathService to cache the 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. 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/10910209 TBR=gab@chromium.org Review URL: https://codereview.chromium.org/10958009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157680 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.gypi1
-rw-r--r--base/base_paths.cc2
-rw-r--r--base/base_paths.h16
-rw-r--r--base/base_paths_android.cc32
-rw-r--r--base/base_paths_android.h1
-rw-r--r--base/base_paths_mac.mm17
-rw-r--r--base/base_paths_posix.cc13
-rw-r--r--base/base_paths_posix.h29
-rw-r--r--base/base_paths_win.cc60
-rw-r--r--base/base_paths_win.h6
-rw-r--r--base/path_service.cc10
-rw-r--r--base/path_service_unittest.cc36
12 files changed, 56 insertions, 167 deletions
diff --git a/base/base.gypi b/base/base.gypi
index c4e14ad..0652249 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -63,7 +63,6 @@
'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 80105b6..1beb9c7 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 case in PathService::Get
+ // NOTE: DIR_CURRENT is a special cased in PathService::Get
FilePath cur;
switch (key) {
diff --git a/base/base_paths.h b/base/base_paths.h
index 3251a84..39edd16 100644
--- a/base/base_paths.h
+++ b/base/base_paths.h
@@ -18,10 +18,6 @@
#include "base/base_paths_android.h"
#endif
-#if defined(OS_POSIX)
-#include "base/base_paths_posix.h"
-#endif
-
namespace base {
enum BasePathKey {
@@ -38,7 +34,17 @@ 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.
- DIR_USER_DESKTOP, // The current user's Desktop.
+#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
PATH_END
};
diff --git a/base/base_paths_android.cc b/base/base_paths_android.cc
index ab14ee3..f631c61 100644
--- a/base/base_paths_android.cc
+++ b/base/base_paths_android.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.
-// Defines base::PathProviderAndroid which replaces base::PathProviderPosix for
-// Android in base/path_service.cc.
+#include "base/base_paths.h"
#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"
@@ -30,38 +28,42 @@ 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_USER_DESKTOP:
- // Android doesn't support GetUserDesktop.
- NOTIMPLEMENTED();
- return false;
- case base::DIR_CACHE:
+ }
+ 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 7a9ac4a..8e59b87 100644
--- a/base/base_paths_android.h
+++ b/base/base_paths_android.h
@@ -15,7 +15,6 @@ 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 2227d7d..14d1c20 100644
--- a/base/base_paths_mac.mm
+++ b/base/base_paths_mac.mm
@@ -2,14 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Defines base::PathProviderMac which replaces base::PathProviderPosix for Mac
-// in base/path_service.cc.
+#include "base/base_paths_mac.h"
#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"
@@ -17,7 +15,6 @@
#include "base/mac/foundation_util.h"
#include "base/path_service.h"
#include "base/string_util.h"
-#include "build/build_config.h"
namespace {
@@ -60,6 +57,8 @@ 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);
@@ -70,7 +69,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;
@@ -91,13 +90,11 @@ bool PathProviderMac(int key, FilePath* result) {
}
#endif
return true;
- 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:
+ }
+ 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 834dee3..95e7585 100644
--- a/base/base_paths_posix.cc
+++ b/base/base_paths_posix.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.
-// 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 "base/base_paths.h"
#include <ostream>
#include <string>
-#include "base/base_paths.h"
+#include "build/build_config.h"
#include "base/environment.h"
#include "base/file_path.h"
#include "base/file_util.h"
@@ -18,7 +16,6 @@
#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>
@@ -99,9 +96,6 @@ 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",
@@ -109,9 +103,10 @@ 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
deleted file mode 100644
index 811c8cb..0000000
--- a/base/base_paths_posix.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// 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 58c3ea5..48238a4 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,38 +16,6 @@
// 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) {
@@ -135,9 +103,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)))
@@ -170,28 +138,6 @@ 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 6cbcb2c..707a6a6 100644
--- a/base/base_paths_win.h
+++ b/base/base_paths_win.h
@@ -35,12 +35,6 @@ 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 7a696e9..a3b882c 100644
--- a/base/path_service.cc
+++ b/base/path_service.cc
@@ -26,8 +26,6 @@ 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
}
@@ -87,8 +85,8 @@ Provider base_provider_android = {
base::PathProviderAndroid,
&base_provider,
#ifndef NDEBUG
- base::PATH_ANDROID_START,
- base::PATH_ANDROID_END,
+ 0,
+ 0,
#endif
true
};
@@ -99,8 +97,8 @@ Provider base_provider_posix = {
base::PathProviderPosix,
&base_provider,
#ifndef NDEBUG
- base::PATH_POSIX_START,
- base::PATH_POSIX_END,
+ 0,
+ 0,
#endif
true
};
diff --git a/base/path_service_unittest.cc b/base/path_service_unittest.cc
index 84564d0..81d1fef 100644
--- a/base/path_service_unittest.cc
+++ b/base/path_service_unittest.cc
@@ -8,14 +8,12 @@
#include "base/file_util.h"
#include "base/file_path.h"
#include "base/scoped_temp_dir.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 "base/win/windows_version.h"
#endif
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/gtest/include/gtest/gtest-spi.h"
+#include "testing/platform_test.h"
namespace {
@@ -28,15 +26,9 @@ 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.empty();
+ return result && !path.value().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.empty() && file_util::PathExists(path);
+ return result && !path.value().empty() && file_util::PathExists(path);
}
#if defined(OS_WIN)
@@ -61,10 +53,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::PATH_START + 1; key < base::PATH_END; ++key) {
+ for (int key = base::DIR_CURRENT; key < base::PATH_END; ++key) {
#if defined(OS_ANDROID)
- if (key == base::FILE_MODULE || key == base::DIR_USER_DESKTOP)
- continue; // Android doesn't implement FILE_MODULE and DIR_USER_DESKTOP;
+ if (key == base::FILE_MODULE)
+ continue; // Android doesn't implement FILE_MODULE;
#endif
EXPECT_PRED1(ReturnsValidPath, key);
}
@@ -91,17 +83,7 @@ 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);
- }
-#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);
+ EXPECT_PRED1(ReturnsValidPath, key);
}
#endif
}