Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 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_USER_MANAGER_H_ | 5 #ifndef COMPONENTS_USER_MANAGER_FAKE_USER_MANAGER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_FAKE_USER_MANAGER_H_ | 6 #define COMPONENTS_USER_MANAGER_FAKE_USER_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "chrome/browser/chromeos/login/user_flow.h" | |
| 13 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | |
| 14 #include "components/user_manager/user.h" | 12 #include "components/user_manager/user.h" |
| 15 #include "components/user_manager/user_image/user_image.h" | 13 #include "components/user_manager/user_image/user_image.h" |
| 14 #include "components/user_manager/user_manager_base.h" | |
| 16 | 15 |
| 17 namespace chromeos { | 16 namespace user_manager { |
| 18 | |
| 19 class FakeSupervisedUserManager; | |
| 20 | 17 |
| 21 // Fake user manager with a barebones implementation. Users can be added | 18 // Fake user manager with a barebones implementation. Users can be added |
| 22 // and set as logged in, and those users can be returned. | 19 // and set as logged in, and those users can be returned. |
| 23 class FakeUserManager : public ChromeUserManager { | 20 class USER_MANAGER_EXPORT FakeUserManager : public UserManagerBase { |
| 24 public: | 21 public: |
| 25 FakeUserManager(); | 22 FakeUserManager(); |
| 26 ~FakeUserManager() override; | 23 ~FakeUserManager() override; |
| 27 | 24 |
| 28 // Create and add a new user. | 25 // Create and add a new user. |
| 29 const user_manager::User* AddUser(const std::string& email); | 26 virtual const user_manager::User* AddUser(const std::string& email); |
| 30 | |
| 31 // Create and add a kiosk app user. | |
| 32 void AddKioskAppUser(const std::string& kiosk_app_username); | |
| 33 | |
| 34 // Create and add a public account user. | |
| 35 const user_manager::User* AddPublicAccountUser(const std::string& email); | |
| 36 | 27 |
| 37 // Calculates the user name hash and calls UserLoggedIn to login a user. | 28 // Calculates the user name hash and calls UserLoggedIn to login a user. |
| 38 void LoginUser(const std::string& email); | 29 void LoginUser(const std::string& email); |
| 39 | 30 |
| 40 // ChromeUserManager overrides. | |
| 41 MultiProfileUserController* GetMultiProfileUserController() override; | |
| 42 UserImageManager* GetUserImageManager(const std::string& user_id) override; | |
| 43 SupervisedUserManager* GetSupervisedUserManager() override; | |
| 44 void SetUserFlow(const std::string& email, UserFlow* flow) override {} | |
| 45 UserFlow* GetCurrentUserFlow() const override; | |
| 46 UserFlow* GetUserFlow(const std::string& email) const override; | |
| 47 void ResetUserFlow(const std::string& email) override {} | |
| 48 | |
| 49 // UserManager overrides. | 31 // UserManager overrides. |
| 50 const user_manager::UserList& GetUsers() const override; | 32 const user_manager::UserList& GetUsers() const override; |
| 51 user_manager::UserList GetUsersAllowedForMultiProfile() const override; | 33 user_manager::UserList GetUsersAllowedForMultiProfile() |
| 52 user_manager::UserList GetUsersAllowedForSupervisedUsersCreation() | |
| 53 const override; | 34 const override; |
| 54 const user_manager::UserList& GetLoggedInUsers() const override; | 35 const user_manager::UserList& GetLoggedInUsers() const override; |
| 55 | 36 |
| 56 // Set the user as logged in. | 37 // Set the user as logged in. |
| 57 void UserLoggedIn(const std::string& email, | 38 void UserLoggedIn(const std::string& email, |
| 58 const std::string& username_hash, | 39 const std::string& username_hash, |
| 59 bool browser_restart) override; | 40 bool browser_restart) override; |
| 60 | 41 |
| 61 const user_manager::User* GetActiveUser() const override; | 42 const user_manager::User* GetActiveUser() const override; |
| 62 user_manager::User* GetActiveUser() override; | 43 user_manager::User* GetActiveUser() override; |
| 63 void SwitchActiveUser(const std::string& email) override; | 44 void SwitchActiveUser(const std::string& email) override; |
| 64 void SaveUserDisplayName(const std::string& username, | 45 void SaveUserDisplayName(const std::string& username, |
| 65 const base::string16& display_name) override; | 46 const base::string16& display_name) override; |
| 66 | 47 |
| 67 // Not implemented. | 48 // Not implemented. |
| 68 void UpdateUserAccountData(const std::string& user_id, | 49 void UpdateUserAccountData( |
| 69 const UserAccountData& account_data) override {} | 50 const std::string& user_id, |
| 51 const UserAccountData& account_data) override {} | |
| 70 void Shutdown() override {} | 52 void Shutdown() override {} |
| 71 const user_manager::UserList& GetLRULoggedInUsers() const override; | 53 const user_manager::UserList& GetLRULoggedInUsers() const override; |
| 72 user_manager::UserList GetUnlockUsers() const override; | 54 user_manager::UserList GetUnlockUsers() const override; |
| 73 const std::string& GetOwnerEmail() const override; | 55 const std::string& GetOwnerEmail() const override; |
| 74 void SessionStarted() override {} | 56 void SessionStarted() override {} |
| 75 void RemoveUser(const std::string& email, | 57 void RemoveUser(const std::string& email, |
| 76 user_manager::RemoveUserDelegate* delegate) override {} | 58 user_manager::RemoveUserDelegate* delegate) override { |
| 59 } | |
| 77 void RemoveUserFromList(const std::string& email) override; | 60 void RemoveUserFromList(const std::string& email) override; |
| 78 bool IsKnownUser(const std::string& email) const override; | 61 bool IsKnownUser(const std::string& email) const override; |
| 79 const user_manager::User* FindUser(const std::string& email) const override; | 62 const user_manager::User* FindUser( |
| 80 user_manager::User* FindUserAndModify(const std::string& email) override; | 63 const std::string& email) const override; |
| 64 user_manager::User* FindUserAndModify( | |
| 65 const std::string& email) override; | |
| 81 const user_manager::User* GetLoggedInUser() const override; | 66 const user_manager::User* GetLoggedInUser() const override; |
| 82 user_manager::User* GetLoggedInUser() override; | 67 user_manager::User* GetLoggedInUser() override; |
| 83 const user_manager::User* GetPrimaryUser() const override; | 68 const user_manager::User* GetPrimaryUser() const override; |
| 84 void SaveUserOAuthStatus( | 69 void SaveUserOAuthStatus( |
| 85 const std::string& username, | 70 const std::string& username, |
| 86 user_manager::User::OAuthTokenStatus oauth_token_status) override {} | 71 user_manager::User::OAuthTokenStatus oauth_token_status) override {} |
| 87 void SaveForceOnlineSignin(const std::string& user_id, | 72 void SaveForceOnlineSignin(const std::string& user_id, |
| 88 bool force_online_signin) override {} | 73 bool force_online_signin) override {} |
| 89 base::string16 GetUserDisplayName(const std::string& username) const override; | 74 base::string16 GetUserDisplayName( |
| 75 const std::string& username) const override; | |
| 90 void SaveUserDisplayEmail(const std::string& username, | 76 void SaveUserDisplayEmail(const std::string& username, |
| 91 const std::string& display_email) override {} | 77 const std::string& display_email) override {} |
| 92 std::string GetUserDisplayEmail(const std::string& username) const override; | 78 std::string GetUserDisplayEmail( |
| 79 const std::string& username) const override; | |
| 93 bool IsCurrentUserOwner() const override; | 80 bool IsCurrentUserOwner() const override; |
| 94 bool IsCurrentUserNew() const override; | 81 bool IsCurrentUserNew() const override; |
| 95 bool IsCurrentUserNonCryptohomeDataEphemeral() const override; | 82 bool IsCurrentUserNonCryptohomeDataEphemeral() const override; |
| 96 bool CanCurrentUserLock() const override; | 83 bool CanCurrentUserLock() const override; |
| 97 bool IsUserLoggedIn() const override; | 84 bool IsUserLoggedIn() const override; |
| 98 bool IsLoggedInAsUserWithGaiaAccount() const override; | 85 bool IsLoggedInAsUserWithGaiaAccount() const override; |
| 99 bool IsLoggedInAsPublicAccount() const override; | 86 bool IsLoggedInAsPublicAccount() const override; |
| 100 bool IsLoggedInAsGuest() const override; | 87 bool IsLoggedInAsGuest() const override; |
| 101 bool IsLoggedInAsSupervisedUser() const override; | 88 bool IsLoggedInAsSupervisedUser() const override; |
| 102 bool IsLoggedInAsKioskApp() const override; | 89 bool IsLoggedInAsKioskApp() const override; |
| 103 bool IsLoggedInAsStub() const override; | 90 bool IsLoggedInAsStub() const override; |
| 104 bool IsSessionStarted() const override; | 91 bool IsSessionStarted() const override; |
| 105 bool IsUserNonCryptohomeDataEphemeral( | 92 bool IsUserNonCryptohomeDataEphemeral( |
| 106 const std::string& email) const override; | 93 const std::string& email) const override; |
| 107 void AddObserver(Observer* obs) override {} | 94 void AddObserver(Observer* obs) override {} |
| 108 void RemoveObserver(Observer* obs) override {} | 95 void RemoveObserver(Observer* obs) override {} |
| 109 void AddSessionStateObserver(UserSessionStateObserver* obs) override {} | 96 void AddSessionStateObserver( |
| 110 void RemoveSessionStateObserver(UserSessionStateObserver* obs) override {} | 97 UserSessionStateObserver* obs) override {} |
| 98 void RemoveSessionStateObserver( | |
| 99 UserSessionStateObserver* obs) override {} | |
| 111 void NotifyLocalStateChanged() override {} | 100 void NotifyLocalStateChanged() override {} |
| 112 bool AreSupervisedUsersAllowed() const override; | 101 bool AreSupervisedUsersAllowed() const override; |
| 113 | 102 |
| 114 // UserManagerBase overrides: | 103 // UserManagerBase overrides: |
| 115 bool AreEphemeralUsersEnabled() const override; | 104 bool AreEphemeralUsersEnabled() const override; |
| 116 const std::string& GetApplicationLocale() const override; | 105 const std::string& GetApplicationLocale() const override; |
| 117 PrefService* GetLocalState() const override; | 106 PrefService* GetLocalState() const override; |
| 118 void HandleUserOAuthTokenStatusChange( | 107 void HandleUserOAuthTokenStatusChange( |
| 119 const std::string& user_id, | 108 const std::string& user_id, |
| 120 user_manager::User::OAuthTokenStatus status) const override {} | 109 user_manager::User::OAuthTokenStatus status) const override {} |
| 121 bool IsEnterpriseManaged() const override; | 110 bool IsEnterpriseManaged() const override; |
| 122 void LoadPublicAccounts(std::set<std::string>* public_sessions_set) override { | 111 void LoadPublicAccounts( |
| 123 } | 112 std::set<std::string>* public_sessions_set) override {} |
| 124 void PerformPreUserListLoadingActions() override {} | 113 void PerformPreUserListLoadingActions() override {} |
| 125 void PerformPostUserListLoadingActions() override {} | 114 void PerformPostUserListLoadingActions() override {} |
| 126 void PerformPostUserLoggedInActions(bool browser_restart) override {} | 115 void PerformPostUserLoggedInActions(bool browser_restart) override {} |
| 127 bool IsDemoApp(const std::string& user_id) const override; | 116 bool IsDemoApp(const std::string& user_id) const override; |
| 128 bool IsKioskApp(const std::string& user_id) const override; | 117 bool IsKioskApp(const std::string& user_id) const override; |
| 129 bool IsPublicAccountMarkedForRemoval( | 118 bool IsPublicAccountMarkedForRemoval( |
| 130 const std::string& user_id) const override; | 119 const std::string& user_id) const override; |
| 131 void DemoAccountLoggedIn() override {} | 120 void DemoAccountLoggedIn() override {} |
| 132 void KioskAppLoggedIn(const std::string& app_id) override {} | 121 void KioskAppLoggedIn(const std::string& app_id) override {} |
| 133 void PublicAccountUserLoggedIn(user_manager::User* user) override {} | 122 void PublicAccountUserLoggedIn(user_manager::User* user) override {} |
| 134 void SupervisedUserLoggedIn(const std::string& user_id) override {} | 123 void SupervisedUserLoggedIn(const std::string& user_id) override {} |
| 135 | 124 |
| 136 void set_owner_email(const std::string& owner_email) { | 125 protected: |
| 137 owner_email_ = owner_email; | 126 user_manager::UserList user_list_; |
| 138 } | 127 user_manager::UserList logged_in_users_; |
| 139 | 128 |
| 140 void set_multi_profile_user_controller( | 129 user_manager::User* primary_user_; |
| 141 MultiProfileUserController* controller) { | 130 // If set this is the active user. If empty, the first created user is the |
|
ygorshenin1
2015/01/20 18:33:40
Nit: add an empty line before comment.
merkulova
2015/01/21 14:10:34
Done.
| |
| 142 multi_profile_user_controller_ = controller; | 131 // active user. |
| 143 } | 132 std::string active_user_id_; |
|
ygorshenin1
2015/01/20 18:33:40
Why not to store a pointer to a user instead of st
merkulova
2015/01/21 14:10:34
Left as discussed offline.
| |
| 144 | 133 |
| 145 private: | 134 private: |
| 146 // We use this internal function for const-correctness. | 135 // We use this internal function for const-correctness. |
| 147 user_manager::User* GetActiveUserInternal() const; | 136 user_manager::User* GetActiveUserInternal() const; |
| 148 | 137 |
| 149 scoped_ptr<FakeSupervisedUserManager> supervised_user_manager_; | 138 // stub, always empty string. |
| 150 user_manager::UserList user_list_; | |
| 151 user_manager::UserList logged_in_users_; | |
| 152 std::string owner_email_; | 139 std::string owner_email_; |
|
ygorshenin1
2015/01/20 18:33:40
Why not to just return std::string() in GetOwnerEm
merkulova
2015/01/21 14:10:34
Done.
| |
| 153 user_manager::User* primary_user_; | |
| 154 | |
| 155 // If set this is the active user. If empty, the first created user is the | |
| 156 // active user. | |
| 157 std::string active_user_id_; | |
| 158 MultiProfileUserController* multi_profile_user_controller_; | |
| 159 | 140 |
| 160 DISALLOW_COPY_AND_ASSIGN(FakeUserManager); | 141 DISALLOW_COPY_AND_ASSIGN(FakeUserManager); |
| 161 }; | 142 }; |
| 162 | 143 |
| 163 } // namespace chromeos | 144 } // namespace user_manager |
| 164 | 145 |
| 165 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_FAKE_USER_MANAGER_H_ | 146 #endif // COMPONENTS_USER_MANAGER_FAKE_USER_MANAGER_H_ |
| OLD | NEW |