summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralemate <alemate@chromium.org>2016-01-13 06:50:30 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-13 14:51:39 +0000
commit33433e20582da39fb95b5ac0afca7fa62ba31dd2 (patch)
tree6c1f260ac31adc3643fdd0f980e5bc680f3ca650
parent08abfdde18300762a0cb5a87ae95bb35ae0e6f39 (diff)
downloadchromium_src-33433e20582da39fb95b5ac0afca7fa62ba31dd2.zip
chromium_src-33433e20582da39fb95b5ac0afca7fa62ba31dd2.tar.gz
chromium_src-33433e20582da39fb95b5ac0afca7fa62ba31dd2.tar.bz2
Remove dependency of SessionManager and user_manager::UserManager on chromeos.
This Cl removes depencency of the two components on "chromeos". TBR=dzhioev@chromium.org BUG=462823 TEST=manual Review URL: https://codereview.chromium.org/1555223003 Cr-Commit-Position: refs/heads/master@{#369167}
-rw-r--r--chrome/browser/chromeos/login/users/chrome_user_manager.cc6
-rw-r--r--chrome/browser/chromeos/login/users/chrome_user_manager.h3
-rw-r--r--chrome/browser/chromeos/login/users/chrome_user_manager_impl.cc88
-rw-r--r--chrome/browser/chromeos/login/users/chrome_user_manager_impl.h16
-rw-r--r--chrome/browser/chromeos/login/users/chrome_user_manager_util.cc65
-rw-r--r--chrome/browser/chromeos/login/users/chrome_user_manager_util.h32
-rw-r--r--chrome/browser/chromeos/login/users/fake_chrome_user_manager.cc65
-rw-r--r--chrome/browser/chromeos/login/users/fake_chrome_user_manager.h16
-rw-r--r--chrome/browser/chromeos/login/users/mock_user_manager.cc2
-rw-r--r--chrome/browser/chromeos/login/users/mock_user_manager.h17
-rw-r--r--chrome/chrome_browser_chromeos.gypi2
-rw-r--r--components/session_manager.gypi7
-rw-r--r--components/session_manager/DEPS3
-rw-r--r--components/session_manager/core/BUILD.gn3
-rw-r--r--components/session_manager/core/session_manager.cc17
-rw-r--r--components/session_manager/core/session_manager.h4
-rw-r--r--components/user_manager.gypi3
-rw-r--r--components/user_manager/BUILD.gn2
-rw-r--r--components/user_manager/DEPS3
-rw-r--r--components/user_manager/fake_user_manager.cc66
-rw-r--r--components/user_manager/fake_user_manager.h16
-rw-r--r--components/user_manager/known_user.cc12
-rw-r--r--components/user_manager/user.cc11
-rw-r--r--components/user_manager/user.h2
-rw-r--r--components/user_manager/user_manager.cc1
-rw-r--r--components/user_manager/user_manager.h45
-rw-r--r--components/user_manager/user_manager_base.cc144
-rw-r--r--components/user_manager/user_manager_base.h16
28 files changed, 489 insertions, 178 deletions
diff --git a/chrome/browser/chromeos/login/users/chrome_user_manager.cc b/chrome/browser/chromeos/login/users/chrome_user_manager.cc
index d2c6a7d..89ba32f 100644
--- a/chrome/browser/chromeos/login/users/chrome_user_manager.cc
+++ b/chrome/browser/chromeos/login/users/chrome_user_manager.cc
@@ -9,10 +9,8 @@
namespace chromeos {
ChromeUserManager::ChromeUserManager(
- scoped_refptr<base::TaskRunner> task_runner,
- scoped_refptr<base::TaskRunner> blocking_task_runner)
- : UserManagerBase(task_runner, blocking_task_runner) {
-}
+ scoped_refptr<base::TaskRunner> task_runner)
+ : UserManagerBase(task_runner) {}
ChromeUserManager::~ChromeUserManager() {
}
diff --git a/chrome/browser/chromeos/login/users/chrome_user_manager.h b/chrome/browser/chromeos/login/users/chrome_user_manager.h
index 9b53aef..51fdc79 100644
--- a/chrome/browser/chromeos/login/users/chrome_user_manager.h
+++ b/chrome/browser/chromeos/login/users/chrome_user_manager.h
@@ -18,8 +18,7 @@ namespace chromeos {
class ChromeUserManager : public user_manager::UserManagerBase,
public UserManagerInterface {
public:
- ChromeUserManager(scoped_refptr<base::TaskRunner> task_runner,
- scoped_refptr<base::TaskRunner> blocking_task_runner);
+ explicit ChromeUserManager(scoped_refptr<base::TaskRunner> task_runner);
~ChromeUserManager() override;
// Returns current ChromeUserManager or NULL if instance hasn't been
diff --git a/chrome/browser/chromeos/login/users/chrome_user_manager_impl.cc b/chrome/browser/chromeos/login/users/chrome_user_manager_impl.cc
index f383c98..dfd93d1 100644
--- a/chrome/browser/chromeos/login/users/chrome_user_manager_impl.cc
+++ b/chrome/browser/chromeos/login/users/chrome_user_manager_impl.cc
@@ -23,6 +23,8 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/sys_info.h"
+#include "base/task_runner.h"
#include "base/thread_task_runner_handle.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
@@ -33,6 +35,7 @@
#include "chrome/browser/chromeos/login/signin/auth_sync_observer_factory.h"
#include "chrome/browser/chromeos/login/users/affiliation.h"
#include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h"
+#include "chrome/browser/chromeos/login/users/chrome_user_manager_util.h"
#include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h"
#include "chrome/browser/chromeos/login/users/supervised_user_manager_impl.h"
#include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
@@ -53,6 +56,8 @@
#include "chrome/common/pref_names.h"
#include "chrome/grit/theme_resources.h"
#include "chromeos/chromeos_switches.h"
+#include "chromeos/cryptohome/async_method_caller.h"
+#include "chromeos/login/login_state.h"
#include "chromeos/login/user_names.h"
#include "chromeos/settings/cros_settings_names.h"
#include "chromeos/timezone/timezone_resolver.h"
@@ -65,6 +70,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "policy/policy_constants.h"
+#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/wm/core/wm_core_switches.h"
@@ -98,6 +104,23 @@ std::string FullyCanonicalize(const std::string& email) {
return gaia::CanonicalizeEmail(gaia::SanitizeEmail(email));
}
+// Callback that is called after user removal is complete.
+void OnRemoveUserComplete(const AccountId& account_id,
+ bool success,
+ cryptohome::MountError return_code) {
+ // Log the error, but there's not much we can do.
+ if (!success) {
+ LOG(ERROR) << "Removal of cryptohome for " << account_id.Serialize()
+ << " failed, return code: " << return_code;
+ }
+}
+
+// Runs on SequencedWorkerPool thread. Passes resolved locale to UI thread.
+void ResolveLocale(const std::string& raw_locale,
+ std::string* resolved_locale) {
+ ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale));
+}
+
} // namespace
// static
@@ -119,8 +142,7 @@ scoped_ptr<ChromeUserManager> ChromeUserManagerImpl::CreateChromeUserManager() {
}
ChromeUserManagerImpl::ChromeUserManagerImpl()
- : ChromeUserManager(base::ThreadTaskRunnerHandle::Get(),
- BrowserThread::GetBlockingPool()),
+ : ChromeUserManager(base::ThreadTaskRunnerHandle::Get()),
cros_settings_(CrosSettings::Get()),
device_local_account_policy_service_(NULL),
supervised_user_manager_(new SupervisedUserManagerImpl(this)),
@@ -1197,4 +1219,66 @@ void ChromeUserManagerImpl::RemoveReportingUser(const AccountId& account_id) {
base::StringValue(FullyCanonicalize(account_id.GetUserEmail())), NULL);
}
+void ChromeUserManagerImpl::UpdateLoginState(
+ const user_manager::User* active_user,
+ const user_manager::User* primary_user,
+ bool is_current_user_owner) const {
+ chrome_user_manager_util::UpdateLoginState(active_user, primary_user,
+ is_current_user_owner);
+}
+
+bool ChromeUserManagerImpl::GetPlatformKnownUserId(
+ const std::string& user_email,
+ const std::string& gaia_id,
+ AccountId* out_account_id) const {
+ return chrome_user_manager_util::GetPlatformKnownUserId(user_email, gaia_id,
+ out_account_id);
+}
+
+const AccountId& ChromeUserManagerImpl::GetGuestAccountId() const {
+ return login::GuestAccountId();
+}
+
+bool ChromeUserManagerImpl::IsFirstExecAfterBoot() const {
+ return base::CommandLine::ForCurrentProcess()->HasSwitch(
+ chromeos::switches::kFirstExecAfterBoot);
+}
+
+void ChromeUserManagerImpl::AsyncRemoveCryptohome(
+ const AccountId& account_id) const {
+ cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove(
+ account_id.GetUserEmail(), base::Bind(&OnRemoveUserComplete, account_id));
+}
+
+bool ChromeUserManagerImpl::IsGuestAccountId(
+ const AccountId& account_id) const {
+ return account_id == login::GuestAccountId();
+}
+
+bool ChromeUserManagerImpl::IsStubAccountId(const AccountId& account_id) const {
+ return account_id == login::StubAccountId();
+}
+
+bool ChromeUserManagerImpl::IsSupervisedAccountId(
+ const AccountId& account_id) const {
+ return gaia::ExtractDomainName(account_id.GetUserEmail()) ==
+ chromeos::login::kSupervisedUserDomain;
+}
+
+bool ChromeUserManagerImpl::HasBrowserRestarted() const {
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+ return base::SysInfo::IsRunningOnChromeOS() &&
+ command_line->HasSwitch(chromeos::switches::kLoginUser);
+}
+
+void ChromeUserManagerImpl::ScheduleResolveLocale(
+ const std::string& locale,
+ const base::Closure& on_resolved_callback,
+ std::string* out_resolved_locale) const {
+ BrowserThread::GetBlockingPool()->PostTaskAndReply(
+ FROM_HERE,
+ base::Bind(ResolveLocale, locale, base::Unretained(out_resolved_locale)),
+ on_resolved_callback);
+}
+
} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/users/chrome_user_manager_impl.h b/chrome/browser/chromeos/login/users/chrome_user_manager_impl.h
index 69b85b5..c1a0bbc 100644
--- a/chrome/browser/chromeos/login/users/chrome_user_manager_impl.h
+++ b/chrome/browser/chromeos/login/users/chrome_user_manager_impl.h
@@ -93,6 +93,22 @@ class ChromeUserManagerImpl
bool IsUserNonCryptohomeDataEphemeral(
const AccountId& account_id) const override;
bool AreSupervisedUsersAllowed() const override;
+ void UpdateLoginState(const user_manager::User* active_user,
+ const user_manager::User* primary_user,
+ bool is_current_user_owner) const override;
+ bool GetPlatformKnownUserId(const std::string& user_email,
+ const std::string& gaia_id,
+ AccountId* out_account_id) const override;
+ const AccountId& GetGuestAccountId() const override;
+ bool IsFirstExecAfterBoot() const override;
+ void AsyncRemoveCryptohome(const AccountId& account_id) const override;
+ bool IsGuestAccountId(const AccountId& account_id) const override;
+ bool IsStubAccountId(const AccountId& account_id) const override;
+ bool IsSupervisedAccountId(const AccountId& account_id) const override;
+ bool HasBrowserRestarted() const override;
+ void ScheduleResolveLocale(const std::string& locale,
+ const base::Closure& on_resolved_callback,
+ std::string* out_resolved_locale) const override;
// content::NotificationObserver implementation.
void Observe(int type,
diff --git a/chrome/browser/chromeos/login/users/chrome_user_manager_util.cc b/chrome/browser/chromeos/login/users/chrome_user_manager_util.cc
new file mode 100644
index 0000000..b84d9fd
--- /dev/null
+++ b/chrome/browser/chromeos/login/users/chrome_user_manager_util.cc
@@ -0,0 +1,65 @@
+// Copyright 2015 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 "chrome/browser/chromeos/login/users/chrome_user_manager_util.h"
+
+#include "chromeos/login/user_names.h"
+#include "components/user_manager/user.h"
+#include "components/user_manager/user_type.h"
+
+namespace chromeos {
+namespace chrome_user_manager_util {
+
+bool GetPlatformKnownUserId(const std::string& user_email,
+ const std::string& gaia_id,
+ AccountId* out_account_id) {
+ if (user_email == chromeos::login::kStubUser) {
+ *out_account_id = chromeos::login::StubAccountId();
+ return true;
+ }
+
+ if (user_email == chromeos::login::kGuestUserName) {
+ *out_account_id = chromeos::login::GuestAccountId();
+ return true;
+ }
+ return false;
+}
+
+void UpdateLoginState(const user_manager::User* active_user,
+ const user_manager::User* primary_user,
+ bool is_current_user_owner) {
+ if (!chromeos::LoginState::IsInitialized())
+ return; // LoginState may not be initialized in tests.
+
+ chromeos::LoginState::LoggedInState logged_in_state;
+ logged_in_state = active_user ? chromeos::LoginState::LOGGED_IN_ACTIVE
+ : chromeos::LoginState::LOGGED_IN_NONE;
+
+ chromeos::LoginState::LoggedInUserType login_user_type;
+ if (logged_in_state == chromeos::LoginState::LOGGED_IN_NONE)
+ login_user_type = chromeos::LoginState::LOGGED_IN_USER_NONE;
+ else if (is_current_user_owner)
+ login_user_type = chromeos::LoginState::LOGGED_IN_USER_OWNER;
+ else if (active_user->GetType() == user_manager::USER_TYPE_GUEST)
+ login_user_type = chromeos::LoginState::LOGGED_IN_USER_GUEST;
+ else if (active_user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT)
+ login_user_type = chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT;
+ else if (active_user->GetType() == user_manager::USER_TYPE_SUPERVISED)
+ login_user_type = chromeos::LoginState::LOGGED_IN_USER_SUPERVISED;
+ else if (active_user->GetType() == user_manager::USER_TYPE_KIOSK_APP)
+ login_user_type = chromeos::LoginState::LOGGED_IN_USER_KIOSK_APP;
+ else
+ login_user_type = chromeos::LoginState::LOGGED_IN_USER_REGULAR;
+
+ if (primary_user) {
+ chromeos::LoginState::Get()->SetLoggedInStateAndPrimaryUser(
+ logged_in_state, login_user_type, primary_user->username_hash());
+ } else {
+ chromeos::LoginState::Get()->SetLoggedInState(logged_in_state,
+ login_user_type);
+ }
+}
+
+} // namespace chrome_user_manager_util
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/users/chrome_user_manager_util.h b/chrome/browser/chromeos/login/users/chrome_user_manager_util.h
new file mode 100644
index 0000000..6f74b44
--- /dev/null
+++ b/chrome/browser/chromeos/login/users/chrome_user_manager_util.h
@@ -0,0 +1,32 @@
+// Copyright 2015 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.
+
+#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_CHROME_USER_MANAGER_UTIL_H_
+#define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_CHROME_USER_MANAGER_UTIL_H_
+
+#include "chromeos/login/login_state.h"
+
+class AccountId;
+
+namespace user_manager {
+class User;
+}
+
+namespace chromeos {
+namespace chrome_user_manager_util {
+
+// Implements user_manager::UserManager::GetPlatformKnownUserId for ChromeOS
+bool GetPlatformKnownUserId(const std::string& user_email,
+ const std::string& gaia_id,
+ AccountId* out_account_id);
+
+// Implements user_manager::UserManager::UpdateLoginState.
+void UpdateLoginState(const user_manager::User* active_user,
+ const user_manager::User* primary_user,
+ bool is_current_user_owner);
+
+} // namespace chrome_user_manager_util
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_CHROME_USER_MANAGER_UTIL_H_
diff --git a/chrome/browser/chromeos/login/users/fake_chrome_user_manager.cc b/chrome/browser/chromeos/login/users/fake_chrome_user_manager.cc
index 0d4812f..a6c1dbc 100644
--- a/chrome/browser/chromeos/login/users/fake_chrome_user_manager.cc
+++ b/chrome/browser/chromeos/login/users/fake_chrome_user_manager.cc
@@ -4,12 +4,18 @@
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
+#include "base/command_line.h"
+#include "base/sys_info.h"
#include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
+#include "chrome/browser/chromeos/login/users/chrome_user_manager_util.h"
#include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h"
#include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/grit/theme_resources.h"
+#include "chromeos/chromeos_switches.h"
+#include "chromeos/login/login_state.h"
+#include "chromeos/login/user_names.h"
#include "components/user_manager/user_image/user_image.h"
#include "components/user_manager/user_type.h"
#include "ui/base/resource/resource_bundle.h"
@@ -188,4 +194,63 @@ UserFlow* FakeChromeUserManager::GetDefaultUserFlow() const {
return default_flow_.get();
}
+void FakeChromeUserManager::UpdateLoginState(
+ const user_manager::User* active_user,
+ const user_manager::User* primary_user,
+ bool is_current_user_owner) const {
+ chrome_user_manager_util::UpdateLoginState(active_user, primary_user,
+ is_current_user_owner);
+}
+
+bool FakeChromeUserManager::GetPlatformKnownUserId(
+ const std::string& user_email,
+ const std::string& gaia_id,
+ AccountId* out_account_id) const {
+ return chrome_user_manager_util::GetPlatformKnownUserId(user_email, gaia_id,
+ out_account_id);
+}
+
+const AccountId& FakeChromeUserManager::GetGuestAccountId() const {
+ return login::GuestAccountId();
+}
+
+bool FakeChromeUserManager::IsFirstExecAfterBoot() const {
+ return base::CommandLine::ForCurrentProcess()->HasSwitch(
+ chromeos::switches::kFirstExecAfterBoot);
+}
+
+void FakeChromeUserManager::AsyncRemoveCryptohome(
+ const AccountId& account_id) const {
+ NOTIMPLEMENTED();
+}
+
+bool FakeChromeUserManager::IsGuestAccountId(
+ const AccountId& account_id) const {
+ return account_id == login::GuestAccountId();
+}
+
+bool FakeChromeUserManager::IsStubAccountId(const AccountId& account_id) const {
+ return account_id == login::StubAccountId();
+}
+
+bool FakeChromeUserManager::IsSupervisedAccountId(
+ const AccountId& account_id) const {
+ return gaia::ExtractDomainName(account_id.GetUserEmail()) ==
+ chromeos::login::kSupervisedUserDomain;
+}
+
+bool FakeChromeUserManager::HasBrowserRestarted() const {
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+ return base::SysInfo::IsRunningOnChromeOS() &&
+ command_line->HasSwitch(chromeos::switches::kLoginUser);
+}
+
+void FakeChromeUserManager::ScheduleResolveLocale(
+ const std::string& locale,
+ const base::Closure& on_resolved_callback,
+ std::string* out_resolved_locale) const {
+ NOTIMPLEMENTED();
+ return;
+}
+
} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/users/fake_chrome_user_manager.h b/chrome/browser/chromeos/login/users/fake_chrome_user_manager.h
index b6aed65..76acc9f 100644
--- a/chrome/browser/chromeos/login/users/fake_chrome_user_manager.h
+++ b/chrome/browser/chromeos/login/users/fake_chrome_user_manager.h
@@ -63,6 +63,22 @@ class FakeChromeUserManager : public user_manager::FakeUserManager,
void RemoveUser(const AccountId& account_id,
user_manager::RemoveUserDelegate* delegate) override;
void RemoveUserFromList(const AccountId& account_id) override;
+ void UpdateLoginState(const user_manager::User* active_user,
+ const user_manager::User* primary_user,
+ bool is_current_user_owner) const override;
+ bool GetPlatformKnownUserId(const std::string& user_email,
+ const std::string& gaia_id,
+ AccountId* out_account_id) const override;
+ const AccountId& GetGuestAccountId() const override;
+ bool IsFirstExecAfterBoot() const override;
+ void AsyncRemoveCryptohome(const AccountId& account_id) const override;
+ bool IsGuestAccountId(const AccountId& account_id) const override;
+ bool IsStubAccountId(const AccountId& account_id) const override;
+ bool IsSupervisedAccountId(const AccountId& account_id) const override;
+ bool HasBrowserRestarted() const override;
+ void ScheduleResolveLocale(const std::string& locale,
+ const base::Closure& on_resolved_callback,
+ std::string* out_resolved_locale) const override;
void set_owner_id(const AccountId& owner_account_id) {
owner_account_id_ = owner_account_id;
diff --git a/chrome/browser/chromeos/login/users/mock_user_manager.cc b/chrome/browser/chromeos/login/users/mock_user_manager.cc
index 20be180..513cb27 100644
--- a/chrome/browser/chromeos/login/users/mock_user_manager.cc
+++ b/chrome/browser/chromeos/login/users/mock_user_manager.cc
@@ -29,7 +29,7 @@ class FakeTaskRunner : public base::TaskRunner {
namespace chromeos {
MockUserManager::MockUserManager()
- : ChromeUserManager(new FakeTaskRunner(), new FakeTaskRunner()),
+ : ChromeUserManager(new FakeTaskRunner()),
user_flow_(new DefaultUserFlow()),
supervised_user_manager_(new FakeSupervisedUserManager()) {
ProfileHelper::SetProfileToUserForTestingEnabled(true);
diff --git a/chrome/browser/chromeos/login/users/mock_user_manager.h b/chrome/browser/chromeos/login/users/mock_user_manager.h
index 77a25ad..f47f57f 100644
--- a/chrome/browser/chromeos/login/users/mock_user_manager.h
+++ b/chrome/browser/chromeos/login/users/mock_user_manager.h
@@ -75,6 +75,19 @@ class MockUserManager : public ChromeUserManager {
void(UserManager::UserSessionStateObserver*));
MOCK_METHOD0(NotifyLocalStateChanged, void(void));
MOCK_CONST_METHOD0(AreSupervisedUsersAllowed, bool(void));
+ MOCK_CONST_METHOD3(UpdateLoginState,
+ void(const user_manager::User*,
+ const user_manager::User*,
+ bool));
+ MOCK_CONST_METHOD1(AsyncRemoveCryptohome, void(const AccountId&));
+ MOCK_CONST_METHOD3(GetPlatformKnownUserId,
+ bool(const std::string&, const std::string&, AccountId*));
+ MOCK_CONST_METHOD0(GetGuestAccountId, const AccountId&());
+ MOCK_CONST_METHOD0(IsFirstExecAfterBoot, bool(void));
+ MOCK_CONST_METHOD1(IsGuestAccountId, bool(const AccountId&));
+ MOCK_CONST_METHOD1(IsStubAccountId, bool(const AccountId&));
+ MOCK_CONST_METHOD1(IsSupervisedAccountId, bool(const AccountId&));
+ MOCK_CONST_METHOD0(HasBrowserRestarted, bool(void));
// UserManagerBase overrides:
MOCK_CONST_METHOD0(AreEphemeralUsersEnabled, bool(void));
@@ -96,6 +109,10 @@ class MockUserManager : public ChromeUserManager {
MOCK_METHOD1(PublicAccountUserLoggedIn, void(user_manager::User*));
MOCK_METHOD1(SupervisedUserLoggedIn, void(const AccountId&));
MOCK_METHOD1(OnUserRemoved, void(const AccountId&));
+ MOCK_CONST_METHOD3(ScheduleResolveLocale,
+ void(const std::string&,
+ const base::Closure&,
+ std::string*));
// You can't mock these functions easily because nobody can create
// User objects but the ChromeUserManager and us.
diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi
index 38ca2577..1edda22 100644
--- a/chrome/chrome_browser_chromeos.gypi
+++ b/chrome/chrome_browser_chromeos.gypi
@@ -649,6 +649,8 @@
'browser/chromeos/login/users/avatar/user_image_manager_impl.h',
'browser/chromeos/login/users/avatar/user_image_sync_observer.cc',
'browser/chromeos/login/users/avatar/user_image_sync_observer.h',
+ 'browser/chromeos/login/users/chrome_user_manager_util.cc',
+ 'browser/chromeos/login/users/chrome_user_manager_util.h',
'browser/chromeos/login/users/chrome_user_manager.cc',
'browser/chromeos/login/users/chrome_user_manager.h',
'browser/chromeos/login/users/chrome_user_manager_impl.cc',
diff --git a/components/session_manager.gypi b/components/session_manager.gypi
index ee925e8..e87d3e0 100644
--- a/components/session_manager.gypi
+++ b/components/session_manager.gypi
@@ -22,13 +22,6 @@
'session_manager/core/session_manager.h',
'session_manager/session_manager_export.h',
],
- 'conditions': [
- ['chromeos == 1', {
- 'dependencies': [
- '<(DEPTH)/chromeos/chromeos.gyp:chromeos',
- ],
- }],
- ],
},
],
}
diff --git a/components/session_manager/DEPS b/components/session_manager/DEPS
deleted file mode 100644
index 85aa5db7..0000000
--- a/components/session_manager/DEPS
+++ /dev/null
@@ -1,3 +0,0 @@
-include_rules = [
- '+chromeos/chromeos_switches.h',
-]
diff --git a/components/session_manager/core/BUILD.gn b/components/session_manager/core/BUILD.gn
index 9bc5f84..311f63b 100644
--- a/components/session_manager/core/BUILD.gn
+++ b/components/session_manager/core/BUILD.gn
@@ -11,8 +11,5 @@ component("core") {
deps = [
"//base",
]
- if (is_chromeos) {
- deps += [ "//chromeos" ]
- }
defines = [ "SESSION_IMPLEMENTATION" ]
}
diff --git a/components/session_manager/core/session_manager.cc b/components/session_manager/core/session_manager.cc
index 226f5dd..b9295a1 100644
--- a/components/session_manager/core/session_manager.cc
+++ b/components/session_manager/core/session_manager.cc
@@ -7,12 +7,6 @@
#include "base/logging.h"
#include "build/build_config.h"
-#if defined(OS_CHROMEOS)
-#include "base/command_line.h"
-#include "base/sys_info.h"
-#include "chromeos/chromeos_switches.h"
-#endif
-
namespace session_manager {
// static
@@ -59,17 +53,6 @@ void SessionManager::Start() {
delegate_->Start();
}
-// static
-bool SessionManager::HasBrowserRestarted() {
-#if defined(OS_CHROMEOS)
- base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
- return base::SysInfo::IsRunningOnChromeOS() &&
- command_line->HasSwitch(chromeos::switches::kLoginUser);
-#else
- return false;
-#endif
-}
-
SessionManagerDelegate::SessionManagerDelegate() : session_manager_(NULL) {
}
diff --git a/components/session_manager/core/session_manager.h b/components/session_manager/core/session_manager.h
index 64a2132..9da9c45 100644
--- a/components/session_manager/core/session_manager.h
+++ b/components/session_manager/core/session_manager.h
@@ -57,10 +57,6 @@ class SESSION_EXPORT SessionManager {
// current session type / state.
void Start();
- // Returns true when the browser has crashed and restarted during the current
- // user's session.
- static bool HasBrowserRestarted();
-
protected:
// Initializes SessionManager with delegate.
void Initialize(SessionManagerDelegate* delegate);
diff --git a/components/user_manager.gypi b/components/user_manager.gypi
index 3fcb019..540cbac 100644
--- a/components/user_manager.gypi
+++ b/components/user_manager.gypi
@@ -54,12 +54,9 @@
['chromeos == 1', {
'dependencies': [
'<(DEPTH)/base/base.gyp:base_prefs',
- '<(DEPTH)/chromeos/chromeos.gyp:chromeos',
'<(DEPTH)/components/components.gyp:session_manager_component',
'<(DEPTH)/google_apis/google_apis.gyp:google_apis',
'<(DEPTH)/ui/base/ui_base.gyp:ui_base',
- '<(DEPTH)/ui/chromeos/ui_chromeos.gyp:ui_chromeos_resources',
- '<(DEPTH)/ui/chromeos/ui_chromeos.gyp:ui_chromeos_strings',
'<(DEPTH)/url/url.gyp:url_lib',
],
'sources': [ '<@(user_manager_chromeos_sources)' ],
diff --git a/components/user_manager/BUILD.gn b/components/user_manager/BUILD.gn
index 1c4019c..ce676aa 100644
--- a/components/user_manager/BUILD.gn
+++ b/components/user_manager/BUILD.gn
@@ -41,7 +41,6 @@ component("user_manager") {
]
deps += [
"//base:prefs",
- "//chromeos:chromeos",
"//components/session_manager/core",
"//google_apis",
"//ui/base",
@@ -62,6 +61,7 @@ source_set("test_support") {
deps = [
":user_manager",
"//base",
+ "//chromeos:chromeos",
"//components/signin/core/account_id",
"//skia",
"//ui/base",
diff --git a/components/user_manager/DEPS b/components/user_manager/DEPS
index 5c77f80..84cc1c6 100644
--- a/components/user_manager/DEPS
+++ b/components/user_manager/DEPS
@@ -1,7 +1,5 @@
include_rules = [
"+chromeos/chromeos_switches.h",
-"+chromeos/cryptohome/async_method_caller.h",
-"+chromeos/login/login_state.h",
"+chromeos/login/user_names.h",
"+components/session_manager/core/session_manager.h",
"+components/signin/core/account_id/account_id.h",
@@ -10,6 +8,7 @@ include_rules = [
"+ui/base/l10n",
"+ui/base/resource",
"+ui/chromeos/resources/grit",
+"+ui/chromeos/resources/grit/ui_chromeos_resources.h",
"+ui/chromeos/strings/grit",
"+ui/gfx/codec",
"+ui/gfx/image",
diff --git a/components/user_manager/fake_user_manager.cc b/components/user_manager/fake_user_manager.cc
index 4caa1b3..b82d519 100644
--- a/components/user_manager/fake_user_manager.cc
+++ b/components/user_manager/fake_user_manager.cc
@@ -5,9 +5,12 @@
#include "components/user_manager/fake_user_manager.h"
#include "base/callback.h"
+#include "base/command_line.h"
+#include "base/sys_info.h"
#include "base/task_runner.h"
+#include "chromeos/chromeos_switches.h"
+#include "chromeos/login/user_names.h"
#include "components/user_manager/user_type.h"
-#include "ui/base/resource/resource_bundle.h"
namespace {
@@ -30,8 +33,7 @@ class FakeTaskRunner : public base::TaskRunner {
namespace user_manager {
FakeUserManager::FakeUserManager()
- : UserManagerBase(new FakeTaskRunner(), new FakeTaskRunner()),
- primary_user_(nullptr) {}
+ : UserManagerBase(new FakeTaskRunner()), primary_user_(nullptr) {}
FakeUserManager::~FakeUserManager() {
}
@@ -284,4 +286,62 @@ bool FakeUserManager::IsPublicAccountMarkedForRemoval(
return false;
}
+void FakeUserManager::UpdateLoginState(const user_manager::User* active_user,
+ const user_manager::User* primary_user,
+ bool is_current_user_owner) const {}
+
+bool FakeUserManager::GetPlatformKnownUserId(const std::string& user_email,
+ const std::string& gaia_id,
+ AccountId* out_account_id) const {
+ if (user_email == chromeos::login::kStubUser) {
+ *out_account_id = chromeos::login::StubAccountId();
+ return true;
+ }
+
+ if (user_email == chromeos::login::kGuestUserName) {
+ *out_account_id = chromeos::login::GuestAccountId();
+ return true;
+ }
+ return false;
+}
+
+const AccountId& FakeUserManager::GetGuestAccountId() const {
+ return chromeos::login::GuestAccountId();
+}
+
+bool FakeUserManager::IsFirstExecAfterBoot() const {
+ return base::CommandLine::ForCurrentProcess()->HasSwitch(
+ chromeos::switches::kFirstExecAfterBoot);
+}
+
+void FakeUserManager::AsyncRemoveCryptohome(const AccountId& account_id) const {
+ NOTIMPLEMENTED();
+}
+
+bool FakeUserManager::IsGuestAccountId(const AccountId& account_id) const {
+ return account_id == chromeos::login::GuestAccountId();
+}
+
+bool FakeUserManager::IsStubAccountId(const AccountId& account_id) const {
+ return account_id == chromeos::login::StubAccountId();
+}
+
+bool FakeUserManager::IsSupervisedAccountId(const AccountId& account_id) const {
+ return false;
+}
+
+bool FakeUserManager::HasBrowserRestarted() const {
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+ return base::SysInfo::IsRunningOnChromeOS() &&
+ command_line->HasSwitch(chromeos::switches::kLoginUser);
+}
+
+void FakeUserManager::ScheduleResolveLocale(
+ const std::string& locale,
+ const base::Closure& on_resolved_callback,
+ std::string* out_resolved_locale) const {
+ NOTIMPLEMENTED();
+ return;
+}
+
} // namespace user_manager
diff --git a/components/user_manager/fake_user_manager.h b/components/user_manager/fake_user_manager.h
index c85bcde..3a7637c 100644
--- a/components/user_manager/fake_user_manager.h
+++ b/components/user_manager/fake_user_manager.h
@@ -51,6 +51,11 @@ class USER_MANAGER_EXPORT FakeUserManager : public UserManagerBase {
void SwitchActiveUser(const AccountId& account_id) override;
void SaveUserDisplayName(const AccountId& account_id,
const base::string16& display_name) override;
+ const AccountId& GetGuestAccountId() const override;
+ bool IsFirstExecAfterBoot() const override;
+ bool IsGuestAccountId(const AccountId& account_id) const override;
+ bool IsStubAccountId(const AccountId& account_id) const override;
+ bool HasBrowserRestarted() const override;
// Not implemented.
void UpdateUserAccountData(const AccountId& account_id,
@@ -99,6 +104,17 @@ class USER_MANAGER_EXPORT FakeUserManager : public UserManagerBase {
void RemoveSessionStateObserver(UserSessionStateObserver* obs) override {}
void NotifyLocalStateChanged() override {}
bool AreSupervisedUsersAllowed() const override;
+ void UpdateLoginState(const user_manager::User* active_user,
+ const user_manager::User* primary_user,
+ bool is_current_user_owner) const override;
+ bool GetPlatformKnownUserId(const std::string& user_email,
+ const std::string& gaia_id,
+ AccountId* out_account_id) const override;
+ void AsyncRemoveCryptohome(const AccountId& account_id) const override;
+ bool IsSupervisedAccountId(const AccountId& account_id) const override;
+ void ScheduleResolveLocale(const std::string& locale,
+ const base::Closure& on_resolved_callback,
+ std::string* out_resolved_locale) const override;
// UserManagerBase overrides:
bool AreEphemeralUsersEnabled() const override;
diff --git a/components/user_manager/known_user.cc b/components/user_manager/known_user.cc
index aa28fa7..b9adce4 100644
--- a/components/user_manager/known_user.cc
+++ b/components/user_manager/known_user.cc
@@ -11,7 +11,6 @@
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "base/values.h"
-#include "chromeos/login/user_names.h"
#include "components/user_manager/user_manager.h"
#include "google_apis/gaia/gaia_auth_util.h"
@@ -216,11 +215,12 @@ AccountId GetAccountId(const std::string& user_email,
if (user_email.empty() && gaia_id.empty())
return EmptyAccountId();
- if (user_email == chromeos::login::kStubUser)
- return chromeos::login::StubAccountId();
-
- if (user_email == chromeos::login::kGuestUserName)
- return chromeos::login::GuestAccountId();
+ AccountId result(EmptyAccountId());
+ UserManager* user_manager = UserManager::Get();
+ if (user_manager &&
+ user_manager->GetPlatformKnownUserId(user_email, gaia_id, &result)) {
+ return result;
+ }
// We can have several users with the same gaia_id but different e-mails.
// The opposite case is not possible.
diff --git a/components/user_manager/user.cc b/components/user_manager/user.cc
index a76546c..ef21de5 100644
--- a/components/user_manager/user.cc
+++ b/components/user_manager/user.cc
@@ -11,11 +11,9 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
-#include "chromeos/login/user_names.h"
#include "components/signin/core/account_id/account_id.h"
#include "components/user_manager/user_image/default_user_images.h"
#include "google_apis/gaia/gaia_auth_util.h"
-#include "ui/base/resource/resource_bundle.h"
namespace user_manager {
@@ -61,7 +59,7 @@ class RegularUser : public User {
class GuestUser : public User {
public:
- GuestUser();
+ explicit GuestUser(const AccountId& guest_account_id);
~GuestUser() override;
// Overridden from User:
@@ -187,8 +185,8 @@ User* User::CreateRegularUser(const AccountId& account_id) {
return new RegularUser(account_id);
}
-User* User::CreateGuestUser() {
- return new GuestUser;
+User* User::CreateGuestUser(const AccountId& guest_account_id) {
+ return new GuestUser(guest_account_id);
}
User* User::CreateKioskAppUser(const AccountId& kiosk_app_account_id) {
@@ -255,7 +253,8 @@ void RegularUser::SetIsChild(bool is_child) {
is_child_ = is_child;
}
-GuestUser::GuestUser() : User(chromeos::login::GuestAccountId()) {
+GuestUser::GuestUser(const AccountId& guest_account_id)
+ : User(guest_account_id) {
set_display_email(std::string());
}
diff --git a/components/user_manager/user.h b/components/user_manager/user.h
index b4e1198..2f5542a 100644
--- a/components/user_manager/user.h
+++ b/components/user_manager/user.h
@@ -184,7 +184,7 @@ class USER_MANAGER_EXPORT User : public UserInfo {
// Do not allow anyone else to create new User instances.
static User* CreateRegularUser(const AccountId& account_id);
- static User* CreateGuestUser();
+ static User* CreateGuestUser(const AccountId& guest_account_id);
static User* CreateKioskAppUser(const AccountId& kiosk_app_account_id);
static User* CreateSupervisedUser(const AccountId& account_id);
static User* CreatePublicAccountUser(const AccountId& account_id);
diff --git a/components/user_manager/user_manager.cc b/components/user_manager/user_manager.cc
index 22425b8..b0cd217 100644
--- a/components/user_manager/user_manager.cc
+++ b/components/user_manager/user_manager.cc
@@ -5,7 +5,6 @@
#include "components/user_manager/user_manager.h"
#include "base/logging.h"
-#include "chromeos/login/user_names.h"
#include "components/signin/core/account_id/account_id.h"
namespace user_manager {
diff --git a/components/user_manager/user_manager.h b/components/user_manager/user_manager.h
index 55245ad..e95b81a 100644
--- a/components/user_manager/user_manager.h
+++ b/components/user_manager/user_manager.h
@@ -7,7 +7,9 @@
#include <string>
+#include "base/callback_forward.h"
#include "base/macros.h"
+#include "base/strings/string16.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager_export.h"
#include "components/user_manager/user_type.h"
@@ -20,9 +22,14 @@ class DictionaryValue;
}
namespace chromeos {
+class LoginState;
class ScopedUserManagerEnabler;
}
+namespace cryptohome {
+class AsyncMethodCaller;
+}
+
namespace user_manager {
class RemoveUserDelegate;
@@ -90,7 +97,7 @@ class USER_MANAGER_EXPORT UserManager {
// after creation so that user_manager::UserManager::Get() doesn't fail.
// Tests could call this method if they are replacing existing UserManager
// instance with their own test instance.
- void Initialize();
+ virtual void Initialize();
// Checks whether the UserManager instance has been created already.
// This method is not thread-safe and must be called from the main UI thread.
@@ -320,6 +327,42 @@ class USER_MANAGER_EXPORT UserManager {
// Returns "Local State" PrefService instance.
virtual PrefService* GetLocalState() const = 0;
+ // Checks for platform-specific known users matching given |user_email| and
+ // |gaia_id|. If data matches a known account, fills |out_account_id| with
+ // account id and returns true.
+ virtual bool GetPlatformKnownUserId(const std::string& user_email,
+ const std::string& gaia_id,
+ AccountId* out_account_id) const = 0;
+
+ // Returns account id of the Guest user.
+ virtual const AccountId& GetGuestAccountId() const = 0;
+
+ // Returns true if this is first exec after boot.
+ virtual bool IsFirstExecAfterBoot() const = 0;
+
+ // Actually removes cryptohome.
+ virtual void AsyncRemoveCryptohome(const AccountId& account_id) const = 0;
+
+ // Returns true if |account_id| is Guest user.
+ virtual bool IsGuestAccountId(const AccountId& account_id) const = 0;
+
+ // Returns true if |account_id| is Stub user.
+ virtual bool IsStubAccountId(const AccountId& account_id) const = 0;
+
+ // Returns true if |account_id| is supervised.
+ virtual bool IsSupervisedAccountId(const AccountId& account_id) const = 0;
+
+ // Returns true when the browser has crashed and restarted during the current
+ // user's session.
+ virtual bool HasBrowserRestarted() const = 0;
+
+ // Schedules CheckAndResolveLocale using given task runner and
+ // |on_resolved_callback| as reply callback.
+ virtual void ScheduleResolveLocale(
+ const std::string& locale,
+ const base::Closure& on_resolved_callback,
+ std::string* out_resolved_locale) const = 0;
+
protected:
// Sets UserManager instance.
static void SetInstance(UserManager* user_manager);
diff --git a/components/user_manager/user_manager_base.cc b/components/user_manager/user_manager_base.cc
index 487ce56..00d81e7 100644
--- a/components/user_manager/user_manager_base.cc
+++ b/components/user_manager/user_manager_base.cc
@@ -25,16 +25,11 @@
#include "base/strings/utf_string_conversions.h"
#include "base/task_runner.h"
#include "base/values.h"
-#include "chromeos/chromeos_switches.h"
-#include "chromeos/cryptohome/async_method_caller.h"
-#include "chromeos/login/login_state.h"
-#include "chromeos/login/user_names.h"
#include "components/session_manager/core/session_manager.h"
#include "components/user_manager/known_user.h"
#include "components/user_manager/remove_user_delegate.h"
#include "components/user_manager/user_type.h"
#include "google_apis/gaia/gaia_auth_util.h"
-#include "ui/base/l10n/l10n_util.h"
namespace user_manager {
namespace {
@@ -76,23 +71,6 @@ const char kLastActiveUser[] = "LastActiveUser";
// one regular user logging out and a different regular user logging in.
const int kLogoutToLoginDelayMaxSec = 1800;
-// Callback that is called after user removal is complete.
-void OnRemoveUserComplete(const AccountId& account_id,
- bool success,
- cryptohome::MountError return_code) {
- // Log the error, but there's not much we can do.
- if (!success) {
- LOG(ERROR) << "Removal of cryptohome for " << account_id.Serialize()
- << " failed, return code: " << return_code;
- }
-}
-
-// Runs on SequencedWorkerPool thread. Passes resolved locale to UI thread.
-void ResolveLocale(const std::string& raw_locale,
- std::string* resolved_locale) {
- ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale));
-}
-
} // namespace
// static
@@ -110,14 +88,8 @@ void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) {
known_user::RegisterPrefs(registry);
}
-UserManagerBase::UserManagerBase(
- scoped_refptr<base::TaskRunner> task_runner,
- scoped_refptr<base::TaskRunner> blocking_task_runner)
- : task_runner_(task_runner),
- blocking_task_runner_(blocking_task_runner),
- weak_factory_(this) {
- UpdateLoginState();
-}
+UserManagerBase::UserManagerBase(scoped_refptr<base::TaskRunner> task_runner)
+ : task_runner_(task_runner), weak_factory_(this) {}
UserManagerBase::~UserManagerBase() {
// Can't use STLDeleteElements because of the private destructor of User.
@@ -178,7 +150,7 @@ void UserManagerBase::UserLoggedIn(const AccountId& account_id,
return;
}
- if (account_id == chromeos::login::GuestAccountId()) {
+ if (IsGuestAccountId(account_id)) {
GuestUserLoggedIn();
} else if (IsKioskApp(account_id)) {
KioskAppLoggedIn(account_id);
@@ -190,9 +162,7 @@ void UserManagerBase::UserLoggedIn(const AccountId& account_id,
if (user && user->GetType() == USER_TYPE_PUBLIC_ACCOUNT) {
PublicAccountUserLoggedIn(user);
} else if ((user && user->GetType() == USER_TYPE_SUPERVISED) ||
- (!user &&
- gaia::ExtractDomainName(account_id.GetUserEmail()) ==
- chromeos::login::kSupervisedUserDomain)) {
+ (!user && IsSupervisedAccountId(account_id))) {
SupervisedUserLoggedIn(account_id);
} else if (browser_restart && IsPublicAccountMarkedForRemoval(account_id)) {
PublicAccountUserLoggedIn(User::CreatePublicAccountUser(account_id));
@@ -282,7 +252,7 @@ void UserManagerBase::SessionStarted() {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
session_started_ = true;
- UpdateLoginState();
+ CallUpdateLoginState();
session_manager::SessionManager::Get()->SetSessionState(
session_manager::SESSION_STATE_ACTIVE);
@@ -312,8 +282,7 @@ void UserManagerBase::RemoveNonOwnerUserInternal(const AccountId& account_id,
if (delegate)
delegate->OnBeforeUserRemoved(account_id);
RemoveUserFromList(account_id);
- cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove(
- account_id.GetUserEmail(), base::Bind(&OnRemoveUserComplete, account_id));
+ AsyncRemoveCryptohome(account_id);
if (delegate)
delegate->OnUserRemoved(account_id);
@@ -325,8 +294,7 @@ void UserManagerBase::RemoveUserFromList(const AccountId& account_id) {
if (user_loading_stage_ == STAGE_LOADED) {
DeleteUser(RemoveRegularOrSupervisedUserFromList(account_id));
} else if (user_loading_stage_ == STAGE_LOADING) {
- DCHECK(gaia::ExtractDomainName(account_id.GetUserEmail()) ==
- chromeos::login::kSupervisedUserDomain ||
+ DCHECK(IsSupervisedAccountId(account_id) ||
HasPendingBootstrap(account_id));
// Special case, removing partially-constructed supervised user or
// boostrapping user during user list loading.
@@ -552,7 +520,7 @@ void UserManagerBase::SetCurrentUserIsOwner(bool is_current_user_owner) {
base::AutoLock lk(is_current_user_owner_lock_);
is_current_user_owner_ = is_current_user_owner;
}
- UpdateLoginState();
+ CallUpdateLoginState();
}
bool UserManagerBase::IsCurrentUserNew() const {
@@ -609,8 +577,7 @@ bool UserManagerBase::IsLoggedInAsKioskApp() const {
bool UserManagerBase::IsLoggedInAsStub() const {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
- return IsUserLoggedIn() &&
- active_user_->email() == chromeos::login::kStubUser;
+ return IsUserLoggedIn() && IsStubAccountId(active_user_->GetAccountId());
}
bool UserManagerBase::IsSessionStarted() const {
@@ -621,10 +588,8 @@ bool UserManagerBase::IsSessionStarted() const {
bool UserManagerBase::IsUserNonCryptohomeDataEphemeral(
const AccountId& account_id) const {
// Data belonging to the guest and stub users is always ephemeral.
- if (account_id == chromeos::login::GuestAccountId() ||
- account_id == chromeos::login::StubAccountId()) {
+ if (IsGuestAccountId(account_id) || IsStubAccountId(account_id))
return true;
- }
// Data belonging to the owner, anyone found on the user list and obsolete
// public accounts whose data has not been removed yet is not ephemeral.
@@ -649,8 +614,7 @@ bool UserManagerBase::IsUserNonCryptohomeDataEphemeral(
// enabled.
// - or -
// b) The browser is restarting after a crash.
- return AreEphemeralUsersEnabled() ||
- session_manager::SessionManager::HasBrowserRestarted();
+ return AreEphemeralUsersEnabled() || HasBrowserRestarted();
}
void UserManagerBase::AddObserver(UserManager::Observer* obs) {
@@ -772,8 +736,7 @@ void UserManagerBase::EnsureUsersLoaded() {
for (std::vector<AccountId>::const_iterator it = regular_users.begin();
it != regular_users.end(); ++it) {
User* user = nullptr;
- const std::string domain = gaia::ExtractDomainName(it->GetUserEmail());
- if (domain == chromeos::login::kSupervisedUserDomain) {
+ if (IsSupervisedAccountId(*it)) {
user = User::CreateSupervisedUser(*it);
} else {
user = User::CreateRegularUser(*it);
@@ -849,7 +812,7 @@ User* UserManagerBase::FindUserInListAndModify(const AccountId& account_id) {
void UserManagerBase::GuestUserLoggedIn() {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
- active_user_ = User::CreateGuestUser();
+ active_user_ = User::CreateGuestUser(GetGuestAccountId());
}
void UserManagerBase::AddUserRecord(User* user) {
@@ -891,7 +854,7 @@ void UserManagerBase::NotifyOnLogin() {
NotifyActiveUserHashChanged(active_user_->username_hash());
NotifyActiveUserChanged(active_user_);
- UpdateLoginState();
+ CallUpdateLoginState();
}
User::OAuthTokenStatus UserManagerBase::LoadUserOAuthStatus(
@@ -1012,37 +975,13 @@ void UserManagerBase::ChangeUserChildStatus(User* user, bool is_child) {
UserChangedChildStatus(user));
}
-void UserManagerBase::UpdateLoginState() {
- if (!chromeos::LoginState::IsInitialized())
- return; // LoginState may not be initialized in tests.
-
- chromeos::LoginState::LoggedInState logged_in_state;
- logged_in_state = active_user_ ? chromeos::LoginState::LOGGED_IN_ACTIVE
- : chromeos::LoginState::LOGGED_IN_NONE;
-
- chromeos::LoginState::LoggedInUserType login_user_type;
- if (logged_in_state == chromeos::LoginState::LOGGED_IN_NONE)
- login_user_type = chromeos::LoginState::LOGGED_IN_USER_NONE;
- else if (is_current_user_owner_)
- login_user_type = chromeos::LoginState::LOGGED_IN_USER_OWNER;
- else if (active_user_->GetType() == USER_TYPE_GUEST)
- login_user_type = chromeos::LoginState::LOGGED_IN_USER_GUEST;
- else if (active_user_->GetType() == USER_TYPE_PUBLIC_ACCOUNT)
- login_user_type = chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT;
- else if (active_user_->GetType() == USER_TYPE_SUPERVISED)
- login_user_type = chromeos::LoginState::LOGGED_IN_USER_SUPERVISED;
- else if (active_user_->GetType() == USER_TYPE_KIOSK_APP)
- login_user_type = chromeos::LoginState::LOGGED_IN_USER_KIOSK_APP;
- else
- login_user_type = chromeos::LoginState::LOGGED_IN_USER_REGULAR;
-
- if (primary_user_) {
- chromeos::LoginState::Get()->SetLoggedInStateAndPrimaryUser(
- logged_in_state, login_user_type, primary_user_->username_hash());
- } else {
- chromeos::LoginState::Get()->SetLoggedInState(logged_in_state,
- login_user_type);
- }
+void UserManagerBase::Initialize() {
+ UserManager::Initialize();
+ CallUpdateLoginState();
+}
+
+void UserManagerBase::CallUpdateLoginState() {
+ UpdateLoginState(active_user_, primary_user_, is_current_user_owner_);
}
void UserManagerBase::SetLRUUser(User* user) {
@@ -1059,21 +998,19 @@ void UserManagerBase::SetLRUUser(User* user) {
void UserManagerBase::SendGaiaUserLoginMetrics(const AccountId& account_id) {
// If this isn't the first time Chrome was run after the system booted,
// assume that Chrome was restarted because a previous session ended.
- if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
- chromeos::switches::kFirstExecAfterBoot)) {
- const std::string last_email =
- GetLocalState()->GetString(kLastLoggedInGaiaUser);
- const base::TimeDelta time_to_login =
- base::TimeTicks::Now() - manager_creation_time_;
- if (!last_email.empty() &&
- account_id != AccountId::FromUserEmail(last_email) &&
- time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) {
- UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay",
- time_to_login.InSeconds(),
- 0,
- kLogoutToLoginDelayMaxSec,
- 50);
- }
+ if (IsFirstExecAfterBoot())
+ return;
+
+ const std::string last_email =
+ GetLocalState()->GetString(kLastLoggedInGaiaUser);
+ const base::TimeDelta time_to_login =
+ base::TimeTicks::Now() - manager_creation_time_;
+ if (!last_email.empty() &&
+ account_id != AccountId::FromUserEmail(last_email) &&
+ time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) {
+ UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay",
+ time_to_login.InSeconds(), 0,
+ kLogoutToLoginDelayMaxSec, 50);
}
}
@@ -1081,15 +1018,14 @@ void UserManagerBase::UpdateUserAccountLocale(const AccountId& account_id,
const std::string& locale) {
scoped_ptr<std::string> resolved_locale(new std::string());
if (!locale.empty() && locale != GetApplicationLocale()) {
- // base::Pased will nullptr out |resolved_locale|, so cache the underlying
+ // base::Passed will nullptr out |resolved_locale|, so cache the underlying
// ptr.
std::string* raw_resolved_locale = resolved_locale.get();
- blocking_task_runner_->PostTaskAndReply(
- FROM_HERE, base::Bind(ResolveLocale, locale,
- base::Unretained(raw_resolved_locale)),
- base::Bind(&UserManagerBase::DoUpdateAccountLocale,
- weak_factory_.GetWeakPtr(), account_id,
- base::Passed(&resolved_locale)));
+ ScheduleResolveLocale(locale,
+ base::Bind(&UserManagerBase::DoUpdateAccountLocale,
+ weak_factory_.GetWeakPtr(), account_id,
+ base::Passed(&resolved_locale)),
+ raw_resolved_locale);
} else {
resolved_locale.reset(new std::string(locale));
DoUpdateAccountLocale(account_id, std::move(resolved_locale));
diff --git a/components/user_manager/user_manager_base.h b/components/user_manager/user_manager_base.h
index d97d5cb..00360ed 100644
--- a/components/user_manager/user_manager_base.h
+++ b/components/user_manager/user_manager_base.h
@@ -39,8 +39,7 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager {
public:
// Creates UserManagerBase with |task_runner| for UI thread and
// |blocking_task_runner| for SequencedWorkerPool.
- UserManagerBase(scoped_refptr<base::TaskRunner> task_runner,
- scoped_refptr<base::TaskRunner> blocking_task_runner);
+ explicit UserManagerBase(scoped_refptr<base::TaskRunner> task_runner);
~UserManagerBase() override;
// Registers UserManagerBase preferences.
@@ -106,6 +105,7 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager {
UserManager::UserSessionStateObserver* obs) override;
void NotifyLocalStateChanged() override;
void ChangeUserChildStatus(User* user, bool is_child) override;
+ void Initialize() override;
// This method updates "User was added to the device in this session nad is
// not full initialized yet" flag.
@@ -240,6 +240,11 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager {
// Should be called when regular user was removed.
virtual void OnUserRemoved(const AccountId& account_id) = 0;
+ // Update the global LoginState.
+ virtual void UpdateLoginState(const User* active_user,
+ const User* primary_user,
+ bool is_current_user_owner) const = 0;
+
// Getters/setters for private members.
virtual void SetCurrentUserIsOwner(bool is_current_user_owner);
@@ -312,8 +317,8 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager {
// Notifies observers that active account_id hash has changed.
void NotifyActiveUserHashChanged(const std::string& hash);
- // Update the global LoginState.
- void UpdateLoginState();
+ // Call UpdateLoginState.
+ void CallUpdateLoginState();
// Insert |user| at the front of the LRU user list.
void SetLRUUser(User* user);
@@ -382,9 +387,6 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager {
// TaskRunner for UI thread.
scoped_refptr<base::TaskRunner> task_runner_;
- // TaskRunner for SequencedWorkerPool.
- scoped_refptr<base::TaskRunner> blocking_task_runner_;
-
base::WeakPtrFactory<UserManagerBase> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(UserManagerBase);