diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-02 08:45:01 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-02 08:45:01 +0000 |
commit | 9e9b6e8ee77229781fa8581b7f46413024404a5f (patch) | |
tree | 5b3dfc45e4e65db382138b64e5a63ac3c3b0dad6 /base/linux_util.cc | |
parent | 7aadea0cf98791bbbf163b0d2ef078c7697fea4e (diff) | |
download | chromium_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
Diffstat (limited to 'base/linux_util.cc')
-rw-r--r-- | base/linux_util.cc | 40 |
1 files changed, 39 insertions, 1 deletions
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(); |