Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Side by Side Diff: components/user_manager/fake_user_manager.cc

Issue 824683002: UserManager stack refactoring. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test fixed. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/user_manager/fake_user_manager.h ('k') | components/user_manager/user.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_user_manager.h" 5 #include "components/user_manager/fake_user_manager.h"
6 6
7 #include "base/callback.h"
7 #include "base/task_runner.h" 8 #include "base/task_runner.h"
8 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h"
9 #include "chrome/browser/chromeos/profiles/profile_helper.h"
10 #include "chrome/grit/theme_resources.h"
11 #include "components/user_manager/user_image/user_image.h"
12 #include "components/user_manager/user_type.h" 9 #include "components/user_manager/user_type.h"
13 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
14 11
15 namespace { 12 namespace {
16 13
17 class FakeTaskRunner : public base::TaskRunner { 14 class FakeTaskRunner : public base::TaskRunner {
18 public: 15 public:
19 bool PostDelayedTask(const tracked_objects::Location& from_here, 16 bool PostDelayedTask(const tracked_objects::Location& from_here,
20 const base::Closure& task, 17 const base::Closure& task,
21 base::TimeDelta delay) override { 18 base::TimeDelta delay) override {
22 task.Run(); 19 task.Run();
23 return true; 20 return true;
24 } 21 }
25 bool RunsTasksOnCurrentThread() const override { return true; } 22 bool RunsTasksOnCurrentThread() const override { return true; }
26 23
27 protected: 24 protected:
28 ~FakeTaskRunner() override {} 25 ~FakeTaskRunner() override {}
29 }; 26 };
30 27
31 } // namespace 28 } // namespace
32 29
33 namespace chromeos { 30 namespace user_manager {
34 31
35 FakeUserManager::FakeUserManager() 32 FakeUserManager::FakeUserManager()
36 : ChromeUserManager(new FakeTaskRunner(), new FakeTaskRunner()), 33 : UserManagerBase(new FakeTaskRunner(), new FakeTaskRunner()),
37 supervised_user_manager_(new FakeSupervisedUserManager),
38 primary_user_(NULL), 34 primary_user_(NULL),
39 multi_profile_user_controller_(NULL) { 35 owner_email_(std::string()) {
40 } 36 }
41 37
42 FakeUserManager::~FakeUserManager() { 38 FakeUserManager::~FakeUserManager() {
43 // Can't use STLDeleteElements because of the private destructor of User.
44 for (user_manager::UserList::iterator it = user_list_.begin();
45 it != user_list_.end();
46 it = user_list_.erase(it)) {
47 delete *it;
48 }
49 } 39 }
50 40
51 const user_manager::User* FakeUserManager::AddUser(const std::string& email) { 41 const user_manager::User* FakeUserManager::AddUser(const std::string& email) {
52 user_manager::User* user = user_manager::User::CreateRegularUser(email); 42 user_manager::User* user = user_manager::User::CreateRegularUser(email);
53 user->set_username_hash( 43 users_.push_back(user);
54 ProfileHelper::GetUserIdHashByUserIdForTesting(email));
55 user->SetStubImage(user_manager::UserImage(
56 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
57 IDR_PROFILE_PICTURE_LOADING)),
58 user_manager::User::USER_IMAGE_PROFILE,
59 false);
60 user_list_.push_back(user);
61 return user; 44 return user;
62 } 45 }
63 46
64 const user_manager::User* FakeUserManager::AddPublicAccountUser(
65 const std::string& email) {
66 user_manager::User* user = user_manager::User::CreatePublicAccountUser(email);
67 user->set_username_hash(
68 ProfileHelper::GetUserIdHashByUserIdForTesting(email));
69 user->SetStubImage(user_manager::UserImage(
70 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
71 IDR_PROFILE_PICTURE_LOADING)),
72 user_manager::User::USER_IMAGE_PROFILE,
73 false);
74 user_list_.push_back(user);
75 return user;
76 }
77
78 void FakeUserManager::AddKioskAppUser(const std::string& kiosk_app_username) {
79 user_manager::User* user =
80 user_manager::User::CreateKioskAppUser(kiosk_app_username);
81 user->set_username_hash(
82 ProfileHelper::GetUserIdHashByUserIdForTesting(kiosk_app_username));
83 user_list_.push_back(user);
84 }
85
86 void FakeUserManager::RemoveUserFromList(const std::string& email) { 47 void FakeUserManager::RemoveUserFromList(const std::string& email) {
87 user_manager::UserList::iterator it = user_list_.begin(); 48 user_manager::UserList::iterator it = users_.begin();
88 while (it != user_list_.end() && (*it)->email() != email) ++it; 49 while (it != users_.end() && (*it)->email() != email)
89 if (it != user_list_.end()) { 50 ++it;
51 if (it != users_.end()) {
90 delete *it; 52 delete *it;
91 user_list_.erase(it); 53 users_.erase(it);
92 } 54 }
93 } 55 }
94 56
95 void FakeUserManager::LoginUser(const std::string& email) {
96 UserLoggedIn(
97 email, ProfileHelper::GetUserIdHashByUserIdForTesting(email), false);
98 }
99
100 const user_manager::UserList& FakeUserManager::GetUsers() const { 57 const user_manager::UserList& FakeUserManager::GetUsers() const {
101 return user_list_; 58 return users_;
102 } 59 }
103 60
104 user_manager::UserList FakeUserManager::GetUsersAllowedForMultiProfile() const { 61 user_manager::UserList FakeUserManager::GetUsersAllowedForMultiProfile() const {
105 user_manager::UserList result; 62 user_manager::UserList result;
106 for (user_manager::UserList::const_iterator it = user_list_.begin(); 63 for (user_manager::UserList::const_iterator it = users_.begin();
107 it != user_list_.end(); 64 it != users_.end(); ++it) {
108 ++it) {
109 if ((*it)->GetType() == user_manager::USER_TYPE_REGULAR && 65 if ((*it)->GetType() == user_manager::USER_TYPE_REGULAR &&
110 !(*it)->is_logged_in()) 66 !(*it)->is_logged_in())
111 result.push_back(*it); 67 result.push_back(*it);
112 } 68 }
113 return result; 69 return result;
114 } 70 }
115 71
116 user_manager::UserList
117 FakeUserManager::GetUsersAllowedForSupervisedUsersCreation() const {
118 return ChromeUserManager::GetUsersAllowedAsSupervisedUserManagers(user_list_);
119 }
120
121 const user_manager::UserList& FakeUserManager::GetLoggedInUsers() const { 72 const user_manager::UserList& FakeUserManager::GetLoggedInUsers() const {
122 return logged_in_users_; 73 return logged_in_users_;
123 } 74 }
124 75
125 void FakeUserManager::UserLoggedIn(const std::string& email, 76 void FakeUserManager::UserLoggedIn(const std::string& email,
126 const std::string& username_hash, 77 const std::string& username_hash,
127 bool browser_restart) { 78 bool browser_restart) {
128 for (user_manager::UserList::const_iterator it = user_list_.begin(); 79 for (user_manager::UserList::const_iterator it = users_.begin();
129 it != user_list_.end(); 80 it != users_.end(); ++it) {
130 ++it) {
131 if ((*it)->username_hash() == username_hash) { 81 if ((*it)->username_hash() == username_hash) {
132 (*it)->set_is_logged_in(true); 82 (*it)->set_is_logged_in(true);
133 (*it)->set_profile_is_created(); 83 (*it)->set_profile_is_created();
134 logged_in_users_.push_back(*it); 84 logged_in_users_.push_back(*it);
135 85
136 if (!primary_user_) 86 if (!primary_user_)
137 primary_user_ = *it; 87 primary_user_ = *it;
138 break; 88 break;
139 } 89 }
140 } 90 }
141 } 91 }
142 92
143 user_manager::User* FakeUserManager::GetActiveUserInternal() const { 93 user_manager::User* FakeUserManager::GetActiveUserInternal() const {
144 if (user_list_.size()) { 94 if (users_.size()) {
145 if (!active_user_id_.empty()) { 95 if (!active_user_id_.empty()) {
146 for (user_manager::UserList::const_iterator it = user_list_.begin(); 96 for (user_manager::UserList::const_iterator it = users_.begin();
147 it != user_list_.end(); 97 it != users_.end(); ++it) {
148 ++it) {
149 if ((*it)->email() == active_user_id_) 98 if ((*it)->email() == active_user_id_)
150 return *it; 99 return *it;
151 } 100 }
152 } 101 }
153 return user_list_[0]; 102 return users_[0];
154 } 103 }
155 return NULL; 104 return NULL;
156 } 105 }
157 106
158 const user_manager::User* FakeUserManager::GetActiveUser() const { 107 const user_manager::User* FakeUserManager::GetActiveUser() const {
159 return GetActiveUserInternal(); 108 return GetActiveUserInternal();
160 } 109 }
161 110
162 user_manager::User* FakeUserManager::GetActiveUser() { 111 user_manager::User* FakeUserManager::GetActiveUser() {
163 return GetActiveUserInternal(); 112 return GetActiveUserInternal();
164 } 113 }
165 114
166 void FakeUserManager::SwitchActiveUser(const std::string& email) { 115 void FakeUserManager::SwitchActiveUser(const std::string& email) {
167 active_user_id_ = email;
168 ProfileHelper::Get()->ActiveUserHashChanged(
169 ProfileHelper::GetUserIdHashByUserIdForTesting(email));
170 if (user_list_.size() && !active_user_id_.empty()) {
171 for (user_manager::UserList::const_iterator it = user_list_.begin();
172 it != user_list_.end(); ++it) {
173 (*it)->set_is_active((*it)->email() == active_user_id_);
174 }
175 }
176 } 116 }
177 117
178 void FakeUserManager::SaveUserDisplayName( 118 void FakeUserManager::SaveUserDisplayName(const std::string& username,
179 const std::string& username, 119 const base::string16& display_name) {
180 const base::string16& display_name) { 120 for (user_manager::UserList::iterator it = users_.begin(); it != users_.end();
181 for (user_manager::UserList::iterator it = user_list_.begin();
182 it != user_list_.end();
183 ++it) { 121 ++it) {
184 if ((*it)->email() == username) { 122 if ((*it)->email() == username) {
185 (*it)->set_display_name(display_name); 123 (*it)->set_display_name(display_name);
186 return; 124 return;
187 } 125 }
188 } 126 }
189 } 127 }
190 128
191 MultiProfileUserController* FakeUserManager::GetMultiProfileUserController() {
192 return multi_profile_user_controller_;
193 }
194
195 SupervisedUserManager* FakeUserManager::GetSupervisedUserManager() {
196 return supervised_user_manager_.get();
197 }
198
199 UserImageManager* FakeUserManager::GetUserImageManager(
200 const std::string& /* user_id */) {
201 return NULL;
202 }
203
204 const user_manager::UserList& FakeUserManager::GetLRULoggedInUsers() const { 129 const user_manager::UserList& FakeUserManager::GetLRULoggedInUsers() const {
205 return user_list_; 130 return users_;
206 } 131 }
207 132
208 user_manager::UserList FakeUserManager::GetUnlockUsers() const { 133 user_manager::UserList FakeUserManager::GetUnlockUsers() const {
209 return user_list_; 134 return users_;
210 } 135 }
211 136
212 const std::string& FakeUserManager::GetOwnerEmail() const { 137 const std::string& FakeUserManager::GetOwnerEmail() const {
213 return owner_email_; 138 return owner_email_;
214 } 139 }
215 140
216 bool FakeUserManager::IsKnownUser(const std::string& email) const { 141 bool FakeUserManager::IsKnownUser(const std::string& email) const {
217 return true; 142 return true;
218 } 143 }
219 144
220 const user_manager::User* FakeUserManager::FindUser( 145 const user_manager::User* FakeUserManager::FindUser(
221 const std::string& email) const { 146 const std::string& email) const {
222 const user_manager::UserList& users = GetUsers(); 147 const user_manager::UserList& users = GetUsers();
223 for (user_manager::UserList::const_iterator it = users.begin(); 148 for (user_manager::UserList::const_iterator it = users.begin();
224 it != users.end(); 149 it != users.end(); ++it) {
225 ++it) {
226 if ((*it)->email() == email) 150 if ((*it)->email() == email)
227 return *it; 151 return *it;
228 } 152 }
229 return NULL; 153 return NULL;
230 } 154 }
231 155
232 user_manager::User* FakeUserManager::FindUserAndModify( 156 user_manager::User* FakeUserManager::FindUserAndModify(
233 const std::string& email) { 157 const std::string& email) {
234 return NULL; 158 return NULL;
235 } 159 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 229
306 bool FakeUserManager::IsSessionStarted() const { 230 bool FakeUserManager::IsSessionStarted() const {
307 return false; 231 return false;
308 } 232 }
309 233
310 bool FakeUserManager::IsUserNonCryptohomeDataEphemeral( 234 bool FakeUserManager::IsUserNonCryptohomeDataEphemeral(
311 const std::string& email) const { 235 const std::string& email) const {
312 return false; 236 return false;
313 } 237 }
314 238
315 UserFlow* FakeUserManager::GetCurrentUserFlow() const {
316 return NULL;
317 }
318
319 UserFlow* FakeUserManager::GetUserFlow(const std::string& email) const {
320 return NULL;
321 }
322
323 bool FakeUserManager::AreSupervisedUsersAllowed() const { 239 bool FakeUserManager::AreSupervisedUsersAllowed() const {
324 return true; 240 return true;
325 } 241 }
326 242
327 bool FakeUserManager::AreEphemeralUsersEnabled() const { 243 bool FakeUserManager::AreEphemeralUsersEnabled() const {
328 return false; 244 return false;
329 } 245 }
330 246
331 const std::string& FakeUserManager::GetApplicationLocale() const { 247 const std::string& FakeUserManager::GetApplicationLocale() const {
332 static const std::string default_locale("en-US"); 248 static const std::string default_locale("en-US");
(...skipping 14 matching lines...) Expand all
347 263
348 bool FakeUserManager::IsKioskApp(const std::string& user_id) const { 264 bool FakeUserManager::IsKioskApp(const std::string& user_id) const {
349 return false; 265 return false;
350 } 266 }
351 267
352 bool FakeUserManager::IsPublicAccountMarkedForRemoval( 268 bool FakeUserManager::IsPublicAccountMarkedForRemoval(
353 const std::string& user_id) const { 269 const std::string& user_id) const {
354 return false; 270 return false;
355 } 271 }
356 272
357 } // namespace chromeos 273 } // namespace user_manager
OLDNEW
« no previous file with comments | « components/user_manager/fake_user_manager.h ('k') | components/user_manager/user.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698