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

Side by Side Diff: chrome/browser/chromeos/login/users/fake_user_manager.cc

Issue 398753004: [cros] Move User class to user_manager component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 5 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 | Annotate | Revision Log
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 "chrome/browser/chromeos/login/users/fake_user_manager.h"
6 6
7 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h" 7 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h"
8 #include "chrome/browser/chromeos/profiles/profile_helper.h" 8 #include "chrome/browser/chromeos/profiles/profile_helper.h"
9 #include "components/user_manager/user_image/user_image.h"
9 #include "components/user_manager/user_type.h" 10 #include "components/user_manager/user_type.h"
11 #include "grit/theme_resources.h"
12 #include "ui/base/resource/resource_bundle.h"
10 13
11 namespace { 14 namespace {
12 15
13 // As defined in /chromeos/dbus/cryptohome_client.cc. 16 // As defined in /chromeos/dbus/cryptohome_client.cc.
14 static const char kUserIdHashSuffix[] = "-hash"; 17 static const char kUserIdHashSuffix[] = "-hash";
15 18
16 } // namespace 19 } // namespace
17 20
18 namespace chromeos { 21 namespace chromeos {
19 22
20 FakeUserManager::FakeUserManager() 23 FakeUserManager::FakeUserManager()
21 : supervised_user_manager_(new FakeSupervisedUserManager), 24 : supervised_user_manager_(new FakeSupervisedUserManager),
22 primary_user_(NULL), 25 primary_user_(NULL),
23 multi_profile_user_controller_(NULL) { 26 multi_profile_user_controller_(NULL) {
24 ProfileHelper::SetProfileToUserForTestingEnabled(true); 27 ProfileHelper::SetProfileToUserForTestingEnabled(true);
25 } 28 }
26 29
27 FakeUserManager::~FakeUserManager() { 30 FakeUserManager::~FakeUserManager() {
28 ProfileHelper::SetProfileToUserForTestingEnabled(false); 31 ProfileHelper::SetProfileToUserForTestingEnabled(false);
29 32
30 // Can't use STLDeleteElements because of the private destructor of User. 33 // Can't use STLDeleteElements because of the private destructor of User.
31 for (UserList::iterator it = user_list_.begin(); it != user_list_.end(); 34 for (user_manager::UserList::iterator it = user_list_.begin();
35 it != user_list_.end();
32 it = user_list_.erase(it)) { 36 it = user_list_.erase(it)) {
33 delete *it; 37 delete *it;
34 } 38 }
35 } 39 }
36 40
37 const User* FakeUserManager::AddUser(const std::string& email) { 41 const user_manager::User* FakeUserManager::AddUser(const std::string& email) {
38 User* user = User::CreateRegularUser(email); 42 user_manager::User* user = user_manager::User::CreateRegularUser(email);
39 user->set_username_hash(email + kUserIdHashSuffix); 43 user->set_username_hash(email + kUserIdHashSuffix);
40 user->SetStubImage(User::kProfileImageIndex, false); 44 user->SetStubImage(user_manager::UserImage(
45 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
46 IDR_PROFILE_PICTURE_LOADING)),
47 user_manager::User::USER_IMAGE_PROFILE,
48 false);
41 user_list_.push_back(user); 49 user_list_.push_back(user);
42 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); 50 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user);
43 return user; 51 return user;
44 } 52 }
45 53
46 const User* FakeUserManager::AddPublicAccountUser(const std::string& email) { 54 const user_manager::User* FakeUserManager::AddPublicAccountUser(
47 User* user = User::CreatePublicAccountUser(email); 55 const std::string& email) {
56 user_manager::User* user = user_manager::User::CreatePublicAccountUser(email);
48 user->set_username_hash(email + kUserIdHashSuffix); 57 user->set_username_hash(email + kUserIdHashSuffix);
49 user->SetStubImage(User::kProfileImageIndex, false); 58 user->SetStubImage(user_manager::UserImage(
59 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
60 IDR_PROFILE_PICTURE_LOADING)),
61 user_manager::User::USER_IMAGE_PROFILE,
62 false);
50 user_list_.push_back(user); 63 user_list_.push_back(user);
51 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); 64 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user);
52 return user; 65 return user;
53 } 66 }
54 67
55 void FakeUserManager::AddKioskAppUser(const std::string& kiosk_app_username) { 68 void FakeUserManager::AddKioskAppUser(const std::string& kiosk_app_username) {
56 User* user = User::CreateKioskAppUser(kiosk_app_username); 69 user_manager::User* user =
70 user_manager::User::CreateKioskAppUser(kiosk_app_username);
57 user->set_username_hash(kiosk_app_username + kUserIdHashSuffix); 71 user->set_username_hash(kiosk_app_username + kUserIdHashSuffix);
58 user_list_.push_back(user); 72 user_list_.push_back(user);
59 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user); 73 ProfileHelper::Get()->SetProfileToUserMappingForTesting(user);
60 } 74 }
61 75
62 void FakeUserManager::RemoveUserFromList(const std::string& email) { 76 void FakeUserManager::RemoveUserFromList(const std::string& email) {
63 UserList::iterator it = user_list_.begin(); 77 user_manager::UserList::iterator it = user_list_.begin();
64 while (it != user_list_.end() && (*it)->email() != email) ++it; 78 while (it != user_list_.end() && (*it)->email() != email) ++it;
65 if (it != user_list_.end()) { 79 if (it != user_list_.end()) {
66 delete *it; 80 delete *it;
67 user_list_.erase(it); 81 user_list_.erase(it);
68 } 82 }
69 } 83 }
70 84
71 void FakeUserManager::LoginUser(const std::string& email) { 85 void FakeUserManager::LoginUser(const std::string& email) {
72 UserLoggedIn(email, email + kUserIdHashSuffix, false); 86 UserLoggedIn(email, email + kUserIdHashSuffix, false);
73 } 87 }
74 88
75 const UserList& FakeUserManager::GetUsers() const { 89 const user_manager::UserList& FakeUserManager::GetUsers() const {
76 return user_list_; 90 return user_list_;
77 } 91 }
78 92
79 UserList FakeUserManager::GetUsersAdmittedForMultiProfile() const { 93 user_manager::UserList FakeUserManager::GetUsersAdmittedForMultiProfile()
80 UserList result; 94 const {
81 for (UserList::const_iterator it = user_list_.begin(); 95 user_manager::UserList result;
96 for (user_manager::UserList::const_iterator it = user_list_.begin();
82 it != user_list_.end(); 97 it != user_list_.end();
83 ++it) { 98 ++it) {
84 if ((*it)->GetType() == user_manager::USER_TYPE_REGULAR && 99 if ((*it)->GetType() == user_manager::USER_TYPE_REGULAR &&
85 !(*it)->is_logged_in()) 100 !(*it)->is_logged_in())
86 result.push_back(*it); 101 result.push_back(*it);
87 } 102 }
88 return result; 103 return result;
89 } 104 }
90 105
91 const UserList& FakeUserManager::GetLoggedInUsers() const { 106 const user_manager::UserList& FakeUserManager::GetLoggedInUsers() const {
92 return logged_in_users_; 107 return logged_in_users_;
93 } 108 }
94 109
95 void FakeUserManager::UserLoggedIn(const std::string& email, 110 void FakeUserManager::UserLoggedIn(const std::string& email,
96 const std::string& username_hash, 111 const std::string& username_hash,
97 bool browser_restart) { 112 bool browser_restart) {
98 for (UserList::const_iterator it = user_list_.begin(); 113 for (user_manager::UserList::const_iterator it = user_list_.begin();
99 it != user_list_.end(); 114 it != user_list_.end();
100 ++it) { 115 ++it) {
101 if ((*it)->username_hash() == username_hash) { 116 if ((*it)->username_hash() == username_hash) {
102 (*it)->set_is_logged_in(true); 117 (*it)->set_is_logged_in(true);
103 logged_in_users_.push_back(*it); 118 logged_in_users_.push_back(*it);
104 119
105 if (!primary_user_) 120 if (!primary_user_)
106 primary_user_ = *it; 121 primary_user_ = *it;
107 break; 122 break;
108 } 123 }
109 } 124 }
110 } 125 }
111 126
112 User* FakeUserManager::GetActiveUserInternal() const { 127 user_manager::User* FakeUserManager::GetActiveUserInternal() const {
113 if (user_list_.size()) { 128 if (user_list_.size()) {
114 if (!active_user_id_.empty()) { 129 if (!active_user_id_.empty()) {
115 for (UserList::const_iterator it = user_list_.begin(); 130 for (user_manager::UserList::const_iterator it = user_list_.begin();
116 it != user_list_.end(); ++it) { 131 it != user_list_.end();
132 ++it) {
117 if ((*it)->email() == active_user_id_) 133 if ((*it)->email() == active_user_id_)
118 return *it; 134 return *it;
119 } 135 }
120 } 136 }
121 return user_list_[0]; 137 return user_list_[0];
122 } 138 }
123 return NULL; 139 return NULL;
124 } 140 }
125 141
126 const User* FakeUserManager::GetActiveUser() const { 142 const user_manager::User* FakeUserManager::GetActiveUser() const {
127 return GetActiveUserInternal(); 143 return GetActiveUserInternal();
128 } 144 }
129 145
130 User* FakeUserManager::GetActiveUser() { 146 user_manager::User* FakeUserManager::GetActiveUser() {
131 return GetActiveUserInternal(); 147 return GetActiveUserInternal();
132 } 148 }
133 149
134 void FakeUserManager::SwitchActiveUser(const std::string& email) { 150 void FakeUserManager::SwitchActiveUser(const std::string& email) {
135 active_user_id_ = email; 151 active_user_id_ = email;
136 } 152 }
137 153
138 void FakeUserManager::SaveUserDisplayName( 154 void FakeUserManager::SaveUserDisplayName(
139 const std::string& username, 155 const std::string& username,
140 const base::string16& display_name) { 156 const base::string16& display_name) {
141 for (UserList::iterator it = user_list_.begin(); 157 for (user_manager::UserList::iterator it = user_list_.begin();
142 it != user_list_.end(); ++it) { 158 it != user_list_.end();
159 ++it) {
143 if ((*it)->email() == username) { 160 if ((*it)->email() == username) {
144 (*it)->set_display_name(display_name); 161 (*it)->set_display_name(display_name);
145 return; 162 return;
146 } 163 }
147 } 164 }
148 } 165 }
149 166
150 MultiProfileUserController* FakeUserManager::GetMultiProfileUserController() { 167 MultiProfileUserController* FakeUserManager::GetMultiProfileUserController() {
151 return multi_profile_user_controller_; 168 return multi_profile_user_controller_;
152 } 169 }
153 170
154 SupervisedUserManager* FakeUserManager::GetSupervisedUserManager() { 171 SupervisedUserManager* FakeUserManager::GetSupervisedUserManager() {
155 return supervised_user_manager_.get(); 172 return supervised_user_manager_.get();
156 } 173 }
157 174
158 UserImageManager* FakeUserManager::GetUserImageManager( 175 UserImageManager* FakeUserManager::GetUserImageManager(
159 const std::string& /* user_id */) { 176 const std::string& /* user_id */) {
160 return NULL; 177 return NULL;
161 } 178 }
162 179
163 const UserList& FakeUserManager::GetLRULoggedInUsers() { 180 const user_manager::UserList& FakeUserManager::GetLRULoggedInUsers() {
164 return user_list_; 181 return user_list_;
165 } 182 }
166 183
167 UserList FakeUserManager::GetUnlockUsers() const { 184 user_manager::UserList FakeUserManager::GetUnlockUsers() const {
168 return user_list_; 185 return user_list_;
169 } 186 }
170 187
171 const std::string& FakeUserManager::GetOwnerEmail() { 188 const std::string& FakeUserManager::GetOwnerEmail() {
172 return owner_email_; 189 return owner_email_;
173 } 190 }
174 191
175 bool FakeUserManager::IsKnownUser(const std::string& email) const { 192 bool FakeUserManager::IsKnownUser(const std::string& email) const {
176 return true; 193 return true;
177 } 194 }
178 195
179 const User* FakeUserManager::FindUser(const std::string& email) const { 196 const user_manager::User* FakeUserManager::FindUser(
180 const UserList& users = GetUsers(); 197 const std::string& email) const {
181 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { 198 const user_manager::UserList& users = GetUsers();
199 for (user_manager::UserList::const_iterator it = users.begin();
200 it != users.end();
201 ++it) {
182 if ((*it)->email() == email) 202 if ((*it)->email() == email)
183 return *it; 203 return *it;
184 } 204 }
185 return NULL; 205 return NULL;
186 } 206 }
187 207
188 User* FakeUserManager::FindUserAndModify(const std::string& email) { 208 user_manager::User* FakeUserManager::FindUserAndModify(
209 const std::string& email) {
189 return NULL; 210 return NULL;
190 } 211 }
191 212
192 const User* FakeUserManager::GetLoggedInUser() const { 213 const user_manager::User* FakeUserManager::GetLoggedInUser() const {
193 return NULL; 214 return NULL;
194 } 215 }
195 216
196 User* FakeUserManager::GetLoggedInUser() { 217 user_manager::User* FakeUserManager::GetLoggedInUser() {
197 return NULL; 218 return NULL;
198 } 219 }
199 220
200 const User* FakeUserManager::GetPrimaryUser() const { 221 const user_manager::User* FakeUserManager::GetPrimaryUser() const {
201 return primary_user_; 222 return primary_user_;
202 } 223 }
203 224
204 base::string16 FakeUserManager::GetUserDisplayName( 225 base::string16 FakeUserManager::GetUserDisplayName(
205 const std::string& username) const { 226 const std::string& username) const {
206 return base::string16(); 227 return base::string16();
207 } 228 }
208 229
209 std::string FakeUserManager::GetUserDisplayEmail( 230 std::string FakeUserManager::GetUserDisplayEmail(
210 const std::string& username) const { 231 const std::string& username) const {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 266
246 bool FakeUserManager::IsLoggedInAsGuest() const { 267 bool FakeUserManager::IsLoggedInAsGuest() const {
247 return false; 268 return false;
248 } 269 }
249 270
250 bool FakeUserManager::IsLoggedInAsSupervisedUser() const { 271 bool FakeUserManager::IsLoggedInAsSupervisedUser() const {
251 return false; 272 return false;
252 } 273 }
253 274
254 bool FakeUserManager::IsLoggedInAsKioskApp() const { 275 bool FakeUserManager::IsLoggedInAsKioskApp() const {
255 const User* active_user = GetActiveUser(); 276 const user_manager::User* active_user = GetActiveUser();
256 return active_user 277 return active_user
257 ? active_user->GetType() == user_manager::USER_TYPE_KIOSK_APP 278 ? active_user->GetType() == user_manager::USER_TYPE_KIOSK_APP
258 : false; 279 : false;
259 } 280 }
260 281
261 bool FakeUserManager::IsLoggedInAsStub() const { 282 bool FakeUserManager::IsLoggedInAsStub() const {
262 return false; 283 return false;
263 } 284 }
264 285
265 bool FakeUserManager::IsSessionStarted() const { 286 bool FakeUserManager::IsSessionStarted() const {
(...skipping 11 matching lines...) Expand all
277 298
278 UserFlow* FakeUserManager::GetUserFlow(const std::string& email) const { 299 UserFlow* FakeUserManager::GetUserFlow(const std::string& email) const {
279 return NULL; 300 return NULL;
280 } 301 }
281 302
282 bool FakeUserManager::AreSupervisedUsersAllowed() const { 303 bool FakeUserManager::AreSupervisedUsersAllowed() const {
283 return true; 304 return true;
284 } 305 }
285 306
286 } // namespace chromeos 307 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/users/fake_user_manager.h ('k') | chrome/browser/chromeos/login/users/mock_user_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698