Move all callers of GetHomeDir() to PathService::Get(base::DIR_HOME).
* Fixes GetHomeDir() for multi-profiles case on Chrome OS.
* Once user signs in on Chrome OS base::DIR_HOME is overridden with primary user homedir.
* Added content switch --homedir to pass that information to ppapi plugins since they
run in a separate process and previous base::DIR_HOME override does not apply there.
This fix doesn't require checking for --multi-profiles switch
since user_id hash is known even without it.
Note:
download_prefs.cc still uses GetHomeDir() in its DownloadPathIsDangerous() check.
// Consider downloads 'dangerous' if they go to the home directory on Linux and
// to the desktop on any platform.
In this context correct behavior is to use "real" base::GetHomeDir() and not "virtual one" base::DIR_HOME.
Since latter is remapped to some test dir in tests, in some subfolders in Chrome OS etc.
BUG=331530
TBR=vitalybuka@chromium.org
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=270872
Review URL: https://codereview.chromium.org/200473002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272898 0039d316-1c4b-4281-b951-d872f2087c98
CrOS-Libchrome-Original-Commit: 6bdc52278501985dd265048a5d14a2ba282d0717
diff --git a/base/file_util.h b/base/file_util.h
index ca7bf62..9c9072f 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -218,6 +218,7 @@
//
// You should not generally call this directly. Instead use DIR_HOME with the
// path service which will use this function but cache the value.
+// Path service may also override DIR_HOME.
BASE_EXPORT FilePath GetHomeDir();
// Creates a temporary file. The full path is placed in |path|, and the
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 9270e8a..e8dec94 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -458,8 +458,12 @@
#if !defined(OS_MACOSX) // Mac implementation is in file_util_mac.mm.
FilePath GetHomeDir() {
#if defined(OS_CHROMEOS)
- if (SysInfo::IsRunningOnChromeOS())
- return FilePath("/home/chronos/user");
+ if (SysInfo::IsRunningOnChromeOS()) {
+ // On Chrome OS chrome::DIR_USER_DATA is overriden with a primary user
+ // homedir once it becomes available.
+ NOTREACHED() << "Called GetHomeDir() without base::DIR_HOME override";
+ return FilePath("/");
+ }
#endif
const char* home_dir = getenv("HOME");
diff --git a/base/nix/xdg_util.cc b/base/nix/xdg_util.cc
index 4c1510f..4086a3d 100644
--- a/base/nix/xdg_util.cc
+++ b/base/nix/xdg_util.cc
@@ -6,9 +6,11 @@
#include <string>
+#include "base/base_paths.h"
#include "base/environment.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
+#include "base/path_service.h"
#include "base/third_party/xdg_user_dirs/xdg_user_dir_lookup.h"
namespace {
@@ -28,10 +30,12 @@
const char* fallback_dir) {
FilePath path;
std::string env_value;
- if (env->GetVar(env_name, &env_value) && !env_value.empty())
+ if (env->GetVar(env_name, &env_value) && !env_value.empty()) {
path = FilePath(env_value);
- else
- path = GetHomeDir().Append(fallback_dir);
+ } else {
+ PathService::Get(base::DIR_HOME, &path);
+ path = path.Append(fallback_dir);
+ }
return path.StripTrailingSeparators();
}
@@ -42,7 +46,8 @@
path = FilePath(xdg_dir);
free(xdg_dir);
} else {
- path = GetHomeDir().Append(fallback_dir);
+ PathService::Get(base::DIR_HOME, &path);
+ path = path.Append(fallback_dir);
}
return path.StripTrailingSeparators();
}