diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-24 22:42:05 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-24 22:42:05 +0000 |
commit | 2b2f8f72f90cf73a432978b7f42f2abaae9112da (patch) | |
tree | 82fb9e5d6fd6dadc75d88bd9f231d583e8be63f4 /chrome/common/chrome_paths_linux.cc | |
parent | d3fc2565089f8471ddc4eaae1b0bd78d40981547 (diff) | |
download | chromium_src-2b2f8f72f90cf73a432978b7f42f2abaae9112da.zip chromium_src-2b2f8f72f90cf73a432978b7f42f2abaae9112da.tar.gz chromium_src-2b2f8f72f90cf73a432978b7f42f2abaae9112da.tar.bz2 |
Final step needed to get be able to download things on linux.
There's still no UI though.
Review URL: http://codereview.chromium.org/27097
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10299 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/chrome_paths_linux.cc')
-rw-r--r-- | chrome/common/chrome_paths_linux.cc | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/chrome/common/chrome_paths_linux.cc b/chrome/common/chrome_paths_linux.cc index cde9949..f416710 100644 --- a/chrome/common/chrome_paths_linux.cc +++ b/chrome/common/chrome_paths_linux.cc @@ -8,6 +8,32 @@ #include "base/file_path.h" #include "base/logging.h" +namespace { + +// |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. +// TODO(thestig): Don't use g_getenv() here because most of the time XDG +// environment variables won't actually be loaded. +FilePath GetStandardDirectory(const char* env_name, const char* fallback_dir) { + FilePath rv; + const char* env_value = g_getenv(env_name); + if (env_value && env_value[0]) { + rv = FilePath(env_value); + } else { + const char* home_dir = g_getenv("HOME"); + if (!home_dir) + home_dir = g_get_home_dir(); + rv = FilePath(home_dir); + if (fallback_dir) + rv = rv.Append(fallback_dir); + } + + return rv; +} + +} // namespace + namespace chrome { // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html @@ -16,17 +42,7 @@ 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; - const char* config_home = g_getenv("XDG_CONFIG_HOME"); - if (config_home && config_home[0]) { - config_dir = FilePath(config_home); - } else { - const char* home_dir = g_getenv("HOME"); - if (!home_dir) - home_dir = g_get_home_dir(); - config_dir = FilePath(home_dir).Append(".config"); - } - + FilePath config_dir = GetStandardDirectory("XDG_CONFIG_HOME", ".config"); #if defined(GOOGLE_CHROME_BUILD) *result = config_dir.Append("google-chrome"); #else @@ -36,17 +52,13 @@ bool GetDefaultUserDataDirectory(FilePath* result) { } bool GetUserDocumentsDirectory(FilePath* result) { - // TODO(port): Get the path (possibly using xdg-user-dirs) - // or decide we don't need it on other platforms. - NOTIMPLEMENTED(); - return false; + *result = GetStandardDirectory("XDG_DOCUMENTS_DIR", "Documents"); + return true; } bool GetUserDesktop(FilePath* result) { - // TODO(port): Get the path (possibly using xdg-user-dirs) - // or decide we don't need it on other platforms. - NOTIMPLEMENTED(); - return false; + *result = GetStandardDirectory("XDG_DESKTOP_DIR", "Desktop"); + return true; } } // namespace chrome |