- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / fake_user_manager.cc
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 void 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 }
36
37 void FakeUserManager::AddKioskAppUser(const std::string& kiosk_app_username) {
38   User* user = User::CreateKioskAppUser(kiosk_app_username);
39   user->set_username_hash(kiosk_app_username + kUserIdHashSuffix);
40   user_list_.push_back(user);
41 }
42
43 void FakeUserManager::LoginUser(const std::string& email) {
44   UserLoggedIn(email, email + kUserIdHashSuffix, false);
45 }
46
47 const UserList& FakeUserManager::GetUsers() const {
48   return user_list_;
49 }
50
51 UserList FakeUserManager::GetUsersAdmittedForMultiProfile() const {
52   UserList result;
53   for (UserList::const_iterator it = user_list_.begin();
54        it != user_list_.end();
55        ++it) {
56     if ((*it)->GetType() == User::USER_TYPE_REGULAR && !(*it)->is_logged_in())
57       result.push_back(*it);
58   }
59   return result;
60 }
61
62 const UserList& FakeUserManager::GetLoggedInUsers() const {
63   return logged_in_users_;
64 }
65
66 void FakeUserManager::UserLoggedIn(const std::string& email,
67                                    const std::string& username_hash,
68                                    bool browser_restart) {
69   for (UserList::const_iterator it = user_list_.begin();
70        it != user_list_.end();
71        ++it) {
72     if ((*it)->username_hash() == username_hash) {
73       (*it)->set_is_logged_in(true);
74       logged_in_users_.push_back(*it);
75
76       if (!primary_user_)
77         primary_user_ = *it;
78       break;
79     }
80   }
81 }
82
83 User* FakeUserManager::GetActiveUserInternal() const {
84   if (user_list_.size()) {
85     if (!active_user_id_.empty()) {
86       for (UserList::const_iterator it = user_list_.begin();
87            it != user_list_.end(); ++it) {
88         if ((*it)->email() == active_user_id_)
89           return *it;
90       }
91     }
92     return user_list_[0];
93   }
94   return NULL;
95 }
96
97 const User* FakeUserManager::GetActiveUser() const {
98   return GetActiveUserInternal();
99 }
100
101 User* FakeUserManager::GetActiveUser() {
102   return GetActiveUserInternal();
103 }
104
105 void FakeUserManager::SwitchActiveUser(const std::string& email) {
106   active_user_id_ = email;
107 }
108
109 void FakeUserManager::SaveUserDisplayName(
110     const std::string& username,
111     const string16& display_name) {
112   for (UserList::iterator it = user_list_.begin();
113        it != user_list_.end(); ++it) {
114     if ((*it)->email() == username) {
115       (*it)->set_display_name(display_name);
116       return;
117     }
118   }
119 }
120
121 void FakeUserManager::UpdateUserAccountData(const std::string&, const string16&,
122                            const std::string&) {
123   // Not implemented
124 }
125
126 SupervisedUserManager* FakeUserManager::GetSupervisedUserManager() {
127   return supervised_user_manager_.get();
128 }
129
130 UserImageManager* FakeUserManager::GetUserImageManager() {
131   return NULL;
132 }
133
134 const UserList& FakeUserManager::GetLRULoggedInUsers() {
135   return user_list_;
136 }
137
138 UserList FakeUserManager::GetUnlockUsers() const {
139   return user_list_;
140 }
141
142 const std::string& FakeUserManager::GetOwnerEmail() {
143   return owner_email_;
144 }
145
146 bool FakeUserManager::IsKnownUser(const std::string& email) const {
147   return true;
148 }
149
150 const User* FakeUserManager::FindUser(const std::string& email) const {
151   return NULL;
152 }
153
154 const User* FakeUserManager::GetLoggedInUser() const {
155   return NULL;
156 }
157
158 User* FakeUserManager::GetLoggedInUser() {
159   return NULL;
160 }
161
162 const User* FakeUserManager::GetPrimaryUser() const {
163   return primary_user_;
164 }
165
166 User* FakeUserManager::GetUserByProfile(Profile* profile) const {
167   const std::string& user_name = profile->GetProfileName();
168   for (UserList::const_iterator it = user_list_.begin();
169        it != user_list_.end(); ++it) {
170     if ((*it)->email() == user_name)
171       return *it;
172   }
173   return primary_user_;
174 }
175
176 string16 FakeUserManager::GetUserDisplayName(
177     const std::string& username) const {
178   return string16();
179 }
180
181 std::string FakeUserManager::GetUserDisplayEmail(
182     const std::string& username) const {
183   return std::string();
184 }
185
186 bool FakeUserManager::IsCurrentUserOwner() const {
187   return false;
188 }
189
190 bool FakeUserManager::IsCurrentUserNew() const {
191   return false;
192 }
193
194 bool FakeUserManager::IsCurrentUserNonCryptohomeDataEphemeral() const {
195   return false;
196 }
197
198 bool FakeUserManager::CanCurrentUserLock() const {
199   return false;
200 }
201
202 bool FakeUserManager::IsUserLoggedIn() const {
203   return logged_in_users_.size() > 0;
204 }
205
206 bool FakeUserManager::IsLoggedInAsRegularUser() const {
207   return true;
208 }
209
210 bool FakeUserManager::IsLoggedInAsDemoUser() const {
211   return false;
212 }
213
214 bool FakeUserManager::IsLoggedInAsPublicAccount() const {
215   return false;
216 }
217
218 bool FakeUserManager::IsLoggedInAsGuest() const {
219   return false;
220 }
221
222 bool FakeUserManager::IsLoggedInAsLocallyManagedUser() const {
223   return false;
224 }
225
226 bool FakeUserManager::IsLoggedInAsKioskApp() const {
227   const User* active_user = GetActiveUser();
228   return active_user ?
229       active_user->GetType() == User::USER_TYPE_KIOSK_APP :
230       false;
231 }
232
233 bool FakeUserManager::IsLoggedInAsStub() const {
234   return false;
235 }
236
237 bool FakeUserManager::IsSessionStarted() const {
238   return false;
239 }
240
241 bool FakeUserManager::UserSessionsRestored() const {
242   return false;
243 }
244
245 bool FakeUserManager::HasBrowserRestarted() const {
246   return false;
247 }
248
249 bool FakeUserManager::IsUserNonCryptohomeDataEphemeral(
250     const std::string& email) const {
251   return false;
252 }
253
254 UserFlow* FakeUserManager::GetCurrentUserFlow() const {
255   return NULL;
256 }
257
258 UserFlow* FakeUserManager::GetUserFlow(const std::string& email) const {
259   return NULL;
260 }
261
262 bool FakeUserManager::GetAppModeChromeClientOAuthInfo(
263     std::string* chrome_client_id,
264     std::string* chrome_client_secret) {
265   return false;
266 }
267
268 bool FakeUserManager::AreLocallyManagedUsersAllowed() const {
269   return true;
270 }
271
272 base::FilePath FakeUserManager::GetUserProfileDir(
273     const std::string&email) const {
274   return base::FilePath();
275 }
276
277 void FakeUserManager::RespectLocalePreference(Profile* profile,
278                                               const User* user) const {
279 }
280
281 }  // namespace chromeos