summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornkostylev@chromium.org <nkostylev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-10 09:32:42 +0000
committernkostylev@chromium.org <nkostylev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-10 09:32:42 +0000
commit847522f9fc1e134417e8bc87af9ab20cb3e7f123 (patch)
tree87b309b01ed8ee6a583ed352bcfc1f4499927209
parent3b7afe15e2b96bcc325eeed3dcaf88fe9b2dc6d7 (diff)
downloadchromium_src-847522f9fc1e134417e8bc87af9ab20cb3e7f123.zip
chromium_src-847522f9fc1e134417e8bc87af9ab20cb3e7f123.tar.gz
chromium_src-847522f9fc1e134417e8bc87af9ab20cb3e7f123.tar.bz2
[cros mp] Load profiles from /home/chronos/u-[$hash], add GetUserIdHashFromProfile()
* KioskTest.InstallAndLaunchApp will fail when --multi-profiles switch is passed. Kiosk MP auth flow support is tracked at http://crbug.com/238985 BUG=238623,229411 TBR=pneubeck Review URL: https://chromiumcodereview.appspot.com/14581006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199434 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/app_mode/kiosk_app_launcher.cc2
-rw-r--r--chrome/browser/chromeos/extensions/networking_private_api.cc22
-rw-r--r--chrome/browser/chromeos/extensions/networking_private_apitest.cc3
-rw-r--r--chrome/browser/chromeos/profiles/profile_helper.cc51
-rw-r--r--chrome/browser/chromeos/profiles/profile_helper.h15
-rw-r--r--chrome/browser/chromeos/profiles/profile_helper_browsertest.cc40
-rw-r--r--chrome/browser/profiles/profile_manager.cc28
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chromeos/dbus/cryptohome_client.cc6
9 files changed, 123 insertions, 45 deletions
diff --git a/chrome/browser/chromeos/app_mode/kiosk_app_launcher.cc b/chrome/browser/chromeos/app_mode/kiosk_app_launcher.cc
index d91c714..1b88139 100644
--- a/chrome/browser/chromeos/app_mode/kiosk_app_launcher.cc
+++ b/chrome/browser/chromeos/app_mode/kiosk_app_launcher.cc
@@ -114,7 +114,7 @@ class KioskAppLauncher::ProfileLoader : public LoginUtils::Delegate {
}
void Start() {
- // TODO(nkostylev): Pass real username_hash here.
+ // TODO(nkostylev): Pass real username_hash here. crbug.com/238985
LoginUtils::Get()->PrepareProfile(
UserContext(GetAppUserNameFromAppId(launcher_->app_id_),
std::string(), // password
diff --git a/chrome/browser/chromeos/extensions/networking_private_api.cc b/chrome/browser/chromeos/extensions/networking_private_api.cc
index 850fbdd..aa946cf 100644
--- a/chrome/browser/chromeos/extensions/networking_private_api.cc
+++ b/chrome/browser/chromeos/extensions/networking_private_api.cc
@@ -7,8 +7,12 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
+#include "base/command_line.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/browser_process_platform_part_chromeos.h"
+#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/extensions/extension_function_registry.h"
-#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/networking_private.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/shill_manager_client.h"
@@ -101,14 +105,18 @@ bool NetworkingPrivateGetManagedPropertiesFunction::RunImpl() {
api::GetManagedProperties::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
- // The profile of the requesting browser.
- Profile* requesting_profile = profile();
- // TODO(pneubeck): Use ProfileHelper to obtain the userhash, once it provides
- // that functionality. crbug/238623.
- std::string userhash = requesting_profile->GetPath().BaseName().value();
+ // User ID hash presence is only enforced when multi-profiles are turned on.
+ std::string user_id_hash;
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles)) {
+ user_id_hash = g_browser_process->platform_part()->
+ profile_helper()->GetUserIdHashFromProfile(profile());
+ } else {
+ user_id_hash = g_browser_process->platform_part()->
+ profile_helper()->active_user_id_hash();
+ }
ManagedNetworkConfigurationHandler::Get()->GetManagedProperties(
- userhash,
+ user_id_hash,
params->network_guid, // service path
base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Success,
this),
diff --git a/chrome/browser/chromeos/extensions/networking_private_apitest.cc b/chrome/browser/chromeos/extensions/networking_private_apitest.cc
index d5e57b0..71cff2f 100644
--- a/chrome/browser/chromeos/extensions/networking_private_apitest.cc
+++ b/chrome/browser/chromeos/extensions/networking_private_apitest.cc
@@ -34,6 +34,7 @@ namespace chromeos {
namespace {
const char kUser1ProfilePath[] = "/profile/user1/shill";
+const char kUserIdStubHashSuffix[] = "-hash";
void AssignString(std::string* out,
DBusMethodCallStatus call_status,
@@ -58,7 +59,7 @@ class ExtensionNetworkingPrivateApiTest : public ExtensionApiTest {
std::string login_user =
command_line->GetSwitchValueNative(switches::kLoginUser);
// Do the same as CryptohomeClientStubImpl::GetSanitizedUsername
- std::string sanitized_user = login_user + "-profile";
+ std::string sanitized_user = login_user + kUserIdStubHashSuffix;
command_line->AppendSwitchASCII(switches::kLoginProfile, sanitized_user);
}
diff --git a/chrome/browser/chromeos/profiles/profile_helper.cc b/chrome/browser/chromeos/profiles/profile_helper.cc
index 98abafb..04abd6a 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
diff --git a/chrome/browser/chromeos/profiles/profile_helper.h b/chrome/browser/chromeos/profiles/profile_helper.h
index aa0a8d6..19f6b85 100644
--- a/chrome/browser/chromeos/profiles/profile_helper.h
+++ b/chrome/browser/chromeos/profiles/profile_helper.h
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/callback_forward.h"
+#include "base/files/file_path.h"
#include "chrome/browser/browsing_data/browsing_data_remover.h"
#include "chrome/browser/chromeos/login/user_manager.h"
@@ -20,6 +21,11 @@ namespace chromeos {
class ProfileHelper : public BrowsingDataRemover::Observer,
public UserManager::UserSessionStateObserver {
public:
+ // Chrome OS profile directories have custom prefix.
+ // Profile path format: [user_data_dir]/u-[$hash]
+ // Ex.: /home/chronos/u-0123456789
+ static const char kProfileDirPrefix[];
+
ProfileHelper();
virtual ~ProfileHelper();
@@ -29,6 +35,10 @@ class ProfileHelper : public BrowsingDataRemover::Observer,
// Returns OffTheRecord profile for use during signing phase.
static Profile* GetSigninProfile();
+ // Returns user_id hash for |profile| instance or empty string if hash
+ // could not be extracted from |profile|.
+ static std::string GetUserIdHashFromProfile(Profile* profile);
+
// Returns true if |profile| is the signin Profile. This can be used during
// construction of the signin Profile to determine if that Profile is the
// signin Profile.
@@ -38,6 +48,9 @@ class ProfileHelper : public BrowsingDataRemover::Observer,
// TODO(dzhioev): Investigate whether or not this method is needed.
static void ProfileStartup(Profile* profile, bool process_startup);
+ // Returns active user profile dir in a format [u-$hash].
+ base::FilePath GetActiveUserProfileDir();
+
// Should called once after UserManager instance has been created.
void Initialize();
@@ -50,6 +63,8 @@ class ProfileHelper : public BrowsingDataRemover::Observer,
void ClearSigninProfile(const base::Closure& on_clear_callback);
private:
+ friend class ProfileHelperTest;
+
// UserManager::UserSessionStateObserver implementation:
virtual void ActiveUserHashChanged(const std::string& hash) OVERRIDE;
diff --git a/chrome/browser/chromeos/profiles/profile_helper_browsertest.cc b/chrome/browser/chromeos/profiles/profile_helper_browsertest.cc
new file mode 100644
index 0000000..dd36974
--- /dev/null
+++ b/chrome/browser/chromeos/profiles/profile_helper_browsertest.cc
@@ -0,0 +1,40 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "base/files/file_path.h"
+#include "chrome/browser/chromeos/profiles/profile_helper.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromeos {
+
+namespace {
+static const char kActiveUserHash[] = "01234567890";
+} // namespace
+
+class ProfileHelperTest : public InProcessBrowserTest {
+ public:
+ ProfileHelperTest() {
+ }
+
+ protected:
+ void ActiveUserChanged(ProfileHelper* profile_helper,
+ const std::string& hash) {
+ profile_helper->ActiveUserHashChanged(hash);
+ }
+};
+
+IN_PROC_BROWSER_TEST_F(ProfileHelperTest, ActiveUserProfileDir) {
+ ProfileHelper profile_helper;
+ ActiveUserChanged(&profile_helper, kActiveUserHash);
+ base::FilePath profile_dir = profile_helper.GetActiveUserProfileDir();
+ std::string expected_dir;
+ expected_dir.append(ProfileHelper::kProfileDirPrefix);
+ expected_dir.append(kActiveUserHash);
+ EXPECT_EQ(expected_dir, profile_dir.BaseName().value());
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc
index a1ed001..dd2c611 100644
--- a/chrome/browser/profiles/profile_manager.cc
+++ b/chrome/browser/profiles/profile_manager.cc
@@ -198,14 +198,6 @@ void CheckCryptohomeIsMounted(chromeos::DBusMethodCallStatus call_status,
LOG(ERROR) << "Cryptohome is not mounted.";
}
-// 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;
-}
#endif
} // namespace
@@ -349,7 +341,8 @@ base::FilePath ProfileManager::GetInitialProfileDir() {
profile_helper()->active_user_id_hash();
if (command_line.HasSwitch(switches::kMultiProfiles) &&
!user_id_hash.empty()) {
- profile_dir = base::FilePath(user_id_hash);
+ profile_dir = g_browser_process->platform_part()->
+ profile_helper()->GetActiveUserProfileDir();
}
relative_profile_dir = relative_profile_dir.Append(profile_dir);
return relative_profile_dir;
@@ -416,13 +409,7 @@ Profile* ProfileManager::GetDefaultProfile(
#if defined(OS_CHROMEOS)
base::FilePath default_profile_dir(user_data_dir);
if (logged_in_) {
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles) &&
- base::chromeos::IsRunningOnChromeOS()) {
- // TODO(nkostylev): Change to [user_data_dir]/profile-[hash]
- default_profile_dir = GetChromeOSProfileDir(GetInitialProfileDir());
- } else {
- default_profile_dir = default_profile_dir.Append(GetInitialProfileDir());
- }
+ default_profile_dir = default_profile_dir.Append(GetInitialProfileDir());
} else {
default_profile_dir = GetDefaultProfileDir(user_data_dir);
}
@@ -550,15 +537,6 @@ void ProfileManager::CreateDefaultProfileAsync(const CreateCallback& callback) {
default_profile_dir = default_profile_dir.Append(
profile_manager->GetInitialProfileDir());
-#if defined(OS_CHROMEOS)
- // TODO(nkostylev): Change to [user_data_dir]/profile-[hash]
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles) &&
- base::chromeos::IsRunningOnChromeOS()) {
- default_profile_dir = GetChromeOSProfileDir(
- profile_manager->GetInitialProfileDir());
- }
-#endif
-
// Chrome OS specific note: since we pass string16() here as the icon_url,
// profile cache information will not get updated with the is_managed value
// so we're fine with passing all default values here.
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index ffd4d10..9429383 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1244,6 +1244,7 @@
'browser/chromeos/policy/power_policy_browsertest.cc',
'browser/chromeos/policy/variations_service_policy_browsertest.cc',
'browser/chromeos/power/peripheral_battery_observer_browsertest.cc',
+ 'browser/chromeos/profiles/profile_helper_browsertest.cc',
'browser/chromeos/screensaver/screensaver_controller_browsertest.cc',
'browser/chromeos/system/tray_accessibility_browsertest.cc',
'browser/chromeos/ui/idle_logout_dialog_view_browsertest.cc',
diff --git a/chromeos/dbus/cryptohome_client.cc b/chromeos/dbus/cryptohome_client.cc
index 286533d..dc4486d 100644
--- a/chromeos/dbus/cryptohome_client.cc
+++ b/chromeos/dbus/cryptohome_client.cc
@@ -18,6 +18,10 @@ namespace chromeos {
namespace {
+// This suffix is appended to user_id to get hash in stub implementation:
+// stub_hash = "[user_id]-hash";
+static const char kUserIdStubHashSuffix[] = "-hash";
+
// The CryptohomeClient implementation.
class CryptohomeClientImpl : public CryptohomeClient {
public:
@@ -854,7 +858,7 @@ class CryptohomeClientStubImpl : public CryptohomeClient {
const StringDBusMethodCallback& callback) OVERRIDE {
// Even for stub implementation we have to return different values
// so that multi-profiles would work.
- std::string sanitized_username = username + "-profile";
+ std::string sanitized_username = username + kUserIdStubHashSuffix;
MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, sanitized_username));