| 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 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 5 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 7 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| 8 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h" | 8 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h" |
| 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 10 #include "chrome/browser/chromeos/settings/cros_settings.h" | 10 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 11 #include "chrome/grit/theme_resources.h" | 11 #include "chrome/grit/theme_resources.h" |
| 12 #include "components/user_manager/user_image/user_image.h" | 12 #include "components/user_manager/user_image/user_image.h" |
| 13 #include "components/user_manager/user_type.h" | 13 #include "components/user_manager/user_type.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 15 | 15 |
| 16 namespace chromeos { | 16 namespace chromeos { |
| 17 | 17 |
| 18 class FakeSupervisedUserManager; | 18 class FakeSupervisedUserManager; |
| 19 | 19 |
| 20 FakeChromeUserManager::FakeChromeUserManager() | 20 FakeChromeUserManager::FakeChromeUserManager() |
| 21 : supervised_user_manager_(new FakeSupervisedUserManager), | 21 : supervised_user_manager_(new FakeSupervisedUserManager), |
| 22 bootstrap_manager_(NULL), | 22 bootstrap_manager_(NULL), |
| 23 multi_profile_user_controller_(NULL) { | 23 multi_profile_user_controller_(NULL) {} |
| 24 } | |
| 25 | 24 |
| 26 FakeChromeUserManager::~FakeChromeUserManager() { | 25 FakeChromeUserManager::~FakeChromeUserManager() { |
| 27 } | 26 } |
| 28 | 27 |
| 29 const user_manager::User* FakeChromeUserManager::AddUser( | 28 const user_manager::User* FakeChromeUserManager::AddUser( |
| 30 const std::string& email) { | 29 const AccountId& account_id) { |
| 31 return AddUserWithAffiliation(email, false); | 30 return AddUserWithAffiliation(account_id, false); |
| 32 } | 31 } |
| 33 | 32 |
| 34 const user_manager::User* FakeChromeUserManager::AddUserWithAffiliation( | 33 const user_manager::User* FakeChromeUserManager::AddUserWithAffiliation( |
| 35 const std::string& email, | 34 const AccountId& account_id, |
| 36 bool is_affiliated) { | 35 bool is_affiliated) { |
| 37 user_manager::User* user = user_manager::User::CreateRegularUser(email); | 36 user_manager::User* user = user_manager::User::CreateRegularUser(account_id); |
| 38 user->set_affiliation(is_affiliated); | 37 user->set_affiliation(is_affiliated); |
| 39 user->set_username_hash( | 38 user->set_username_hash(ProfileHelper::GetUserIdHashByUserIdForTesting( |
| 40 ProfileHelper::GetUserIdHashByUserIdForTesting(email)); | 39 account_id.GetUserEmail())); |
| 41 user->SetStubImage(user_manager::UserImage( | 40 user->SetStubImage(user_manager::UserImage( |
| 42 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 41 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 43 IDR_PROFILE_PICTURE_LOADING)), | 42 IDR_PROFILE_PICTURE_LOADING)), |
| 44 user_manager::User::USER_IMAGE_PROFILE, false); | 43 user_manager::User::USER_IMAGE_PROFILE, false); |
| 45 users_.push_back(user); | 44 users_.push_back(user); |
| 46 return user; | 45 return user; |
| 47 } | 46 } |
| 48 | 47 |
| 49 const user_manager::User* FakeChromeUserManager::AddPublicAccountUser( | 48 const user_manager::User* FakeChromeUserManager::AddPublicAccountUser( |
| 50 const std::string& email) { | 49 const AccountId& account_id) { |
| 51 user_manager::User* user = user_manager::User::CreatePublicAccountUser(email); | 50 user_manager::User* user = |
| 52 user->set_username_hash( | 51 user_manager::User::CreatePublicAccountUser(account_id); |
| 53 ProfileHelper::GetUserIdHashByUserIdForTesting(email)); | 52 user->set_username_hash(ProfileHelper::GetUserIdHashByUserIdForTesting( |
| 53 account_id.GetUserEmail())); |
| 54 user->SetStubImage(user_manager::UserImage( | 54 user->SetStubImage(user_manager::UserImage( |
| 55 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 55 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 56 IDR_PROFILE_PICTURE_LOADING)), | 56 IDR_PROFILE_PICTURE_LOADING)), |
| 57 user_manager::User::USER_IMAGE_PROFILE, false); | 57 user_manager::User::USER_IMAGE_PROFILE, false); |
| 58 users_.push_back(user); | 58 users_.push_back(user); |
| 59 return user; | 59 return user; |
| 60 } | 60 } |
| 61 | 61 |
| 62 void FakeChromeUserManager::AddKioskAppUser( | 62 void FakeChromeUserManager::AddKioskAppUser( |
| 63 const std::string& kiosk_app_username) { | 63 const AccountId& kiosk_app_account_id) { |
| 64 user_manager::User* user = | 64 user_manager::User* user = |
| 65 user_manager::User::CreateKioskAppUser(kiosk_app_username); | 65 user_manager::User::CreateKioskAppUser(kiosk_app_account_id); |
| 66 user->set_username_hash( | 66 user->set_username_hash(ProfileHelper::GetUserIdHashByUserIdForTesting( |
| 67 ProfileHelper::GetUserIdHashByUserIdForTesting(kiosk_app_username)); | 67 kiosk_app_account_id.GetUserEmail())); |
| 68 users_.push_back(user); | 68 users_.push_back(user); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void FakeChromeUserManager::LoginUser(const std::string& email) { | 71 void FakeChromeUserManager::LoginUser(const AccountId& account_id) { |
| 72 UserLoggedIn(email, ProfileHelper::GetUserIdHashByUserIdForTesting(email), | 72 UserLoggedIn(account_id, ProfileHelper::GetUserIdHashByUserIdForTesting( |
| 73 account_id.GetUserEmail()), |
| 73 false /* browser_restart */); | 74 false /* browser_restart */); |
| 74 } | 75 } |
| 75 | 76 |
| 76 BootstrapManager* FakeChromeUserManager::GetBootstrapManager() { | 77 BootstrapManager* FakeChromeUserManager::GetBootstrapManager() { |
| 77 return bootstrap_manager_; | 78 return bootstrap_manager_; |
| 78 } | 79 } |
| 79 | 80 |
| 80 MultiProfileUserController* | 81 MultiProfileUserController* |
| 81 FakeChromeUserManager::GetMultiProfileUserController() { | 82 FakeChromeUserManager::GetMultiProfileUserController() { |
| 82 return multi_profile_user_controller_; | 83 return multi_profile_user_controller_; |
| 83 } | 84 } |
| 84 | 85 |
| 85 SupervisedUserManager* FakeChromeUserManager::GetSupervisedUserManager() { | 86 SupervisedUserManager* FakeChromeUserManager::GetSupervisedUserManager() { |
| 86 return supervised_user_manager_.get(); | 87 return supervised_user_manager_.get(); |
| 87 } | 88 } |
| 88 | 89 |
| 89 UserImageManager* FakeChromeUserManager::GetUserImageManager( | 90 UserImageManager* FakeChromeUserManager::GetUserImageManager( |
| 90 const std::string& /* user_id */) { | 91 const AccountId& /* account_id */) { |
| 91 return nullptr; | 92 return nullptr; |
| 92 } | 93 } |
| 93 | 94 |
| 94 void FakeChromeUserManager::SetUserFlow(const std::string& email, | 95 void FakeChromeUserManager::SetUserFlow(const AccountId& account_id, |
| 95 UserFlow* flow) { | 96 UserFlow* flow) { |
| 96 ResetUserFlow(email); | 97 ResetUserFlow(account_id); |
| 97 specific_flows_[email] = flow; | 98 specific_flows_[account_id] = flow; |
| 98 } | 99 } |
| 99 | 100 |
| 100 UserFlow* FakeChromeUserManager::GetCurrentUserFlow() const { | 101 UserFlow* FakeChromeUserManager::GetCurrentUserFlow() const { |
| 101 if (!IsUserLoggedIn()) | 102 if (!IsUserLoggedIn()) |
| 102 return GetDefaultUserFlow(); | 103 return GetDefaultUserFlow(); |
| 103 return GetUserFlow(GetLoggedInUser()->email()); | 104 return GetUserFlow(GetLoggedInUser()->GetAccountId()); |
| 104 } | 105 } |
| 105 | 106 |
| 106 UserFlow* FakeChromeUserManager::GetUserFlow(const std::string& email) const { | 107 UserFlow* FakeChromeUserManager::GetUserFlow( |
| 107 FlowMap::const_iterator it = specific_flows_.find(email); | 108 const AccountId& account_id) const { |
| 109 FlowMap::const_iterator it = specific_flows_.find(account_id); |
| 108 if (it != specific_flows_.end()) | 110 if (it != specific_flows_.end()) |
| 109 return it->second; | 111 return it->second; |
| 110 return GetDefaultUserFlow(); | 112 return GetDefaultUserFlow(); |
| 111 } | 113 } |
| 112 | 114 |
| 113 void FakeChromeUserManager::ResetUserFlow(const std::string& email) { | 115 void FakeChromeUserManager::ResetUserFlow(const AccountId& account_id) { |
| 114 FlowMap::iterator it = specific_flows_.find(email); | 116 FlowMap::iterator it = specific_flows_.find(account_id); |
| 115 if (it != specific_flows_.end()) { | 117 if (it != specific_flows_.end()) { |
| 116 delete it->second; | 118 delete it->second; |
| 117 specific_flows_.erase(it); | 119 specific_flows_.erase(it); |
| 118 } | 120 } |
| 119 } | 121 } |
| 120 | 122 |
| 121 void FakeChromeUserManager::SwitchActiveUser(const std::string& email) { | 123 void FakeChromeUserManager::SwitchActiveUser(const AccountId& account_id) { |
| 122 active_user_id_ = email; | 124 active_account_id_ = account_id; |
| 123 ProfileHelper::Get()->ActiveUserHashChanged( | 125 ProfileHelper::Get()->ActiveUserHashChanged( |
| 124 ProfileHelper::GetUserIdHashByUserIdForTesting(email)); | 126 ProfileHelper::GetUserIdHashByUserIdForTesting( |
| 125 if (!users_.empty() && !active_user_id_.empty()) { | 127 account_id.GetUserEmail())); |
| 128 if (!users_.empty() && active_account_id_.is_valid()) { |
| 126 for (user_manager::User* user : users_) | 129 for (user_manager::User* user : users_) |
| 127 user->set_is_active(user->email() == active_user_id_); | 130 user->set_is_active(user->GetAccountId() == active_account_id_); |
| 128 } | 131 } |
| 129 } | 132 } |
| 130 | 133 |
| 131 const std::string& FakeChromeUserManager::GetOwnerEmail() const { | 134 const AccountId& FakeChromeUserManager::GetOwnerAccountId() const { |
| 132 return owner_email_; | 135 return owner_account_id_; |
| 133 } | 136 } |
| 134 | 137 |
| 135 void FakeChromeUserManager::SessionStarted() { | 138 void FakeChromeUserManager::SessionStarted() { |
| 136 } | 139 } |
| 137 | 140 |
| 138 void FakeChromeUserManager::RemoveUser( | 141 void FakeChromeUserManager::RemoveUser( |
| 139 const std::string& email, | 142 const AccountId& account_id, |
| 140 user_manager::RemoveUserDelegate* delegate) { | 143 user_manager::RemoveUserDelegate* delegate) {} |
| 141 } | |
| 142 | 144 |
| 143 user_manager::UserList | 145 user_manager::UserList |
| 144 FakeChromeUserManager::GetUsersAllowedForSupervisedUsersCreation() const { | 146 FakeChromeUserManager::GetUsersAllowedForSupervisedUsersCreation() const { |
| 145 CrosSettings* cros_settings = CrosSettings::Get(); | 147 CrosSettings* cros_settings = CrosSettings::Get(); |
| 146 bool allow_new_user = true; | 148 bool allow_new_user = true; |
| 147 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 149 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
| 148 bool supervised_users_allowed = AreSupervisedUsersAllowed(); | 150 bool supervised_users_allowed = AreSupervisedUsersAllowed(); |
| 149 | 151 |
| 150 // Restricted either by policy or by owner. | 152 // Restricted either by policy or by owner. |
| 151 if (!allow_new_user || !supervised_users_allowed) | 153 if (!allow_new_user || !supervised_users_allowed) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 174 return result; | 176 return result; |
| 175 } | 177 } |
| 176 | 178 |
| 177 UserFlow* FakeChromeUserManager::GetDefaultUserFlow() const { | 179 UserFlow* FakeChromeUserManager::GetDefaultUserFlow() const { |
| 178 if (!default_flow_.get()) | 180 if (!default_flow_.get()) |
| 179 default_flow_.reset(new DefaultUserFlow()); | 181 default_flow_.reset(new DefaultUserFlow()); |
| 180 return default_flow_.get(); | 182 return default_flow_.get(); |
| 181 } | 183 } |
| 182 | 184 |
| 183 bool FakeChromeUserManager::FindKnownUserPrefs( | 185 bool FakeChromeUserManager::FindKnownUserPrefs( |
| 184 const user_manager::UserID& user_id, | 186 const AccountId& account_id, |
| 185 const base::DictionaryValue** out_value) { | 187 const base::DictionaryValue** out_value) { |
| 186 return false; | 188 return false; |
| 187 } | 189 } |
| 188 | 190 |
| 189 void FakeChromeUserManager::UpdateKnownUserPrefs( | 191 void FakeChromeUserManager::UpdateKnownUserPrefs( |
| 190 const user_manager::UserID& user_id, | 192 const AccountId& account_id, |
| 191 const base::DictionaryValue& values, | 193 const base::DictionaryValue& values, |
| 192 bool clear) { | 194 bool clear) {} |
| 193 } | |
| 194 | 195 |
| 195 } // namespace chromeos | 196 } // namespace chromeos |
| OLD | NEW |