Skip to content

Commit

Permalink
Revert 270872 "Move all callers of GetHomeDir() to PathService::..."
Browse files Browse the repository at this point in the history
> 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.
> 
> BUG=331530
> TBR=vitalybuka@chromium.org
> 
> Review URL: https://codereview.chromium.org/200473002

This test has caused two tests to start failing on the chromeos valgrind bots:
http://build.chromium.org/p/chromium.memory.fyi/builders/Chromium%20OS%20%28valgrind%29%286%29/builds/25884
http://build.chromium.org/p/chromium.memory.fyi/builders/Chromium%20OS%20%28valgrind%29%285%29/builds/26990

TBR=nkostylev@chromium.org

Review URL: https://codereview.chromium.org/284333002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270951 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
benwells@chromium.org committed May 16, 2014
1 parent cee6a92 commit e0879c1
Show file tree
Hide file tree
Showing 19 changed files with 27 additions and 103 deletions.
1 change: 0 additions & 1 deletion base/file_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ BASE_EXPORT bool GetTempDir(FilePath* path);
//
// 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
Expand Down
8 changes: 2 additions & 6 deletions base/file_util_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,8 @@ bool GetTempDir(FilePath* path) {
#if !defined(OS_MACOSX) // Mac implementation is in file_util_mac.mm.
FilePath GetHomeDir() {
#if defined(OS_CHROMEOS)
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("/");
}
if (SysInfo::IsRunningOnChromeOS())
return FilePath("/home/chronos/user");
#endif

const char* home_dir = getenv("HOME");
Expand Down
13 changes: 4 additions & 9 deletions base/nix/xdg_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

#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 {
Expand All @@ -30,12 +28,10 @@ FilePath GetXDGDirectory(Environment* env, const char* env_name,
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 {
PathService::Get(base::DIR_HOME, &path);
path = path.Append(fallback_dir);
}
else
path = GetHomeDir().Append(fallback_dir);
return path.StripTrailingSeparators();
}

Expand All @@ -46,8 +42,7 @@ FilePath GetXDGUserDirectory(const char* dir_name, const char* fallback_dir) {
path = FilePath(xdg_dir);
free(xdg_dir);
} else {
PathService::Get(base::DIR_HOME, &path);
path = path.Append(fallback_dir);
path = GetHomeDir().Append(fallback_dir);
}
return path.StripTrailingSeparators();
}
Expand Down
11 changes: 0 additions & 11 deletions chrome/app/chrome_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "chrome/app/chrome_main_delegate.h"

#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/cpu.h"
#include "base/files/file_path.h"
Expand Down Expand Up @@ -477,16 +476,6 @@ bool ChromeMainDelegate::BasicStartupComplete(int* exit_code) {
#endif

#if defined(OS_CHROMEOS)
// Initialize primary user homedir (in multi-profile session) as it may be
// passed as a command line switch.
base::FilePath homedir;
if (command_line.HasSwitch(chromeos::switches::kHomedir)) {
homedir = base::FilePath(
command_line.GetSwitchValueASCII(chromeos::switches::kHomedir));
PathService::OverrideAndCreateIfNeeded(
base::DIR_HOME, homedir, true, false);
}

// If we are recovering from a crash on ChromeOS, then we will do some
// recovery using the diagnostics module, and then continue on. We fake up a
// command line to tell it that we want it to recover, and to preserve the
Expand Down
8 changes: 0 additions & 8 deletions chrome/browser/chrome_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1513,14 +1513,6 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
arraysize(kIpcFuzzerSwitches));
#endif

#if defined(OS_CHROMEOS)
// On Chrome OS need to pass primary user homedir (in multi-profiles session).
base::FilePath homedir;
PathService::Get(base::DIR_HOME, &homedir);
command_line->AppendSwitchASCII(chromeos::switches::kHomedir,
homedir.value().c_str());
#endif

