| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_FAKE_CHROME_USER_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_FAKE_CHROME_USER_MANAGER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_FAKE_CHROME_USER_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_FAKE_CHROME_USER_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "chrome/browser/chromeos/login/user_flow.h" | 13 #include "chrome/browser/chromeos/login/user_flow.h" |
| 14 #include "chrome/browser/chromeos/login/users/user_manager_interface.h" | 14 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| 15 #include "components/user_manager/fake_user_manager.h" | 15 #include "components/user_manager/fake_user_manager.h" |
| 16 #include "components/user_manager/user.h" | 16 #include "components/user_manager/user.h" |
| 17 #include "components/user_manager/user_image/user_image.h" | 17 #include "components/user_manager/user_image/user_image.h" |
| 18 #include "components/user_manager/user_manager_base.h" | |
| 19 | 18 |
| 20 namespace chromeos { | 19 namespace chromeos { |
| 21 | 20 |
| 22 class FakeSupervisedUserManager; | 21 class FakeSupervisedUserManager; |
| 23 | 22 |
| 24 // Fake chrome user manager with a barebones implementation. Users can be added | 23 // Fake chrome user manager with a barebones implementation. Users can be added |
| 25 // and set as logged in, and those users can be returned. | 24 // and set as logged in, and those users can be returned. |
| 26 class FakeChromeUserManager : public user_manager::FakeUserManager, | 25 class FakeChromeUserManager : public ChromeUserManager { |
| 27 public UserManagerInterface { | |
| 28 public: | 26 public: |
| 29 FakeChromeUserManager(); | 27 FakeChromeUserManager(); |
| 30 ~FakeChromeUserManager() override; | 28 ~FakeChromeUserManager() override; |
| 31 | 29 |
| 32 // Create and add a kiosk app user. | 30 // Create and add a kiosk app user. |
| 33 user_manager::User* AddKioskAppUser(const AccountId& account_id); | 31 user_manager::User* AddKioskAppUser(const AccountId& account_id); |
| 34 user_manager::User* AddArcKioskAppUser(const AccountId& account_id); | 32 user_manager::User* AddArcKioskAppUser(const AccountId& account_id); |
| 35 | 33 |
| 36 // Create and add a public account user. | 34 // Create and add a public account user. |
| 37 const user_manager::User* AddPublicAccountUser(const AccountId& account_id); | 35 const user_manager::User* AddPublicAccountUser(const AccountId& account_id); |
| 38 | 36 |
| 39 // Calculates the user name hash and calls UserLoggedIn to login a user. | 37 // Calculates the user name hash and calls UserLoggedIn to login a user. |
| 40 void LoginUser(const AccountId& account_id); | 38 void LoginUser(const AccountId& account_id); |
| 41 | 39 |
| 42 // UserManager overrides. | 40 const user_manager::User* AddUser(const AccountId& account_id); |
| 41 const user_manager::User* AddUserWithAffiliation(const AccountId& account_id, |
| 42 bool is_affiliated); |
| 43 |
| 44 // user_manager::UserManager override. |
| 45 void Shutdown() override; |
| 46 const user_manager::UserList& GetUsers() const override; |
| 43 user_manager::UserList GetUsersAllowedForMultiProfile() const override; | 47 user_manager::UserList GetUsersAllowedForMultiProfile() const override; |
| 44 | 48 const user_manager::UserList& GetLoggedInUsers() const override; |
| 45 // user_manager::FakeUserManager override. | 49 const user_manager::UserList& GetLRULoggedInUsers() const override; |
| 46 const user_manager::User* AddUser(const AccountId& account_id) override; | 50 user_manager::UserList GetUnlockUsers() const override; |
| 47 const user_manager::User* AddUserWithAffiliation(const AccountId& account_id, | 51 const AccountId& GetOwnerAccountId() const override; |
| 48 bool is_affiliated) override; | 52 void UserLoggedIn(const AccountId& account_id, |
| 49 bool AreEphemeralUsersEnabled() const override; | 53 const std::string& user_id_hash, |
| 50 | 54 bool browser_restart) override; |
| 51 // UserManagerInterface implementation. | |
| 52 BootstrapManager* GetBootstrapManager() override; | |
| 53 MultiProfileUserController* GetMultiProfileUserController() override; | |
| 54 UserImageManager* GetUserImageManager(const AccountId& account_id) override; | |
| 55 SupervisedUserManager* GetSupervisedUserManager() override; | |
| 56 void SetUserFlow(const AccountId& account_id, UserFlow* flow) override; | |
| 57 UserFlow* GetCurrentUserFlow() const override; | |
| 58 UserFlow* GetUserFlow(const AccountId& account_id) const override; | |
| 59 void ResetUserFlow(const AccountId& account_id) override; | |
| 60 user_manager::UserList GetUsersAllowedForSupervisedUsersCreation() | |
| 61 const override; | |
| 62 void SwitchActiveUser(const AccountId& account_id) override; | 55 void SwitchActiveUser(const AccountId& account_id) override; |
| 63 const AccountId& GetOwnerAccountId() const override; | 56 void SwitchToLastActiveUser() override; |
| 64 void OnSessionStarted() override; | 57 void OnSessionStarted() override; |
| 65 void RemoveUser(const AccountId& account_id, | 58 void RemoveUser(const AccountId& account_id, |
| 66 user_manager::RemoveUserDelegate* delegate) override; | 59 user_manager::RemoveUserDelegate* delegate) override; |
| 67 void RemoveUserFromList(const AccountId& account_id) override; | 60 void RemoveUserFromList(const AccountId& account_id) override; |
| 68 void UpdateLoginState(const user_manager::User* active_user, | 61 bool IsKnownUser(const AccountId& account_id) const override; |
| 69 const user_manager::User* primary_user, | 62 const user_manager::User* FindUser( |
| 70 bool is_current_user_owner) const override; | 63 const AccountId& account_id) const override; |
| 64 user_manager::User* FindUserAndModify(const AccountId& account_id) override; |
| 65 const user_manager::User* GetActiveUser() const override; |
| 66 user_manager::User* GetActiveUser() override; |
| 67 const user_manager::User* GetPrimaryUser() const override; |
| 68 void SaveUserOAuthStatus( |
| 69 const AccountId& account_id, |
| 70 user_manager::User::OAuthTokenStatus oauth_token_status) override; |
| 71 void SaveForceOnlineSignin(const AccountId& account_id, |
| 72 bool force_online_signin) override; |
| 73 void SaveUserDisplayName(const AccountId& account_id, |
| 74 const base::string16& display_name) override; |
| 75 base::string16 GetUserDisplayName(const AccountId& account_id) const override; |
| 76 void SaveUserDisplayEmail(const AccountId& account_id, |
| 77 const std::string& display_email) override; |
| 78 std::string GetUserDisplayEmail(const AccountId& account_id) const override; |
| 79 void SaveUserType(const AccountId& account_id, |
| 80 const user_manager::UserType& user_type) override; |
| 81 void UpdateUserAccountData(const AccountId& account_id, |
| 82 const UserAccountData& account_data) override; |
| 83 bool IsCurrentUserOwner() const override; |
| 84 bool IsCurrentUserNew() const override; |
| 85 bool IsCurrentUserNonCryptohomeDataEphemeral() const override; |
| 86 bool CanCurrentUserLock() const override; |
| 87 bool IsUserLoggedIn() const override; |
| 88 bool IsLoggedInAsUserWithGaiaAccount() const override; |
| 89 bool IsLoggedInAsChildUser() const override; |
| 90 bool IsLoggedInAsPublicAccount() const override; |
| 91 bool IsLoggedInAsGuest() const override; |
| 92 bool IsLoggedInAsSupervisedUser() const override; |
| 93 bool IsLoggedInAsKioskApp() const override; |
| 94 bool IsLoggedInAsArcKioskApp() const override; |
| 95 bool IsLoggedInAsStub() const override; |
| 96 bool IsUserNonCryptohomeDataEphemeral( |
| 97 const AccountId& account_id) const override; |
| 98 void AddObserver(UserManager::Observer* obs) override; |
| 99 void RemoveObserver(UserManager::Observer* obs) override; |
| 100 void AddSessionStateObserver( |
| 101 UserManager::UserSessionStateObserver* obs) override; |
| 102 void RemoveSessionStateObserver( |
| 103 UserManager::UserSessionStateObserver* obs) override; |
| 104 void NotifyLocalStateChanged() override; |
| 105 void ChangeUserChildStatus(user_manager::User* user, bool is_child) override; |
| 106 bool AreSupervisedUsersAllowed() const override; |
| 107 PrefService* GetLocalState() const override; |
| 71 bool GetPlatformKnownUserId(const std::string& user_email, | 108 bool GetPlatformKnownUserId(const std::string& user_email, |
| 72 const std::string& gaia_id, | 109 const std::string& gaia_id, |
| 73 AccountId* out_account_id) const override; | 110 AccountId* out_account_id) const override; |
| 74 const AccountId& GetGuestAccountId() const override; | 111 const AccountId& GetGuestAccountId() const override; |
| 75 bool IsFirstExecAfterBoot() const override; | 112 bool IsFirstExecAfterBoot() const override; |
| 76 void AsyncRemoveCryptohome(const AccountId& account_id) const override; | 113 void AsyncRemoveCryptohome(const AccountId& account_id) const override; |
| 77 bool IsGuestAccountId(const AccountId& account_id) const override; | 114 bool IsGuestAccountId(const AccountId& account_id) const override; |
| 78 bool IsStubAccountId(const AccountId& account_id) const override; | 115 bool IsStubAccountId(const AccountId& account_id) const override; |
| 79 bool IsSupervisedAccountId(const AccountId& account_id) const override; | 116 bool IsSupervisedAccountId(const AccountId& account_id) const override; |
| 80 bool HasBrowserRestarted() const override; | 117 bool HasBrowserRestarted() const override; |
| 81 const gfx::ImageSkia& GetResourceImagekiaNamed(int id) const override; | 118 const gfx::ImageSkia& GetResourceImagekiaNamed(int id) const override; |
| 82 base::string16 GetResourceStringUTF16(int string_id) const override; | 119 base::string16 GetResourceStringUTF16(int string_id) const override; |
| 83 void ScheduleResolveLocale(const std::string& locale, | 120 void ScheduleResolveLocale(const std::string& locale, |
| 84 const base::Closure& on_resolved_callback, | 121 const base::Closure& on_resolved_callback, |
| 85 std::string* out_resolved_locale) const override; | 122 std::string* out_resolved_locale) const override; |
| 86 bool IsValidDefaultUserImageId(int image_index) const override; | 123 bool IsValidDefaultUserImageId(int image_index) const override; |
| 124 bool AreEphemeralUsersEnabled() const override; |
| 125 void SetIsCurrentUserNew(bool is_new) override; |
| 126 void Initialize() override; |
| 127 |
| 128 // user_manager::UserManagerBase override. |
| 129 const std::string& GetApplicationLocale() const override; |
| 130 void HandleUserOAuthTokenStatusChange( |
| 131 const AccountId& account_id, |
| 132 user_manager::User::OAuthTokenStatus status) const override; |
| 133 void LoadDeviceLocalAccounts(std::set<AccountId>* users_set) override; |
| 134 bool IsEnterpriseManaged() const override; |
| 135 void PerformPreUserListLoadingActions() override; |
| 136 void PerformPostUserListLoadingActions() override; |
| 137 void PerformPostUserLoggedInActions(bool browser_restart) override; |
| 138 bool IsDemoApp(const AccountId& account_id) const override; |
| 139 bool IsDeviceLocalAccountMarkedForRemoval( |
| 140 const AccountId& account_id) const override; |
| 141 void DemoAccountLoggedIn() override; |
| 142 void KioskAppLoggedIn(user_manager::User* user) override; |
| 143 void ArcKioskAppLoggedIn(user_manager::User* user) override; |
| 144 void PublicAccountUserLoggedIn(user_manager::User* user) override; |
| 145 void SupervisedUserLoggedIn(const AccountId& account_id) override; |
| 146 void OnUserRemoved(const AccountId& account_id) override; |
| 147 void UpdateLoginState(const user_manager::User* active_user, |
| 148 const user_manager::User* primary_user, |
| 149 bool is_current_user_owner) const override; |
| 150 |
| 151 // UserManagerInterface override. |
| 152 BootstrapManager* GetBootstrapManager() override; |
| 153 MultiProfileUserController* GetMultiProfileUserController() override; |
| 154 UserImageManager* GetUserImageManager(const AccountId& account_id) override; |
| 155 SupervisedUserManager* GetSupervisedUserManager() override; |
| 156 void SetUserFlow(const AccountId& account_id, UserFlow* flow) override; |
| 157 UserFlow* GetCurrentUserFlow() const override; |
| 158 UserFlow* GetUserFlow(const AccountId& account_id) const override; |
| 159 void ResetUserFlow(const AccountId& account_id) override; |
| 160 user_manager::UserList GetUsersAllowedForSupervisedUsersCreation() |
| 161 const override; |
| 162 |
| 163 // ChromeUserManager override. |
| 164 void SetUserAffiliation( |
| 165 const std::string& user_email, |
| 166 const AffiliationIDSet& user_affiliation_ids) override; |
| 167 bool ShouldReportUser(const std::string& user_id) const override; |
| 87 | 168 |
| 88 void set_ephemeral_users_enabled(bool ephemeral_users_enabled) { | 169 void set_ephemeral_users_enabled(bool ephemeral_users_enabled) { |
| 89 fake_ephemeral_users_enabled_ = ephemeral_users_enabled; | 170 fake_ephemeral_users_enabled_ = ephemeral_users_enabled; |
| 90 } | 171 } |
| 91 | 172 |
| 92 void set_owner_id(const AccountId& owner_account_id) { | 173 void set_owner_id(const AccountId& owner_account_id) { |
| 93 owner_account_id_ = owner_account_id; | 174 owner_account_id_ = owner_account_id; |
| 94 } | 175 } |
| 95 | 176 |
| 96 void set_bootstrap_manager(BootstrapManager* bootstrap_manager) { | 177 void set_bootstrap_manager(BootstrapManager* bootstrap_manager) { |
| 97 bootstrap_manager_ = bootstrap_manager; | 178 bootstrap_manager_ = bootstrap_manager; |
| 98 } | 179 } |
| 99 | 180 |
| 100 void set_multi_profile_user_controller( | 181 void set_multi_profile_user_controller( |
| 101 MultiProfileUserController* controller) { | 182 MultiProfileUserController* controller) { |
| 102 multi_profile_user_controller_ = controller; | 183 multi_profile_user_controller_ = controller; |
| 103 } | 184 } |
| 104 | 185 |
| 105 private: | 186 private: |
| 106 // Lazily creates default user flow. | 187 // Lazily creates default user flow. |
| 107 UserFlow* GetDefaultUserFlow() const; | 188 UserFlow* GetDefaultUserFlow() const; |
| 108 | 189 |
| 190 // Returns the active user. |
| 191 user_manager::User* GetActiveUserInternal() const; |
| 192 |
| 109 std::unique_ptr<FakeSupervisedUserManager> supervised_user_manager_; | 193 std::unique_ptr<FakeSupervisedUserManager> supervised_user_manager_; |
| 110 AccountId owner_account_id_ = EmptyAccountId(); | 194 AccountId owner_account_id_ = EmptyAccountId(); |
| 111 bool fake_ephemeral_users_enabled_ = false; | 195 bool fake_ephemeral_users_enabled_ = false; |
| 112 | 196 |
| 113 BootstrapManager* bootstrap_manager_; | 197 BootstrapManager* bootstrap_manager_ = nullptr; |
| 114 MultiProfileUserController* multi_profile_user_controller_; | 198 MultiProfileUserController* multi_profile_user_controller_ = nullptr; |
| 199 |
| 200 // If set this is the active user. If empty, the first created user is the |
| 201 // active user. |
| 202 AccountId active_account_id_ = EmptyAccountId(); |
| 115 | 203 |
| 116 // Lazy-initialized default flow. | 204 // Lazy-initialized default flow. |
| 117 mutable std::unique_ptr<UserFlow> default_flow_; | 205 mutable std::unique_ptr<UserFlow> default_flow_; |
| 118 | 206 |
| 119 using FlowMap = std::map<AccountId, UserFlow*>; | 207 using FlowMap = std::map<AccountId, UserFlow*>; |
| 120 | 208 |
| 121 // Specific flows by user e-mail. | 209 // Specific flows by user e-mail. |
| 122 // Keys should be canonicalized before access. | 210 // Keys should be canonicalized before access. |
| 123 FlowMap specific_flows_; | 211 FlowMap specific_flows_; |
| 124 | 212 |
| 125 DISALLOW_COPY_AND_ASSIGN(FakeChromeUserManager); | 213 DISALLOW_COPY_AND_ASSIGN(FakeChromeUserManager); |
| 126 }; | 214 }; |
| 127 | 215 |
| 128 } // namespace chromeos | 216 } // namespace chromeos |
| 129 | 217 |
| 130 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_FAKE_CHROME_USER_MANAGER_H_ | 218 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_FAKE_CHROME_USER_MANAGER_H_ |
| OLD | NEW |