Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Unified Diff: base/linux_util.cc

Issue 449048: Move some XDG code from chrome to base. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix linux base_unittest Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/linux_util.h ('k') | base/test/test_suite.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/linux_util.cc
===================================================================
--- base/linux_util.cc (revision 33536)
+++ base/linux_util.cc (working copy)
@@ -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 @@
"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 @@
#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();
« no previous file with comments | « base/linux_util.h ('k') | base/test/test_suite.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698