1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/user_manager.h"
7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h"
9 #include "chrome/browser/chromeos/login/user_manager_impl.h"
10 #include "chrome/common/chrome_switches.h"
15 const char UserManager::kStubUser
[] = "stub-user@example.com";
18 // Should match cros constant in platform/libchromeos/chromeos/cryptohome.h
19 const char UserManager::kGuestUserName
[] = "$guest";
22 const char UserManager::kLocallyManagedUserDomain
[] =
23 "locally-managed.localhost";
27 const char UserManager::kRetailModeUserName
[] = "demouser@";
28 static UserManager
* g_user_manager
= NULL
;
30 UserManager::Observer::~Observer() {
33 void UserManager::Observer::LocalStateChanged(UserManager
* user_manager
) {
36 void UserManager::UserSessionStateObserver::ActiveUserChanged(
37 const User
* active_user
) {
40 void UserManager::UserSessionStateObserver::UserAddedToSession(
41 const User
* active_user
) {
44 void UserManager::UserSessionStateObserver::ActiveUserHashChanged(
45 const std::string
& hash
) {
48 void UserManager::UserSessionStateObserver::
49 PendingUserSessionsRestoreFinished() {
52 UserManager::UserSessionStateObserver::~UserSessionStateObserver() {
55 UserManager::UserAccountData::UserAccountData(const base::string16
& display_name
,
56 const base::string16
& given_name
,
57 const std::string
& locale
)
58 : display_name_(display_name
),
59 given_name_(given_name
),
63 UserManager::UserAccountData::~UserAccountData() {}
66 void UserManager::Initialize() {
67 CHECK(!g_user_manager
);
68 g_user_manager
= new UserManagerImpl();
72 bool UserManager::IsInitialized() {
73 return g_user_manager
;
76 void UserManager::Destroy() {
77 DCHECK(g_user_manager
);
78 delete g_user_manager
;
79 g_user_manager
= NULL
;
83 UserManager
* UserManager::Get() {
84 CHECK(g_user_manager
);
85 return g_user_manager
;
89 bool UserManager::IsMultipleProfilesAllowed() {
90 if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kMultiProfiles
))
93 // TODO(xiyuan): Get rid of this when the underlying support is ready.
94 const char kFieldTrialName
[] = "ChromeOSUseMultiProfiles";
95 const char kEnable
[] = "Enable";
96 return base::FieldTrialList::FindFullName(kFieldTrialName
) == kEnable
;
99 UserManager::~UserManager() {
103 UserManager
* UserManager::SetForTesting(UserManager
* user_manager
) {
104 UserManager
* previous_user_manager
= g_user_manager
;
105 g_user_manager
= user_manager
;
106 return previous_user_manager
;
109 ScopedUserManagerEnabler::ScopedUserManagerEnabler(UserManager
* user_manager
)
110 : previous_user_manager_(UserManager::SetForTesting(user_manager
)) {
113 ScopedUserManagerEnabler::~ScopedUserManagerEnabler() {
114 UserManager::Get()->Shutdown();
115 UserManager::Destroy();
116 UserManager::SetForTesting(previous_user_manager_
);
119 ScopedTestUserManager::ScopedTestUserManager() {
120 UserManager::Initialize();
123 ScopedTestUserManager::~ScopedTestUserManager() {
124 UserManager::Get()->Shutdown();
125 UserManager::Destroy();
128 } // namespace chromeos