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

Unified Diff: chrome/browser/chromeos/profiles/profile_helper.cc

Issue 14581006: [cros mp] Load profiles from /home/chronos/u-[$hash], add GetUserIdHashFromProfile() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 7 months 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
Index: chrome/browser/chromeos/profiles/profile_helper.cc
diff --git a/chrome/browser/chromeos/profiles/profile_helper.cc b/chrome/browser/chromeos/profiles/profile_helper.cc
index 98abafbb25bd983bce6c646e22b85a9f2b3cbcc7..04abd6ac6117db1fef5c3b00f47c28bafb41c802 100644
--- a/chrome/browser/chromeos/profiles/profile_helper.cc
+++ b/chrome/browser/chromeos/profiles/profile_helper.cc
@@ -20,13 +20,18 @@ namespace chromeos {
namespace {
-// TODO(nkostylev): Remove this hack when http://crbug.com/224291 is fixed.
-// Now user homedirs are mounted to /home/user which is different from
-// user data dir (/home/chronos).
-base::FilePath GetChromeOSProfileDir(const base::FilePath& path) {
- base::FilePath profile_dir(FILE_PATH_LITERAL("/home/user/"));
- profile_dir = profile_dir.Append(path);
- return profile_dir;
+base::FilePath GetProfilePathByUserIdHash(const std::string user_id_hash) {
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ // Fails for KioskTest.InstallAndLaunchApp test - crbug.com/238985
+ // Will probably fail for Guest session / restart after a crash -
+ // crbug.com/238998
+ // TODO(nkostylev): Remove this check once these bugs are fixed.
+ if (command_line.HasSwitch(switches::kMultiProfiles))
+ DCHECK(!user_id_hash.empty());
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ base::FilePath profile_path = profile_manager->user_data_dir();
+ return profile_path.Append(
+ base::FilePath(ProfileHelper::kProfileDirPrefix + user_id_hash));
}
} // namespace
@@ -34,6 +39,9 @@ base::FilePath GetChromeOSProfileDir(const base::FilePath& path) {
////////////////////////////////////////////////////////////////////////////////
// ProfileHelper, public
+// static
+const char ProfileHelper::kProfileDirPrefix[] = "u-";
+
ProfileHelper::ProfileHelper()
: signin_profile_clear_requested_(false) {
}
@@ -45,8 +53,7 @@ ProfileHelper::~ProfileHelper() {
Profile* ProfileHelper::GetProfileByUserIdHash(
const std::string& user_id_hash) {
ProfileManager* profile_manager = g_browser_process->profile_manager();
- return profile_manager->GetProfile(
- GetChromeOSProfileDir(base::FilePath(user_id_hash)));
+ return profile_manager->GetProfile(GetProfilePathByUserIdHash(user_id_hash));
}
// static
@@ -60,6 +67,23 @@ Profile* ProfileHelper::GetSigninProfile() {
}
// static
+std::string ProfileHelper::GetUserIdHashFromProfile(Profile* profile) {
+ if (!profile)
+ return std::string();
+
+ // Check that profile directory starts with the correct prefix.
+ std::string profile_dir = profile->GetPath().BaseName().value();
+ std::string prefix(ProfileHelper::kProfileDirPrefix);
+ if (profile_dir.find(prefix) != 0) {
+ NOTREACHED();
+ return std::string();
+ }
+
+ return profile_dir.substr(prefix.length(),
+ profile_dir.length() - prefix.length());
+}
+
+// static
bool ProfileHelper::IsSigninProfile(Profile* profile) {
return profile->GetPath().BaseName().value() == chrome::kInitialProfile;
}
@@ -83,6 +107,12 @@ void ProfileHelper::ProfileStartup(Profile* profile, bool process_startup) {
}
}
+base::FilePath ProfileHelper::GetActiveUserProfileDir() {
+ DCHECK(!active_user_id_hash_.empty());
+ return base::FilePath(
+ ProfileHelper::kProfileDirPrefix + active_user_id_hash_);
+}
+
void ProfileHelper::Initialize() {
UserManager::Get()->AddSessionStateObserver(this);
}
@@ -116,7 +146,8 @@ void ProfileHelper::OnBrowsingDataRemoverDone() {
void ProfileHelper::ActiveUserHashChanged(const std::string& hash) {
active_user_id_hash_ = hash;
- LOG(INFO) << "Switching to custom profile_dir: " << active_user_id_hash_;
+ base::FilePath profile_path = GetProfilePathByUserIdHash(hash);
+ LOG(INFO) << "Switching to profile path: " << profile_path.value();
}
} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/profiles/profile_helper.h ('k') | chrome/browser/chromeos/profiles/profile_helper_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698