Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / fake_user_manager.cc
blob34f3248b67d60b9bb00c21d687c4132358d0b584
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.
5 #include "chrome/browser/chromeos/login/fake_user_manager.h"
7 #include "chrome/browser/chromeos/login/fake_supervised_user_manager.h"
9 namespace {
11 // As defined in /chromeos/dbus/cryptohome_client.cc.
12 static const char kUserIdHashSuffix[] = "-hash";
14 } // namespace
16 namespace chromeos {
18 FakeUserManager::FakeUserManager()
19 : supervised_user_manager_(new FakeSupervisedUserManager),
20 primary_user_(NULL) {}
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;
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;
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);
44 void FakeUserManager::LoginUser(const std::string& email) {
45 UserLoggedIn(email, email + kUserIdHashSuffix, false);
48 void FakeUserManager::SetProfileForUser(const User* user, Profile* profile) {
49 user_to_profile_[user] = profile;
52 const UserList& FakeUserManager::GetUsers() const {
53 return user_list_;
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);
64 return result;
67 const UserList& FakeUserManager::GetLoggedInUsers() const {
68 return logged_in_users_;
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);
81 if (!primary_user_)
82 primary_user_ = *it;
83 break;
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;
97 return user_list_[0];
99 return NULL;
102 const User* FakeUserManager::GetActiveUser() const {
103 return GetActiveUserInternal();
106 User* FakeUserManager::GetActiveUser() {
107 return GetActiveUserInternal();
110 void FakeUserManager::SwitchActiveUser(const std::string& email) {
111 active_user_id_ = email;
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;
126 SupervisedUserManager* FakeUserManager::GetSupervisedUserManager() {
127 return supervised_user_manager_.get();
130 UserImageManager* FakeUserManager::GetUserImageManager(
131 const std::string& /* user_id */) {
132 return NULL;
135 const UserList& FakeUserManager::GetLRULoggedInUsers() {
136 return user_list_;
139 UserList FakeUserManager::GetUnlockUsers() const {
140 return user_list_;
143 const std::string& FakeUserManager::GetOwnerEmail() {
144 return owner_email_;
147 bool FakeUserManager::IsKnownUser(const std::string& email) const {
148 return true;
151 const User* FakeUserManager::FindUser(const std::string& email) const {
152 return NULL;
155 User* FakeUserManager::FindUserAndModify(const std::string& email) {
156 return NULL;
159 const User* FakeUserManager::GetLoggedInUser() const {
160 return NULL;
163 User* FakeUserManager::GetLoggedInUser() {
164 return NULL;
167 const User* FakeUserManager::GetPrimaryUser() const {
168 return primary_user_;
171 User* FakeUserManager::GetUserByProfile(Profile* profile) const {
172 const std::string& user_name = profile->GetProfileName();
173 for (UserList::const_iterator it = user_list_.begin();
174 it != user_list_.end(); ++it) {
175 if ((*it)->email() == user_name)
176 return *it;
178 return primary_user_;
181 Profile* FakeUserManager::GetProfileByUser(const User* user) const {
182 std::map<const User*, Profile*>::const_iterator it =
183 user_to_profile_.find(user);
184 return it == user_to_profile_.end() ? NULL : it->second;
187 base::string16 FakeUserManager::GetUserDisplayName(
188 const std::string& username) const {
189 return base::string16();
192 std::string FakeUserManager::GetUserDisplayEmail(
193 const std::string& username) const {
194 return std::string();
197 bool FakeUserManager::IsCurrentUserOwner() const {
198 return false;
201 bool FakeUserManager::IsCurrentUserNew() const {
202 return false;
205 bool FakeUserManager::IsCurrentUserNonCryptohomeDataEphemeral() const {
206 return false;
209 bool FakeUserManager::CanCurrentUserLock() const {
210 return false;
213 bool FakeUserManager::IsUserLoggedIn() const {
214 return logged_in_users_.size() > 0;
217 bool FakeUserManager::IsLoggedInAsRegularUser() const {
218 return true;
221 bool FakeUserManager::IsLoggedInAsDemoUser() const {
222 return false;
225 bool FakeUserManager::IsLoggedInAsPublicAccount() const {
226 return false;
229 bool FakeUserManager::IsLoggedInAsGuest() const {
230 return false;
233 bool FakeUserManager::IsLoggedInAsLocallyManagedUser() const {
234 return false;
237 bool FakeUserManager::IsLoggedInAsKioskApp() const {
238 const User* active_user = GetActiveUser();
239 return active_user ?
240 active_user->GetType() == User::USER_TYPE_KIOSK_APP :
241 false;
244 bool FakeUserManager::IsLoggedInAsStub() const {
245 return false;
248 bool FakeUserManager::IsSessionStarted() const {
249 return false;
252 bool FakeUserManager::UserSessionsRestored() const {
253 return false;
256 bool FakeUserManager::HasBrowserRestarted() const {
257 return false;
260 bool FakeUserManager::IsUserNonCryptohomeDataEphemeral(
261 const std::string& email) const {
262 return false;
265 UserFlow* FakeUserManager::GetCurrentUserFlow() const {
266 return NULL;
269 UserFlow* FakeUserManager::GetUserFlow(const std::string& email) const {
270 return NULL;
273 bool FakeUserManager::GetAppModeChromeClientOAuthInfo(
274 std::string* chrome_client_id,
275 std::string* chrome_client_secret) {
276 return false;
279 bool FakeUserManager::AreLocallyManagedUsersAllowed() const {
280 return true;
283 base::FilePath FakeUserManager::GetUserProfileDir(
284 const std::string&email) const {
285 return base::FilePath();
288 bool FakeUserManager::RespectLocalePreference(
289 Profile* profile,
290 const User* user,
291 scoped_ptr<locale_util::SwitchLanguageCallback> callback) const {
292 return false;
295 } // namespace chromeos