| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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/fake_user_manager.h" | |
| 6 | |
| 7 #include "chrome/browser/chromeos/login/fake_supervised_user_manager.h" | |
| 8 | |
| 9 namespace { | |
| 10 | |
| 11 // As defined in /chromeos/dbus/cryptohome_client.cc. | |
| 12 static const char kUserIdHashSuffix[] = "-hash"; | |
| 13 | |
| 14 } // namespace | |
| 15 | |
| 16 namespace chromeos { | |
| 17 | |
| 18 FakeUserManager::FakeUserManager() | |
| 19 : supervised_user_manager_(new FakeSupervisedUserManager), | |
| 20 primary_user_(NULL) {} | |
| 21 | |
| 22 FakeUserManager::~FakeUserManager() { | |
| 23 // Can't use STLDeleteElements because of the private destructor of User. | |
| 24 for (UserList::iterator it = user_list_.begin(); it != user_list_.end(); | |
| 25 it = user_list_.erase(it)) { | |
| 26 delete *it; | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 const User* FakeUserManager::AddUser(const std::string& email) { | |
| 31 User* user = User::CreateRegularUser(email); | |
| 32 user->set_username_hash(email + kUserIdHashSuffix); | |
| 33 user->SetStubImage(User::kProfileImageIndex, false); | |
| 34 user_list_.push_back(user); | |
| 35 return user; | |
| 36 } | |
| 37 | |
| 38 void FakeUserManager::AddKioskAppUser(const std::string& kiosk_app_username) { | |
| 39 User* user = User::CreateKioskAppUser(kiosk_app_username); | |
| 40 user->set_username_hash(kiosk_app_username + kUserIdHashSuffix); | |
| 41 user_list_.push_back(user); | |
| 42 } | |
| 43 | |
| 44 void FakeUserManager::LoginUser(const std::string& email) { | |
| 45 UserLoggedIn(email, email + kUserIdHashSuffix, false); | |
| 46 } | |
| 47 | |
| 48 void FakeUserManager::SetProfileForUser(const User* user, Profile* profile) { | |
| 49 user_to_profile_[user] = profile; | |
| 50 } | |
| 51 | |
| 52 const UserList& FakeUserManager::GetUsers() const { | |
| 53 return user_list_; | |
| 54 } | |
| 55 | |
| 56 UserList FakeUserManager::GetUsersAdmittedForMultiProfile() const { | |
| 57 UserList result; | |
| 58 for (UserList::const_iterator it = user_list_.begin(); | |
| 59 it != user_list_.end(); | |
| 60 ++it) { | |
| 61 if ((*it)->GetType() == User::USER_TYPE_REGULAR && !(*it)->is_logged_in()) | |
| 62 result.push_back(*it); | |
| 63 } | |
| 64 return result; | |
| 65 } | |
| 66 | |
| 67 const UserList& FakeUserManager::GetLoggedInUsers() const { | |
| 68 return logged_in_users_; | |
| 69 } | |
| 70 | |
| 71 void FakeUserManager::UserLoggedIn(const std::string& email, | |
| 72 const std::string& username_hash, | |
| 73 bool browser_restart) { | |
| 74 for (UserList::const_iterator it = user_list_.begin(); | |
| 75 it != user_list_.end(); | |
| 76 ++it) { | |
| 77 if ((*it)->username_hash() == username_hash) { | |
| 78 (*it)->set_is_logged_in(true); | |
| 79 logged_in_users_.push_back(*it); | |
| 80 | |
| 81 if (!primary_user_) | |
| 82 primary_user_ = *it; | |
| 83 break; | |
| 84 } | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 User* FakeUserManager::GetActiveUserInternal() const { | |
| 89 if (user_list_.size()) { | |
| 90 if (!active_user_id_.empty()) { | |
| 91 for (UserList::const_iterator it = user_list_.begin(); | |
| 92 it != user_list_.end(); ++it) { | |
| 93 if ((*it)->email() == active_user_id_) | |
| 94 return *it; | |
| 95 } | |
| 96 } | |
| 97 return user_list_[0]; | |
| 98 } | |
| 99 return NULL; | |
| 100 } | |
| 101 | |
| 102 const User* FakeUserManager::GetActiveUser() const { | |
| 103 return GetActiveUserInternal(); | |
| 104 } | |
| 105 | |
| 106 User* FakeUserManager::GetActiveUser() { | |
| 107 return GetActiveUserInternal(); | |
| 108 } | |
| 109 | |
| 110 void FakeUserManager::SwitchActiveUser(const std::string& email) { | |
| 111 active_user_id_ = email; | |
| 112 } | |
| 113 | |
| 114 void FakeUserManager::SaveUserDisplayName( | |
| 115 const std::string& username, | |
| 116 const base::string16& display_name) { | |
| 117 for (UserList::iterator it = user_list_.begin(); | |
| 118 it != user_list_.end(); ++it) { | |
| 119 if ((*it)->email() == username) { | |
| 120 (*it)->set_display_name(display_name); | |
| 121 return; | |
| 122 } | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 MultiProfileUserController* FakeUserManager::GetMultiProfileUserController() { | |
| 127 return NULL; | |
| 128 } | |
| 129 | |
| 130 SupervisedUserManager* FakeUserManager::GetSupervisedUserManager() { | |
| 131 return supervised_user_manager_.get(); | |
| 132 } | |
| 133 | |
| 134 UserImageManager* FakeUserManager::GetUserImageManager( | |
| 135 const std::string& /* user_id */) { | |
| 136 return NULL; | |
| 137 } | |
| 138 | |
| 139 const UserList& FakeUserManager::GetLRULoggedInUsers() { | |
| 140 return user_list_; | |
| 141 } | |
| 142 | |
| 143 UserList FakeUserManager::GetUnlockUsers() const { | |
| 144 return user_list_; | |
| 145 } | |
| 146 | |
| 147 const std::string& FakeUserManager::GetOwnerEmail() { | |
| 148 return owner_email_; | |
| 149 } | |
| 150 | |
| 151 bool FakeUserManager::IsKnownUser(const std::string& email) const { | |
| 152 return true; | |
| 153 } | |
| 154 | |
| 155 const User* FakeUserManager::FindUser(const std::string& email) const { | |
| 156 return NULL; | |
| 157 } | |
| 158 | |
| 159 User* FakeUserManager::FindUserAndModify(const std::string& email) { | |
| 160 return NULL; | |
| 161 } | |
| 162 | |
| 163 const User* FakeUserManager::GetLoggedInUser() const { | |
| 164 return NULL; | |
| 165 } | |
| 166 | |
| 167 User* FakeUserManager::GetLoggedInUser() { | |
| 168 return NULL; | |
| 169 } | |
| 170 | |
| 171 const User* FakeUserManager::GetPrimaryUser() const { | |
| 172 return primary_user_; | |
| 173 } | |
| 174 | |
| 175 User* FakeUserManager::GetUserByProfile(Profile* profile) const { | |
| 176 const std::string& user_name = profile->GetProfileName(); | |
| 177 for (UserList::const_iterator it = user_list_.begin(); | |
| 178 it != user_list_.end(); ++it) { | |
| 179 if ((*it)->email() == user_name) | |
| 180 return *it; | |
| 181 } | |
| 182 return primary_user_; | |
| 183 } | |
| 184 | |
| 185 Profile* FakeUserManager::GetProfileByUser(const User* user) const { | |
| 186 std::map<const User*, Profile*>::const_iterator it = | |
| 187 user_to_profile_.find(user); | |
| 188 return it == user_to_profile_.end() ? NULL : it->second; | |
| 189 } | |
| 190 | |
| 191 base::string16 FakeUserManager::GetUserDisplayName( | |
| 192 const std::string& username) const { | |
| 193 return base::string16(); | |
| 194 } | |
| 195 | |
| 196 std::string FakeUserManager::GetUserDisplayEmail( | |
| 197 const std::string& username) const { | |
| 198 return std::string(); | |
| 199 } | |
| 200 | |
| 201 bool FakeUserManager::IsCurrentUserOwner() const { | |
| 202 return false; | |
| 203 } | |
| 204 | |
| 205 bool FakeUserManager::IsCurrentUserNew() const { | |
| 206 return false; | |
| 207 } | |
| 208 | |
| 209 bool FakeUserManager::IsCurrentUserNonCryptohomeDataEphemeral() const { | |
| 210 return false; | |
| 211 } | |
| 212 | |
| 213 bool FakeUserManager::CanCurrentUserLock() const { | |
| 214 return false; | |
| 215 } | |
| 216 | |
| 217 bool FakeUserManager::IsUserLoggedIn() const { | |
| 218 return logged_in_users_.size() > 0; | |
| 219 } | |
| 220 | |
| 221 bool FakeUserManager::IsLoggedInAsRegularUser() const { | |
| 222 return true; | |
| 223 } | |
| 224 | |
| 225 bool FakeUserManager::IsLoggedInAsDemoUser() const { | |
| 226 return false; | |
| 227 } | |
| 228 | |
| 229 bool FakeUserManager::IsLoggedInAsPublicAccount() const { | |
| 230 return false; | |
| 231 } | |
| 232 | |
| 233 bool FakeUserManager::IsLoggedInAsGuest() const { | |
| 234 return false; | |
| 235 } | |
| 236 | |
| 237 bool FakeUserManager::IsLoggedInAsLocallyManagedUser() const { | |
| 238 return false; | |
| 239 } | |
| 240 | |
| 241 bool FakeUserManager::IsLoggedInAsKioskApp() const { | |
| 242 const User* active_user = GetActiveUser(); | |
| 243 return active_user ? | |
| 244 active_user->GetType() == User::USER_TYPE_KIOSK_APP : | |
| 245 false; | |
| 246 } | |
| 247 | |
| 248 bool FakeUserManager::IsLoggedInAsStub() const { | |
| 249 return false; | |
| 250 } | |
| 251 | |
| 252 bool FakeUserManager::IsSessionStarted() const { | |
| 253 return false; | |
| 254 } | |
| 255 | |
| 256 bool FakeUserManager::UserSessionsRestored() const { | |
| 257 return false; | |
| 258 } | |
| 259 | |
| 260 bool FakeUserManager::HasBrowserRestarted() const { | |
| 261 return false; | |
| 262 } | |
| 263 | |
| 264 bool FakeUserManager::IsUserNonCryptohomeDataEphemeral( | |
| 265 const std::string& email) const { | |
| 266 return false; | |
| 267 } | |
| 268 | |
| 269 UserFlow* FakeUserManager::GetCurrentUserFlow() const { | |
| 270 return NULL; | |
| 271 } | |
| 272 | |
| 273 UserFlow* FakeUserManager::GetUserFlow(const std::string& email) const { | |
| 274 return NULL; | |
| 275 } | |
| 276 | |
| 277 bool FakeUserManager::GetAppModeChromeClientOAuthInfo( | |
| 278 std::string* chrome_client_id, | |
| 279 std::string* chrome_client_secret) { | |
| 280 return false; | |
| 281 } | |
| 282 | |
| 283 bool FakeUserManager::AreLocallyManagedUsersAllowed() const { | |
| 284 return true; | |
| 285 } | |
| 286 | |
| 287 base::FilePath FakeUserManager::GetUserProfileDir( | |
| 288 const std::string&email) const { | |
| 289 return base::FilePath(); | |
| 290 } | |
| 291 | |
| 292 bool FakeUserManager::RespectLocalePreference( | |
| 293 Profile* profile, | |
| 294 const User* user, | |
| 295 scoped_ptr<locale_util::SwitchLanguageCallback> callback) const { | |
| 296 return false; | |
| 297 } | |
| 298 | |
| 299 } // namespace chromeos | |
| OLD | NEW |