From 2b2f8f72f90cf73a432978b7f42f2abaae9112da Mon Sep 17 00:00:00 2001 From: "estade@chromium.org" Date: Tue, 24 Feb 2009 22:42:05 +0000 Subject: 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 --- chrome/common/chrome_paths_linux.cc | 50 +++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 19 deletions(-) (limited to 'chrome/common/chrome_paths_linux.cc') 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 -- cgit v1.1