diff options
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/chrome_paths.cc | 10 | ||||
-rw-r--r-- | chrome/common/chrome_paths.h | 1 | ||||
-rw-r--r-- | chrome/common/chrome_paths_internal.h | 5 | ||||
-rw-r--r-- | chrome/common/chrome_paths_linux.cc | 90 |
4 files changed, 20 insertions, 86 deletions
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; } |