Chromium Code Reviews| Index: chrome/browser/chromeos/login/users/fake_chrome_user_manager.cc |
| 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 d8be14ea5683b769104275649622ec731fd646c3..5ef978b2b464e4338ba9ab377eea579ff9b23004 100644 |
| --- a/chrome/browser/chromeos/login/users/fake_chrome_user_manager.cc |
| +++ b/chrome/browser/chromeos/login/users/fake_chrome_user_manager.cc |
| @@ -22,12 +22,31 @@ |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/gfx/image/image_skia.h" |
| +namespace { |
| + |
| +class FakeTaskRunner : public base::TaskRunner { |
| + public: |
| + bool PostDelayedTask(const tracked_objects::Location& from_here, |
|
achuithb
2016/11/15 20:13:28
Add comment:
// TaskRunner overrides.
or something
yoshiki
2016/11/16 15:50:19
Done.
|
| + const base::Closure& task, |
| + base::TimeDelta delay) override { |
| + task.Run(); |
| + return true; |
| + } |
| + bool RunsTasksOnCurrentThread() const override { return true; } |
| + |
| + protected: |
| + ~FakeTaskRunner() override {} |
| +}; |
|
achuithb
2016/11/15 20:13:28
DISALLOW_COPY_AND_ASSIGN in private section
yoshiki
2016/11/16 15:50:19
Done.
|
| + |
| +} // namespace |
| + |
| namespace chromeos { |
| class FakeSupervisedUserManager; |
| FakeChromeUserManager::FakeChromeUserManager() |
| - : supervised_user_manager_(new FakeSupervisedUserManager), |
| + : ChromeUserManager(new FakeTaskRunner()), |
| + supervised_user_manager_(new FakeSupervisedUserManager), |
| bootstrap_manager_(NULL), |
| multi_profile_user_controller_(NULL) { |
|
achuithb
2016/11/15 20:13:28
move the initialization of these to header
yoshiki
2016/11/16 15:50:19
Done.
|
| ProfileHelper::SetProfileToUserForTestingEnabled(true); |
| @@ -177,7 +196,19 @@ void FakeChromeUserManager::RemoveUser( |
| void FakeChromeUserManager::RemoveUserFromList(const AccountId& account_id) { |
| WallpaperManager::Get()->RemoveUserWallpaperInfo(account_id); |
| chromeos::ProfileHelper::Get()->RemoveUserFromListForTesting(account_id); |
| - FakeUserManager::RemoveUserFromList(account_id); |
| + |
| + const user_manager::UserList::iterator it = |
| + std::find_if(users_.begin(), users_.end(), |
| + [&account_id](const user_manager::User* user) { |
| + return user->GetAccountId() == account_id; |
| + }); |
| + if (it != users_.end()) { |
| + if (primary_user_ == *it) |
| + primary_user_ = nullptr; |
| + if (active_user_ != *it) |
| + delete *it; |
| + users_.erase(it); |
| + } |
| } |
| user_manager::UserList |
| @@ -191,7 +222,7 @@ FakeChromeUserManager::GetUsersAllowedForSupervisedUsersCreation() const { |
| if (!allow_new_user || !supervised_users_allowed) |
| return user_manager::UserList(); |
| - return ChromeUserManager::GetUsersAllowedAsSupervisedUserManagers(GetUsers()); |
| + return GetUsersAllowedAsSupervisedUserManagers(GetUsers()); |
| } |
| user_manager::UserList FakeChromeUserManager::GetUsersAllowedForMultiProfile() |
| @@ -294,4 +325,324 @@ bool FakeChromeUserManager::IsValidDefaultUserImageId(int image_index) const { |
| return false; |
| } |
| +// UserManager implementation: |
| +void FakeChromeUserManager::Initialize() { |
| + return ChromeUserManager::Initialize(); |
| +} |
| + |
| +void FakeChromeUserManager::Shutdown() { |
| + return ChromeUserManager::Shutdown(); |
| +} |
| + |
| +const user_manager::UserList& FakeChromeUserManager::GetUsers() const { |
| + return users_; |
| +} |
| + |
| +const user_manager::UserList& FakeChromeUserManager::GetLoggedInUsers() const { |
| + return logged_in_users_; |
| +} |
| + |
| +const user_manager::UserList& FakeChromeUserManager::GetLRULoggedInUsers() |
| + const { |
| + return users_; |
| +} |
| + |
| +user_manager::UserList FakeChromeUserManager::GetUnlockUsers() const { |
| + return users_; |
| +} |
| + |
| +void FakeChromeUserManager::UserLoggedIn(const AccountId& account_id, |
| + const std::string& username_hash, |
| + bool browser_restart) { |
| + for (user_manager::UserList::const_iterator it = users_.begin(); |
|
achuithb
2016/11/15 20:13:28
range loop
yoshiki
2016/11/16 15:50:19
Done.
|
| + it != users_.end(); ++it) { |
| + if ((*it)->username_hash() == username_hash) { |
| + (*it)->set_is_logged_in(true); |
| + (*it)->set_profile_is_created(); |
| + logged_in_users_.push_back(*it); |
| + |
| + if (!primary_user_) |
| + primary_user_ = *it; |
| + break; |
| + } |
| + } |
| +} |
| + |
| +void FakeChromeUserManager::SwitchToLastActiveUser() { |
| + NOTREACHED(); |
| +} |
| + |
| +bool FakeChromeUserManager::IsKnownUser(const AccountId& account_id) const { |
| + return true; |
| +} |
| + |
| +const user_manager::User* FakeChromeUserManager::FindUser( |
| + const AccountId& account_id) const { |
| + if (active_user_ != nullptr && active_user_->GetAccountId() == account_id) |
| + return active_user_; |
| + |
| + const user_manager::UserList& users = GetUsers(); |
| + for (user_manager::UserList::const_iterator it = users.begin(); |
|
achuithb
2016/11/15 20:13:28
Does a range loop not work here?
yoshiki
2016/11/16 15:50:19
Done.
|
| + it != users.end(); ++it) { |
| + if ((*it)->GetAccountId() == account_id) |
| + return *it; |
| + } |
| + |
| + return nullptr; |
| +} |
| + |
| +user_manager::User* FakeChromeUserManager::FindUserAndModify( |
| + const AccountId& account_id) { |
| + return nullptr; |
| +} |
| + |
| +const user_manager::User* FakeChromeUserManager::GetActiveUser() const { |
| + return GetActiveUserInternal(); |
| +} |
| + |
| +user_manager::User* FakeChromeUserManager::GetActiveUser() { |
| + return GetActiveUserInternal(); |
| +} |
| + |
| +const user_manager::User* FakeChromeUserManager::GetPrimaryUser() const { |
| + return primary_user_; |
| +} |
| + |
| +void FakeChromeUserManager::SaveUserOAuthStatus( |
| + const AccountId& account_id, |
| + user_manager::User::OAuthTokenStatus oauth_token_status) { |
| + NOTREACHED(); |
| +} |
| + |
| +void FakeChromeUserManager::SaveForceOnlineSignin(const AccountId& account_id, |
| + bool force_online_signin) { |
| + NOTREACHED(); |
| +} |
| + |
| +void FakeChromeUserManager::SaveUserDisplayName( |
| + const AccountId& account_id, |
| + const base::string16& display_name) { |
| + for (user_manager::UserList::iterator it = users_.begin(); it != users_.end(); |
|
achuithb
2016/11/15 20:13:28
range loop
yoshiki
2016/11/16 15:50:19
Done.
|
| + ++it) { |
| + if ((*it)->GetAccountId() == account_id) { |
| + (*it)->set_display_name(display_name); |
| + return; |
| + } |
| + } |
| +} |
| + |
| +base::string16 FakeChromeUserManager::GetUserDisplayName( |
| + const AccountId& account_id) const { |
| + return base::string16(); |
| +} |
| + |
| +void FakeChromeUserManager::SaveUserDisplayEmail( |
| + const AccountId& account_id, |
| + const std::string& display_email) { |
| + NOTREACHED(); |
| +} |
| + |
| +std::string FakeChromeUserManager::GetUserDisplayEmail( |
| + const AccountId& account_id) const { |
| + return std::string(); |
| +} |
| + |
| +void FakeChromeUserManager::SaveUserType( |
| + const AccountId& account_id, |
| + const user_manager::UserType& user_type) { |
| + NOTREACHED(); |
| +} |
| + |
| +void FakeChromeUserManager::UpdateUserAccountData( |
| + const AccountId& account_id, |
| + const UserAccountData& account_data) { |
| + NOTREACHED(); |
| +} |
| + |
| +bool FakeChromeUserManager::IsCurrentUserOwner() const { |
| + return false; |
| +} |
| + |
| +bool FakeChromeUserManager::IsCurrentUserNew() const { |
| + return false; |
| +} |
| + |
| +bool FakeChromeUserManager::IsCurrentUserNonCryptohomeDataEphemeral() const { |
| + return false; |
| +} |
| + |
| +bool FakeChromeUserManager::CanCurrentUserLock() const { |
| + return false; |
| +} |
| + |
| +bool FakeChromeUserManager::IsUserLoggedIn() const { |
| + return logged_in_users_.size() > 0; |
| +} |
| + |
| +bool FakeChromeUserManager::IsLoggedInAsUserWithGaiaAccount() const { |
| + return true; |
| +} |
| + |
| +bool FakeChromeUserManager::IsLoggedInAsChildUser() const { |
| + NOTREACHED(); |
| + return false; |
| +} |
| + |
| +bool FakeChromeUserManager::IsLoggedInAsPublicAccount() const { |
| + return false; |
| +} |
| + |
| +bool FakeChromeUserManager::IsLoggedInAsGuest() const { |
| + return false; |
| +} |
| + |
| +bool FakeChromeUserManager::IsLoggedInAsSupervisedUser() const { |
| + return false; |
| +} |
| + |
| +bool FakeChromeUserManager::IsLoggedInAsKioskApp() const { |
| + const user_manager::User* active_user = GetActiveUser(); |
| + return active_user |
| + ? active_user->GetType() == user_manager::USER_TYPE_KIOSK_APP |
| + : false; |
| +} |
| + |
| +bool FakeChromeUserManager::IsLoggedInAsArcKioskApp() const { |
| + const user_manager::User* active_user = GetActiveUser(); |
| + return active_user |
| + ? active_user->GetType() == user_manager::USER_TYPE_ARC_KIOSK_APP |
| + : false; |
| +} |
| + |
| +bool FakeChromeUserManager::IsLoggedInAsStub() const { |
| + return false; |
| +} |
| + |
| +bool FakeChromeUserManager::IsUserNonCryptohomeDataEphemeral( |
| + const AccountId& account_id) const { |
| + return false; |
| +} |
| + |
| +void FakeChromeUserManager::AddObserver(UserManager::Observer* obs) { |
| + NOTREACHED(); |
| +} |
| + |
| +void FakeChromeUserManager::RemoveObserver(UserManager::Observer* obs) { |
| + NOTREACHED(); |
| +} |
| + |
| +void FakeChromeUserManager::AddSessionStateObserver( |
| + UserManager::UserSessionStateObserver* obs) {} |
| + |
| +void FakeChromeUserManager::RemoveSessionStateObserver( |
| + UserManager::UserSessionStateObserver* obs) {} |
| + |
| +void FakeChromeUserManager::NotifyLocalStateChanged() { |
| + NOTREACHED(); |
| +} |
| + |
| +void FakeChromeUserManager::ChangeUserChildStatus(user_manager::User* user, |
| + bool is_child) { |
| + NOTREACHED(); |
| +} |
| + |
| +bool FakeChromeUserManager::AreSupervisedUsersAllowed() const { |
| + return true; |
| +} |
| + |
| +PrefService* FakeChromeUserManager::GetLocalState() const { |
| + return nullptr; |
| +} |
| + |
| +void FakeChromeUserManager::SetIsCurrentUserNew(bool is_new) { |
| + NOTREACHED(); |
| +} |
| + |
| +const std::string& FakeChromeUserManager::GetApplicationLocale() const { |
| + static const std::string default_locale("en-US"); |
| + return default_locale; |
| +} |
| + |
| +void FakeChromeUserManager::HandleUserOAuthTokenStatusChange( |
| + const AccountId& account_id, |
| + user_manager::User::OAuthTokenStatus status) const { |
| + NOTREACHED(); |
| +} |
| + |
| +void FakeChromeUserManager::LoadDeviceLocalAccounts( |
| + std::set<AccountId>* users_set) { |
| + NOTREACHED(); |
| +} |
| + |
| +bool FakeChromeUserManager::IsEnterpriseManaged() const { |
| + return false; |
| +} |
| + |
| +void FakeChromeUserManager::PerformPreUserListLoadingActions() { |
| + NOTREACHED(); |
| +} |
| + |
| +void FakeChromeUserManager::PerformPostUserListLoadingActions() { |
| + NOTREACHED(); |
| +} |
| + |
| +void FakeChromeUserManager::PerformPostUserLoggedInActions( |
| + bool browser_restart) { |
| + NOTREACHED(); |
| +} |
| + |
| +bool FakeChromeUserManager::IsDemoApp(const AccountId& account_id) const { |
| + return account_id == user_manager::DemoAccountId(); |
| +} |
| + |
| +bool FakeChromeUserManager::IsDeviceLocalAccountMarkedForRemoval( |
| + const AccountId& account_id) const { |
| + return false; |
| +} |
| + |
| +void FakeChromeUserManager::DemoAccountLoggedIn() { |
| + NOTREACHED(); |
| +} |
| + |
| +void FakeChromeUserManager::KioskAppLoggedIn(user_manager::User* user) {} |
| + |
| +void FakeChromeUserManager::PublicAccountUserLoggedIn( |
| + user_manager::User* user) { |
| + NOTREACHED(); |
| +} |
| + |
| +void FakeChromeUserManager::SupervisedUserLoggedIn( |
| + const AccountId& account_id) { |
| + NOTREACHED(); |
| +} |
| + |
| +void FakeChromeUserManager::OnUserRemoved(const AccountId& account_id) { |
| + NOTREACHED(); |
| +} |
| + |
| +void FakeChromeUserManager::SetUserAffiliation( |
| + const std::string& user_email, |
| + const AffiliationIDSet& user_affiliation_ids) {} |
| + |
| +bool FakeChromeUserManager::ShouldReportUser(const std::string& user_id) const { |
| + return false; |
| +} |
| + |
| +user_manager::User* FakeChromeUserManager::GetActiveUserInternal() const { |
| + if (active_user_ != nullptr) |
| + return active_user_; |
| + |
| + if (!users_.empty()) { |
|
achuithb
2016/11/15 20:13:28
Early return seems preferable here rather than nes
yoshiki
2016/11/16 15:50:19
Done.
|
| + if (active_account_id_.is_valid()) { |
| + for (user_manager::UserList::const_iterator it = users_.begin(); |
|
achuithb
2016/11/15 20:13:28
range loop
yoshiki
2016/11/16 15:50:19
Done.
|
| + it != users_.end(); ++it) { |
| + if ((*it)->GetAccountId() == active_account_id_) |
| + return *it; |
| + } |
| + } |
| + return users_[0]; |
| + } |
| + return nullptr; |
| +} |
| + |
| } // namespace chromeos |