if (process_type == switches::kRendererProcess) {
#if defined(OS_CHROMEOS)
const std::string& login_profile =
Expand Down
6 changes: 2 additions & 4 deletions chrome/browser/chromeos/login/login_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <set>
#include <vector>

#include "base/base_paths.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
Expand Down Expand Up @@ -66,6 +65,7 @@
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/app_list/start_page_service.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/logging_chrome.h"
#include "chrome/common/pref_names.h"
Expand Down Expand Up @@ -98,9 +98,7 @@ const base::FilePath::CharType kRLZDisabledFlagName[] =
FILE_PATH_LITERAL(".rlz_disabled");

base::FilePath GetRlzDisabledFlagPath() {
base::FilePath homedir;
PathService::Get(base::DIR_HOME, &homedir);
return homedir.Append(kRLZDisabledFlagName);
return base::GetHomeDir().Append(kRLZDisabledFlagName);
}
#endif

Expand Down
7 changes: 2 additions & 5 deletions chrome/browser/diagnostics/sqlite_diagnostics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "chrome/browser/diagnostics/sqlite_diagnostics.h"

#include "base/base_paths.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
Expand Down Expand Up @@ -241,16 +240,14 @@ DiagnosticsTest* MakeSqliteHistoryDbTest() {

#if defined(OS_CHROMEOS)
DiagnosticsTest* MakeSqliteNssCertDbTest() {
base::FilePath home_dir;
PathService::Get(base::DIR_HOME, &home_dir);
base::FilePath home_dir = base::GetHomeDir();
return new SqliteIntegrityTest(SqliteIntegrityTest::REMOVE_IF_CORRUPT,
DIAGNOSTICS_SQLITE_INTEGRITY_NSS_CERT_TEST,
home_dir.Append(chromeos::kNssCertDbPath));
}

DiagnosticsTest* MakeSqliteNssKeyDbTest() {
base::FilePath home_dir;
PathService::Get(base::DIR_HOME, &home_dir);
base::FilePath home_dir = base::GetHomeDir();
return new SqliteIntegrityTest(SqliteIntegrityTest::REMOVE_IF_CORRUPT,
DIAGNOSTICS_SQLITE_INTEGRITY_NSS_KEY_TEST,
home_dir.Append(chromeos::kNssKeyDbPath));
Expand Down
8 changes: 2 additions & 6 deletions chrome/common/chrome_paths_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

#include "chrome/common/chrome_paths_internal.h"

#include "base/base_paths.h"
#include "base/environment.h"
#include "base/file_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/nix/xdg_util.h"
#include "base/path_service.h"
#include "chrome/common/chrome_paths.h"

namespace chrome {

Expand All @@ -36,8 +34,7 @@ bool GetUserMediaDirectory(const std::string& xdg_name,
#else
*result = GetXDGUserDirectory(xdg_name.c_str(), fallback_name.c_str());

base::FilePath home;
PathService::Get(base::DIR_HOME, &home);
base::FilePath home = base::GetHomeDir();
if (*result != home) {
base::FilePath desktop;
if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop))
Expand Down Expand Up @@ -106,8 +103,7 @@ bool GetUserDocumentsDirectory(base::FilePath* result) {
}

bool GetUserDownloadsDirectorySafe(base::FilePath* result) {
base::FilePath home;
PathService::Get(base::DIR_HOME, &home);
base::FilePath home = base::GetHomeDir();
*result = home.Append(kDownloadsDir);
return true;
}
Expand Down
4 changes: 1 addition & 3 deletions chrome/common/chrome_paths_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <stdlib.h>

#include "base/base_paths.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
Expand All @@ -30,8 +29,7 @@ TEST(ChromePaths, UserCacheDir) {
base::FilePath expected_cache_dir;
ASSERT_TRUE(PathService::Get(base::DIR_CACHE, &expected_cache_dir));
#elif(OS_POSIX)
base::FilePath homedir;
PathService::Get(base::DIR_HOME, &homedir);
base::FilePath homedir = base::GetHomeDir();
// Note: we assume XDG_CACHE_HOME/XDG_CONFIG_HOME are at their
// default settings.
test_profile_dir = homedir.Append(".config/foobar");
Expand Down
6 changes: 1 addition & 5 deletions chrome/common/importer/firefox_importer_utils_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@

#include "chrome/common/importer/firefox_importer_utils.h"

#include "base/base_paths.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/path_service.h"

base::FilePath GetProfilesINI() {
base::FilePath ini_file;
// The default location of the profile folder containing user data is
// under user HOME directory in .mozilla/firefox folder on Linux.
base::FilePath home;
PathService::Get(base::DIR_HOME, &home);
base::FilePath home = base::GetHomeDir();
if (!home.empty()) {
ini_file = home.Append(".mozilla/firefox/profiles.ini");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,9 @@ chrome.test.runTests([
chrome.test.callbackPass(function(directoryEntry) {
var reader = directoryEntry.createReader();
reader.readEntries(chrome.test.callback(function(entries) {
// On POSIX systems DIR_HOME is overridden for this test and
// [.config] directory may be created there, ignore it
// See https://codereview.chromium.org/200473002/
var testEntry;
entries.forEach(function(entry) {
if (entry.name != '.config') {
chrome.test.assertEq(entry.name, 'open_existing.txt');
testEntry = entry;
}
});
checkEntry(testEntry, 'open_existing.txt', false, false);
chrome.test.assertEq(entries.length, 1);
var entry = entries[0];
checkEntry(entry, 'open_existing.txt', false, false);
}));
}));
},
Expand Down
3 changes: 0 additions & 3 deletions chromeos/chromeos_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ const char kHasChromeOSKeyboard[] = "has-chromeos-keyboard";
// If true, the Chromebook has a keyboard with a diamond key.
const char kHasChromeOSDiamondKey[] = "has-chromeos-diamond-key";

// Defines user homedir. This defaults to primary user homedir.
const char kHomedir[] = "homedir";

// If true, profile selection in UserManager will always return active user's
// profile.
// TODO(nkostlyev): http://crbug.com/364604 - Get rid of this switch after we
Expand Down
1 change: 0 additions & 1 deletion chromeos/chromeos_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ CHROMEOS_EXPORT extern const char kForceLoginManagerInTests[];
CHROMEOS_EXPORT extern const char kGuestSession[];
CHROMEOS_EXPORT extern const char kHasChromeOSDiamondKey[];
CHROMEOS_EXPORT extern const char kHasChromeOSKeyboard[];
CHROMEOS_EXPORT extern const char kHomedir[];
CHROMEOS_EXPORT extern const char kIgnoreUserProfileMappingForTests[];
CHROMEOS_EXPORT extern const char kKioskModeScreensaverPath[];
CHROMEOS_EXPORT extern const char kLoginManager[];
Expand Down
7 changes: 1 addition & 6 deletions content/ppapi_plugin/ppapi_plugin_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/debug/debugger.h"
#include "base/files/file_path.h"
#include "base/i18n/rtl.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/threading/platform_thread.h"
#include "build/build_config.h"
#include "content/child/child_process.h"
Expand Down Expand Up @@ -104,9 +101,7 @@ int PpapiPluginMain(const MainFunctionParams& parameters) {
#if defined(OS_CHROMEOS)
// Specifies $HOME explicitly because some plugins rely on $HOME but
// no other part of Chrome OS uses that. See crbug.com/335290.
base::FilePath homedir;
PathService::Get(base::DIR_HOME, &homedir);
setenv("HOME", homedir.value().c_str(), 1);
setenv("HOME", base::GetHomeDir().value().c_str(), 1);
#endif

base::MessageLoop main_message_loop;
Expand Down
5 changes: 1 addition & 4 deletions crypto/nss_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <map>
#include <vector>

#include "base/base_paths.h"
#include "base/bind.h"
#include "base/cpu.h"
#include "base/debug/alias.h"
Expand All @@ -35,7 +34,6 @@
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/native_library.h"
#include "base/path_service.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_checker.h"
Expand Down Expand Up @@ -82,8 +80,7 @@ std::string GetNSSErrorMessage() {

#if defined(USE_NSS)
base::FilePath GetDefaultConfigDirectory() {
base::FilePath dir;
PathService::Get(base::DIR_HOME, &dir);
base::FilePath dir = base::GetHomeDir();
if (dir.empty()) {
LOG(ERROR) << "Failed to get home directory.";
return dir;
Expand Down
7 changes: 2 additions & 5 deletions printing/backend/cups_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

#include <cups/ppd.h>

#include "base/base_paths.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
Expand Down Expand Up @@ -101,9 +99,8 @@ void MarkLpOptions(const std::string& printer_name, ppd_file_t** ppd) {

std::vector<base::FilePath> file_locations;
file_locations.push_back(base::FilePath(kSystemLpOptionPath));
base::FilePath homedir;
PathService::Get(base::DIR_HOME, &homedir);
file_locations.push_back(base::FilePath(homedir.Append(kUserLpOptionPath)));
file_locations.push_back(base::FilePath(
base::GetHomeDir().Append(kUserLpOptionPath)));

for (std::vector<base::FilePath>::const_iterator it = file_locations.begin();
it != file_locations.end(); ++it) {
Expand Down
4 changes: 2 additions & 2 deletions remoting/host/branding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "remoting/host/branding.h"

#include "base/base_paths.h"
#include "base/file_util.h"
#include "base/path_service.h"

namespace {
Expand Down Expand Up @@ -46,7 +46,7 @@ base::FilePath GetConfigDir() {
#elif defined(OS_MACOSX)
PathService::Get(base::DIR_APP_DATA, &app_data_dir);
#else
PathService::Get(base::DIR_HOME, &app_data_dir);
app_data_dir = base::GetHomeDir();
#endif

return app_data_dir.Append(kConfigDir);
Expand Down
7 changes: 2 additions & 5 deletions remoting/host/setup/daemon_controller_delegate_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <unistd.h>

#include "base/base_paths.h"
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/command_line.h"
Expand All @@ -17,7 +16,6 @@
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/md5.h"
#include "base/path_service.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/process/process_handle.h"
Expand Down Expand Up @@ -57,9 +55,8 @@ std::string GetMd5(const std::string& value) {

base::FilePath GetConfigPath() {
std::string filename = "host#" + GetMd5(net::GetHostName()) + ".json";
base::FilePath homedir;
PathService::Get(base::DIR_HOME, &homedir);
return homedir.Append(".config/chrome-remote-desktop").Append(filename);
return base::GetHomeDir().
Append(".config/chrome-remote-desktop").Append(filename);
}

bool GetScriptPath(base::FilePath* result) {
Expand Down
Loading

0 comments on commit e0879c1

Please sign in to comment.