summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-02 08:45:01 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-02 08:45:01 +0000
commit9e9b6e8ee77229781fa8581b7f46413024404a5f (patch)
tree5b3dfc45e4e65db382138b64e5a63ac3c3b0dad6
parent7aadea0cf98791bbbf163b0d2ef078c7697fea4e (diff)
downloadchromium_src-9e9b6e8ee77229781fa8581b7f46413024404a5f.zip
chromium_src-9e9b6e8ee77229781fa8581b7f46413024404a5f.tar.gz
chromium_src-9e9b6e8ee77229781fa8581b7f46413024404a5f.tar.bz2
Move some XDG code from chrome to base, make DIR_USER_CACHE generic rather than Chromium specific, and clean up a few headers.
BUG=none TEST=none Review URL: http://codereview.chromium.org/449048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33565 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/base.gyp3
-rw-r--r--base/base_paths.h6
-rw-r--r--base/base_paths_posix.cc12
-rw-r--r--base/linux_util.cc40
-rw-r--r--base/linux_util.h19
-rw-r--r--base/test/test_suite.h1
-rw-r--r--base/third_party/xdg_user_dirs/README.chromium (renamed from chrome/third_party/xdg_user_dirs/README.chromium)0
-rw-r--r--base/third_party/xdg_user_dirs/xdg_user_dir_lookup.cc (renamed from chrome/third_party/xdg_user_dirs/xdg_user_dir_lookup.cc)0
-rw-r--r--base/third_party/xdg_user_dirs/xdg_user_dir_lookup.h (renamed from chrome/third_party/xdg_user_dirs/xdg_user_dir_lookup.h)0
-rw-r--r--chrome/browser/process_singleton_win.cc1
-rw-r--r--chrome/browser/profile.cc17
-rwxr-xr-xchrome/chrome.gyp7
-rw-r--r--chrome/common/chrome_paths.cc10
-rw-r--r--chrome/common/chrome_paths.h1
-rw-r--r--chrome/common/chrome_paths_internal.h5
-rw-r--r--chrome/common/chrome_paths_linux.cc90
-rw-r--r--media/audio/win/audio_output_win_unittest.cc1
-rw-r--r--media/base/yuv_convert_unittest.cc2
-rw-r--r--media/filters/file_data_source_unittest.cc1
19 files changed, 118 insertions, 98 deletions
diff --git a/base/base.gyp b/base/base.gyp
index 3373f5a..0a7aaba 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -63,6 +63,8 @@
'third_party/xdg_mime/xdgmimemagic.h',
'third_party/xdg_mime/xdgmimeparent.c',
'third_party/xdg_mime/xdgmimeparent.h',
+ 'third_party/xdg_user_dirs/xdg_user_dir_lookup.cc',
+ 'third_party/xdg_user_dirs/xdg_user_dir_lookup.h',
'atomicops_internals_x86_gcc.cc',
'at_exit.cc',
'at_exit.h',
@@ -434,6 +436,7 @@
{ # else: OS != "linux" && OS != "freebsd"
'sources/': [
['exclude', '/xdg_mime/'],
+ ['exclude', '/xdg_user_dirs/'],
['exclude', '_nss\.cc$'],
],
'sources!': [
diff --git a/base/base_paths.h b/base/base_paths.h
index 8ec19e5..7718fbe 100644
--- a/base/base_paths.h
+++ b/base/base_paths.h
@@ -14,7 +14,6 @@
#elif defined(OS_MACOSX)
#include "base/base_paths_mac.h"
#endif
-#include "base/path_service.h"
namespace base {
@@ -32,6 +31,11 @@ enum {
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_LINUX)
+ DIR_USER_CACHE, // Directory where user cache data resides. The Chromium
+ // browser cache can be a subdirectory of DIR_USER_CACHE.
+ // This is $XDG_CACHE_HOME on Linux.
+#endif
PATH_END
};
diff --git a/base/base_paths_posix.cc b/base/base_paths_posix.cc
index 799c135..bcbc578 100644
--- a/base/base_paths_posix.cc
+++ b/base/base_paths_posix.cc
@@ -2,15 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// This is really Posix minus Mac. Mac code is in base_paths_mac.mm.
+
#include "base/base_paths.h"
#include <unistd.h>
#include "base/file_path.h"
#include "base/file_util.h"
+#include "base/linux_util.h"
#include "base/logging.h"
#include "base/path_service.h"
-#include "base/string_piece.h"
+#include "base/scoped_ptr.h"
#include "base/sys_string_conversions.h"
namespace base {
@@ -56,6 +59,13 @@ bool PathProviderPosix(int key, FilePath* result) {
LOG(ERROR) << "Couldn't find your source root. "
<< "Try running from your chromium/src directory.";
return false;
+ case base::DIR_USER_CACHE:
+ scoped_ptr<base::EnvironmentVariableGetter> env(
+ base::EnvironmentVariableGetter::Create());
+ FilePath cache_dir(base::GetXDGDirectory(env.get(), "XDG_CACHE_HOME",
+ ".cache"));
+ *result = cache_dir;
+ return true;
}
return false;
}
diff --git a/base/linux_util.cc b/base/linux_util.cc
index dce4248d..8ac2e49 100644
--- a/base/linux_util.cc
+++ b/base/linux_util.cc
@@ -6,18 +6,20 @@
#include <dirent.h>
#include <errno.h>
+#include <glib.h>
#include <stdlib.h>
#include <sys/stat.h>
-#include <sys/types.h>
#include <unistd.h>
#include <vector>
#include "base/command_line.h"
#include "base/lock.h"
+#include "base/path_service.h"
#include "base/process_util.h"
#include "base/singleton.h"
#include "base/string_util.h"
+#include "base/third_party/xdg_user_dirs/xdg_user_dir_lookup.h"
namespace {
@@ -179,6 +181,23 @@ std::string linux_distro =
"Unknown";
#endif
+FilePath GetHomeDir(EnvironmentVariableGetter* env) {
+ std::string home_dir;
+ if (env->Getenv("HOME", &home_dir) && !home_dir.empty())
+ return FilePath(home_dir);
+
+ home_dir = g_get_home_dir();
+ if (!home_dir.empty())
+ return FilePath(home_dir);
+
+ FilePath rv;
+ if (PathService::Get(base::DIR_TEMP, &rv))
+ return rv;
+
+ // Last resort.
+ return FilePath("/tmp");
+}
+
std::string GetLinuxDistro() {
#if defined(OS_CHROMEOS)
return linux_distro;
@@ -215,6 +234,25 @@ std::string GetLinuxDistro() {
#endif
}
+FilePath GetXDGDirectory(EnvironmentVariableGetter* env,
+ const char* env_name, const char* fallback_dir) {
+ std::string env_value;
+ if (env->Getenv(env_name, &env_value) && !env_value.empty())
+ return FilePath(env_value);
+ return GetHomeDir(env).Append(fallback_dir);
+}
+
+FilePath GetXDGUserDirectory(EnvironmentVariableGetter* env,
+ const char* dir_name, const char* fallback_dir) {
+ char* xdg_dir = xdg_user_dir_lookup(dir_name);
+ if (xdg_dir) {
+ FilePath rv(xdg_dir);
+ free(xdg_dir);
+ return rv;
+ }
+ return GetHomeDir(env).Append(fallback_dir);
+}
+
// static
EnvironmentVariableGetter* EnvironmentVariableGetter::Create() {
return new EnvironmentVariableGetterImpl();
diff --git a/base/linux_util.h b/base/linux_util.h
index 1da519e..b62f7cc 100644
--- a/base/linux_util.h
+++ b/base/linux_util.h
@@ -10,6 +10,8 @@
#include <string>
+class FilePath;
+
namespace base {
static const char kFindInodeSwitch[] = "--find-inode";
@@ -35,6 +37,23 @@ class EnvironmentVariableGetter {
static EnvironmentVariableGetter* Create();
};
+// Get the home directory.
+FilePath GetHomeDir(EnvironmentVariableGetter* env);
+
+// Utility function for getting XDG directories.
+// |env_name| is the name of an environment variable that we want to use to get
+// a directory path. |fallback_dir| is the directory relative to $HOME that we
+// use if |env_name| cannot be found or is empty. |fallback_dir| may be NULL.
+// Examples of |env_name| are XDG_CONFIG_HOME and XDG_DATA_HOME.
+FilePath GetXDGDirectory(EnvironmentVariableGetter* env,
+ const char* env_name, const char* fallback_dir);
+
+// Wrapper around xdg_user_dir_lookup() from src/base/third_party/xdg-user-dirs
+// This looks up "well known" user directories like the desktop and music
+// folder. Examples of |dir_name| are DESKTOP and MUSIC.
+FilePath GetXDGUserDirectory(EnvironmentVariableGetter* env,
+ const char* dir_name, const char* fallback_dir);
+
enum DesktopEnvironment {
DESKTOP_ENVIRONMENT_OTHER,
DESKTOP_ENVIRONMENT_GNOME,
diff --git a/base/test/test_suite.h b/base/test/test_suite.h
index 2566b1a..7eac0d4 100644
--- a/base/test/test_suite.h
+++ b/base/test/test_suite.h
@@ -15,6 +15,7 @@
#include "base/i18n/icu_util.h"
#include "base/multiprocess_test.h"
#include "base/nss_init.h"
+#include "base/path_service.h"
#include "base/process_util.h"
#include "base/scoped_nsautorelease_pool.h"
#include "base/scoped_ptr.h"
diff --git a/chrome/third_party/xdg_user_dirs/README.chromium b/base/third_party/xdg_user_dirs/README.chromium
index 9dc2103..9dc2103 100644
--- a/chrome/third_party/xdg_user_dirs/README.chromium
+++ b/base/third_party/xdg_user_dirs/README.chromium
diff --git a/chrome/third_party/xdg_user_dirs/xdg_user_dir_lookup.cc b/base/third_party/xdg_user_dirs/xdg_user_dir_lookup.cc
index 343f70c..343f70c 100644
--- a/chrome/third_party/xdg_user_dirs/xdg_user_dir_lookup.cc
+++ b/base/third_party/xdg_user_dirs/xdg_user_dir_lookup.cc
diff --git a/chrome/third_party/xdg_user_dirs/xdg_user_dir_lookup.h b/base/third_party/xdg_user_dirs/xdg_user_dir_lookup.h
index 9e81e1b..9e81e1b 100644
--- a/chrome/third_party/xdg_user_dirs/xdg_user_dir_lookup.h
+++ b/base/third_party/xdg_user_dirs/xdg_user_dir_lookup.h
diff --git a/chrome/browser/process_singleton_win.cc b/chrome/browser/process_singleton_win.cc
index 9997efd..0f2b9af 100644
--- a/chrome/browser/process_singleton_win.cc
+++ b/chrome/browser/process_singleton_win.cc
@@ -8,6 +8,7 @@
#include "app/win_util.h"
#include "base/base_paths.h"
#include "base/command_line.h"
+#include "base/path_service.h"
#include "base/process_util.h"
#include "base/win_util.h"
#include "chrome/browser/browser_init.h"
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index ebe224f..278a297 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -609,9 +609,22 @@ ProfileImpl::ProfileImpl(const FilePath& path)
base_cache_path_ = user_cache_path;
}
}
+#elif defined(OS_POSIX) // Posix minus Mac.
+ // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
+ // for a spec on where cache files go. The net effect for most systems is we
+ // use ~/.cache/chromium/ for Chromium and ~/.cache/google-chrome/ for
+ // official builds.
+ if (!PathService::IsOverridden(chrome::DIR_USER_DATA)) {
+#if defined(GOOGLE_CHROME_BUILD)
+ const char kCacheDir[] = "google-chrome";
#else
- if (!PathService::IsOverridden(chrome::DIR_USER_DATA))
- PathService::Get(chrome::DIR_USER_CACHE, &base_cache_path_);
+ const char kCacheDir[] = "chromium";
+#endif
+ PathService::Get(base::DIR_USER_CACHE, &base_cache_path_);
+ base_cache_path_ = base_cache_path_.Append(kCacheDir);
+ if (!file_util::PathExists(base_cache_path_))
+ file_util::CreateDirectory(base_cache_path_);
+ }
#endif
if (base_cache_path_.empty())
base_cache_path_ = path_;
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 9ddf866..7126672 100755
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -704,7 +704,6 @@
'common/x11_util_internal.h',
'common/zip.cc', # Requires zlib directly.
'common/zip.h',
- 'third_party/xdg_user_dirs/xdg_user_dir_lookup.cc',
],
'direct_dependent_settings': {
'include_dirs': [
@@ -729,11 +728,7 @@
'-lXext',
],
},
- }, { # else: 'OS!="linux"'
- 'sources!': [
- 'third_party/xdg_user_dirs/xdg_user_dir_lookup.cc',
- ],
- }],
+ },],
['OS=="linux" and selinux==1', {
'dependencies': [
'../build/linux/system.gyp:selinux',
diff --git a/chrome/common/chrome_paths.cc b/chrome/common/chrome_paths.cc
index 4382793..9b02bb7 100644
--- a/chrome/common/chrome_paths.cc
+++ b/chrome/common/chrome_paths.cc
@@ -78,16 +78,6 @@ bool PathProvider(int key, FilePath* result) {
}
create_dir = true;
break;
- case chrome::DIR_USER_CACHE:
-#if defined(OS_LINUX)
- if (!GetUserCacheDirectory(&cur))
- return false;
- create_dir = true;
-#else
- // No concept of a separate cache directory on non-Linux systems.
- return false;
-#endif
- break;
case chrome::DIR_USER_DOCUMENTS:
if (!GetUserDocumentsDirectory(&cur))
return false;
diff --git a/chrome/common/chrome_paths.h b/chrome/common/chrome_paths.h
index 1577fc2..4382c62 100644
--- a/chrome/common/chrome_paths.h
+++ b/chrome/common/chrome_paths.h
@@ -18,7 +18,6 @@ enum {
DIR_APP = PATH_START, // directory where dlls and data reside
DIR_LOGS, // directory where logs should be written
DIR_USER_DATA, // directory where user data can be written
- DIR_USER_CACHE, // directory where user cache data resides
DIR_CRASH_DUMPS, // directory where crash dumps are written
DIR_USER_DESKTOP, // directory that correspond to the desktop
DIR_INSPECTOR, // directory where web inspector is located
diff --git a/chrome/common/chrome_paths_internal.h b/chrome/common/chrome_paths_internal.h
index 4dc4e0f..dc726d6 100644
--- a/chrome/common/chrome_paths_internal.h
+++ b/chrome/common/chrome_paths_internal.h
@@ -19,11 +19,6 @@ bool GetDefaultUserDataDirectory(FilePath* result);
// CF and Google Chrome want to share the same binaries.
bool GetChromeFrameUserDataDirectory(FilePath* result);
-#if defined(OS_LINUX)
-// Get the path to the user's cache directory.
-bool GetUserCacheDirectory(FilePath* result);
-#endif
-
// Get the path to the user's documents directory.
bool GetUserDocumentsDirectory(FilePath* result);
diff --git a/chrome/common/chrome_paths_linux.cc b/chrome/common/chrome_paths_linux.cc
index 71cb03f..5a880e1 100644
--- a/chrome/common/chrome_paths_linux.cc
+++ b/chrome/common/chrome_paths_linux.cc
@@ -4,56 +4,8 @@
#include "chrome/common/chrome_paths_internal.h"
-#include <glib.h>
-#include <stdlib.h>
-
-#include "base/file_path.h"
-#include "base/path_service.h"
-#include "chrome/third_party/xdg_user_dirs/xdg_user_dir_lookup.h"
-
-namespace {
-
-FilePath GetHomeDir() {
- const char *home_dir = getenv("HOME");
-
- if (home_dir && home_dir[0])
- return FilePath(home_dir);
-
- home_dir = g_get_home_dir();
- if (home_dir && home_dir[0])
- return FilePath(home_dir);
-
- FilePath rv;
- if (PathService::Get(base::DIR_TEMP, &rv))
- return rv;
-
- /* last resort */
- return FilePath("/tmp/");
-}
-
-// Wrapper around xdg_user_dir_lookup() from
-// src/chrome/third_party/xdg-user-dirs
-FilePath GetXDGUserDirectory(const char* env_name, const char* fallback_dir) {
- char* xdg_dir = xdg_user_dir_lookup(env_name);
- if (xdg_dir) {
- FilePath rv(xdg_dir);
- free(xdg_dir);
- return rv;
- }
- return GetHomeDir().Append(fallback_dir);
-}
-
-// |env_name| is the name of an environment variable that we want to use to get
-// a directory path. |fallback_dir| is the directory relative to $HOME that we
-// use if |env_name| cannot be found or is empty. |fallback_dir| may be NULL.
-FilePath GetXDGDirectory(const char* env_name, const char* fallback_dir) {
- const char* env_value = getenv(env_name);
- if (env_value && env_value[0])
- return FilePath(env_value);
- return GetHomeDir().Append(fallback_dir);
-}
-
-} // namespace
+#include "base/linux_util.h"
+#include "base/scoped_ptr.h"
namespace chrome {
@@ -63,7 +15,10 @@ namespace chrome {
// ~/.config/google-chrome/ for official builds.
// (This also helps us sidestep issues with other apps grabbing ~/.chromium .)
bool GetDefaultUserDataDirectory(FilePath* result) {
- FilePath config_dir(GetXDGDirectory("XDG_CONFIG_HOME", ".config"));
+ scoped_ptr<base::EnvironmentVariableGetter> env(
+ base::EnvironmentVariableGetter::Create());
+ FilePath config_dir(
+ base::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config"));
#if defined(GOOGLE_CHROME_BUILD)
*result = config_dir.Append("google-chrome");
#else
@@ -73,7 +28,10 @@ bool GetDefaultUserDataDirectory(FilePath* result) {
}
bool GetChromeFrameUserDataDirectory(FilePath* result) {
- FilePath config_dir(GetXDGDirectory("XDG_CONFIG_HOME", ".config"));
+ scoped_ptr<base::EnvironmentVariableGetter> env(
+ base::EnvironmentVariableGetter::Create());
+ FilePath config_dir(
+ base::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config"));
#if defined(GOOGLE_CHROME_BUILD)
*result = config_dir.Append("google-chrome-frame");
#else
@@ -82,31 +40,21 @@ bool GetChromeFrameUserDataDirectory(FilePath* result) {
return true;
}
-// See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
-// for a spec on where cache files go. The net effect for most
-// systems is we use ~/.cache/chromium/ for Chromium and
-// ~/.cache/google-chrome/ for official builds.
-bool GetUserCacheDirectory(FilePath* result) {
- FilePath cache_dir(GetXDGDirectory("XDG_CACHE_HOME", ".cache"));
-#if defined(GOOGLE_CHROME_BUILD)
- *result = cache_dir.Append("google-chrome");
-#else
- *result = cache_dir.Append("chromium");
-#endif
- return true;
-}
-
bool GetUserDocumentsDirectory(FilePath* result) {
- *result = GetXDGUserDirectory("DOCUMENTS", "Documents");
+ scoped_ptr<base::EnvironmentVariableGetter> env(
+ base::EnvironmentVariableGetter::Create());
+ *result = base::GetXDGUserDirectory(env.get(), "DOCUMENTS", "Documents");
return true;
}
// We respect the user's preferred download location, unless it is
// ~ or their desktop directory, in which case we default to ~/Downloads.
bool GetUserDownloadsDirectory(FilePath* result) {
- *result = GetXDGUserDirectory("DOWNLOAD", "Downloads");
+ scoped_ptr<base::EnvironmentVariableGetter> env(
+ base::EnvironmentVariableGetter::Create());
+ *result = base::GetXDGUserDirectory(env.get(), "DOWNLOAD", "Downloads");
- FilePath home = GetHomeDir();
+ FilePath home = base::GetHomeDir(env.get());
if (*result == home) {
*result = home.Append("Downloads");
return true;
@@ -122,7 +70,9 @@ bool GetUserDownloadsDirectory(FilePath* result) {
}
bool GetUserDesktop(FilePath* result) {
- *result = GetXDGUserDirectory("DESKTOP", "Desktop");
+ scoped_ptr<base::EnvironmentVariableGetter> env(
+ base::EnvironmentVariableGetter::Create());
+ *result = base::GetXDGUserDirectory(env.get(), "DESKTOP", "Desktop");
return true;
}
diff --git a/media/audio/win/audio_output_win_unittest.cc b/media/audio/win/audio_output_win_unittest.cc
index 33d016d..eb1f3c3 100644
--- a/media/audio/win/audio_output_win_unittest.cc
+++ b/media/audio/win/audio_output_win_unittest.cc
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/base_paths.h"
#include "base/file_util.h"
+#include "base/path_service.h"
#include "media/audio/audio_output.h"
#include "media/audio/simple_sources.h"
#include "testing/gmock/include/gmock/gmock.h"
diff --git a/media/base/yuv_convert_unittest.cc b/media/base/yuv_convert_unittest.cc
index 3f2f78f..849decf 100644
--- a/media/base/yuv_convert_unittest.cc
+++ b/media/base/yuv_convert_unittest.cc
@@ -4,6 +4,7 @@
#include "base/base_paths.h"
#include "base/file_util.h"
+#include "base/path_service.h"
#include "media/base/djb2.h"
#include "media/base/yuv_convert.h"
#include "media/base/yuv_row.h"
@@ -254,4 +255,3 @@ TEST(YUVConvertTest, Clamp) {
int expected_test = memcmp(rgb, expected, sizeof(expected));
EXPECT_EQ(0, expected_test);
}
-
diff --git a/media/filters/file_data_source_unittest.cc b/media/filters/file_data_source_unittest.cc
index 193f31a..a5063c8 100644
--- a/media/filters/file_data_source_unittest.cc
+++ b/media/filters/file_data_source_unittest.cc
@@ -6,6 +6,7 @@
#include "base/base_paths.h"
#include "base/file_path.h"
+#include "base/path_service.h"
#include "base/string_util.h"
#include "media/base/mock_filter_host.h"
#include "media/base/mock_filters.h"