1 // Copyright 2014 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. 4 5 #include "chrome/browser/chromeos/login/users/user_manager.h" 6 7 #include "base/command_line.h" 8 #include "base/prefs/pref_registry_simple.h" 9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process_platform_part_chromeos.h" 11 #include "chrome/browser/chromeos/login/users/user_manager_impl.h" 12 #include "chrome/browser/chromeos/profiles/profile_helper.h" 13 #include "chrome/common/chrome_switches.h" 14 15 namespace chromeos { 16 17 // static 18 const char UserManager::kStubUser[] = "stub-user (at) example.com"; 19 20 // static 21 const char UserManager::kSignInUser[] = "sign-in-user-id"; 22 23 // static 24 // Should match cros constant in platform/libchromeos/chromeos/cryptohome.h 25 const char UserManager::kGuestUserName[] = "$guest"; 26 27 // static 28 const char UserManager::kLocallyManagedUserDomain[] = 29 "locally-managed.localhost"; 30 31 32 // static 33 const char UserManager::kRetailModeUserName[] = "demouser@"; 34 static UserManager* g_user_manager = NULL; 35 36 UserManager::Observer::~Observer() { 37 } 38 39 void UserManager::Observer::LocalStateChanged(UserManager* user_manager) { 40 } 41 42 void UserManager::UserSessionStateObserver::ActiveUserChanged( 43 const User* active_user) { 44 } 45 46 void UserManager::UserSessionStateObserver::UserAddedToSession( 47 const User* active_user) { 48 } 49 50 void UserManager::UserSessionStateObserver::ActiveUserHashChanged( 51 const std::string& hash) { 52 } 53 54 void UserManager::UserSessionStateObserver:: 55 PendingUserSessionsRestoreFinished() { 56 } 57 58 UserManager::UserSessionStateObserver::~UserSessionStateObserver() { 59 } 60 61 UserManager::UserAccountData::UserAccountData( 62 const base::string16& display_name, 63 const base::string16& given_name, 64 const std::string& locale) 65 : display_name_(display_name), 66 given_name_(given_name), 67 locale_(locale) { 68 } 69 70 UserManager::UserAccountData::~UserAccountData() {} 71 72 // static 73 void UserManager::Initialize() { 74 CHECK(!g_user_manager); 75 g_user_manager = new UserManagerImpl(); 76 } 77 78 // static 79 bool UserManager::IsInitialized() { 80 return g_user_manager; 81 } 82 83 void UserManager::Destroy() { 84 DCHECK(g_user_manager); 85 delete g_user_manager; 86 g_user_manager = NULL; 87 } 88 89 // static 90 UserManager* UserManager::Get() { 91 CHECK(g_user_manager); 92 return g_user_manager; 93 } 94 95 UserManager::~UserManager() { 96 } 97 98 // static 99 UserManager* UserManager::SetForTesting(UserManager* user_manager) { 100 UserManager* previous_user_manager = g_user_manager; 101 if (previous_user_manager) 102 previous_user_manager->Shutdown(); 103 104 g_user_manager = user_manager; 105 return previous_user_manager; 106 } 107 108 ScopedUserManagerEnabler::ScopedUserManagerEnabler(UserManager* user_manager) 109 : previous_user_manager_(UserManager::SetForTesting(user_manager)) { 110 } 111 112 ScopedUserManagerEnabler::~ScopedUserManagerEnabler() { 113 UserManager::Get()->Shutdown(); 114 UserManager::Destroy(); 115 UserManager::SetForTesting(previous_user_manager_); 116 } 117 118 ScopedTestUserManager::ScopedTestUserManager() { 119 UserManager::Initialize(); 120 121 // ProfileHelper has to be initialized after UserManager instance is created. 122 g_browser_process->platform_part()->profile_helper()->Initialize(); 123 } 124 125 ScopedTestUserManager::~ScopedTestUserManager() { 126 UserManager::Get()->Shutdown(); 127 UserManager::Destroy(); 128 } 129 130 } // namespace chromeos 131