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

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

Issue 1412813003: This CL replaces user_manager::UserID with AccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@468875--Chrome-OS-handles-deletion-of-Gmail-account-poorly--Create-AccountID-structure-part2--user_names
Patch Set: Update after review. Created 5 years, 1 month 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
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 "components/user_manager/fake_user_manager.h" 5 #include "components/user_manager/fake_user_manager.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/task_runner.h" 8 #include "base/task_runner.h"
9 #include "components/user_manager/user_type.h" 9 #include "components/user_manager/user_type.h"
10 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
(...skipping 13 matching lines...) Expand all
24 protected: 24 protected:
25 ~FakeTaskRunner() override {} 25 ~FakeTaskRunner() override {}
26 }; 26 };
27 27
28 } // namespace 28 } // namespace
29 29
30 namespace user_manager { 30 namespace user_manager {
31 31
32 FakeUserManager::FakeUserManager() 32 FakeUserManager::FakeUserManager()
33 : UserManagerBase(new FakeTaskRunner(), new FakeTaskRunner()), 33 : UserManagerBase(new FakeTaskRunner(), new FakeTaskRunner()),
34 primary_user_(NULL), 34 primary_user_(NULL) {}
achuithb 2015/10/28 23:11:46 switch to nullptr for this file as well, since the
Alexander Alekseev 2015/10/29 02:00:42 Done.
35 owner_email_(std::string()) {
36 }
37 35
38 FakeUserManager::~FakeUserManager() { 36 FakeUserManager::~FakeUserManager() {
39 } 37 }
40 38
41 const user_manager::User* FakeUserManager::AddUser(const std::string& email) { 39 const user_manager::User* FakeUserManager::AddUser(
42 return AddUserWithAffiliation(email, false); 40 const AccountId& account_id) {
41 return AddUserWithAffiliation(account_id, false);
43 } 42 }
44 43
45 const user_manager::User* FakeUserManager::AddUserWithAffiliation( 44 const user_manager::User* FakeUserManager::AddUserWithAffiliation(
46 const std::string& email, bool is_affiliated) { 45 const AccountId& account_id,
47 user_manager::User* user = user_manager::User::CreateRegularUser(email); 46 bool is_affiliated) {
47 user_manager::User* user = user_manager::User::CreateRegularUser(account_id);
48 user->set_affiliation(is_affiliated); 48 user->set_affiliation(is_affiliated);
49 users_.push_back(user); 49 users_.push_back(user);
50 return user; 50 return user;
51 } 51 }
52 52
53 void FakeUserManager::RemoveUserFromList(const std::string& email) { 53 void FakeUserManager::RemoveUserFromList(const AccountId& account_id) {
54 user_manager::UserList::iterator it = users_.begin(); 54 user_manager::UserList::iterator it = users_.begin();
55 while (it != users_.end() && (*it)->email() != email) 55 // TODO (alemate): Chenge this to GetAccountId(), once a real AccountId is
56 // passed. crbug.com/546876
57 while (it != users_.end() && (*it)->GetEmail() != account_id.GetUserEmail())
56 ++it; 58 ++it;
57 if (it != users_.end()) { 59 if (it != users_.end()) {
58 delete *it; 60 delete *it;
59 users_.erase(it); 61 users_.erase(it);
60 } 62 }
61 } 63 }
62 64
63 const user_manager::UserList& FakeUserManager::GetUsers() const { 65 const user_manager::UserList& FakeUserManager::GetUsers() const {
64 return users_; 66 return users_;
65 } 67 }
66 68
67 user_manager::UserList FakeUserManager::GetUsersAllowedForMultiProfile() const { 69 user_manager::UserList FakeUserManager::GetUsersAllowedForMultiProfile() const {
68 user_manager::UserList result; 70 user_manager::UserList result;
69 for (user_manager::UserList::const_iterator it = users_.begin(); 71 for (user_manager::UserList::const_iterator it = users_.begin();
70 it != users_.end(); ++it) { 72 it != users_.end(); ++it) {
71 if ((*it)->GetType() == user_manager::USER_TYPE_REGULAR && 73 if ((*it)->GetType() == user_manager::USER_TYPE_REGULAR &&
72 !(*it)->is_logged_in()) 74 !(*it)->is_logged_in())
73 result.push_back(*it); 75 result.push_back(*it);
74 } 76 }
75 return result; 77 return result;
76 } 78 }
77 79
78 const user_manager::UserList& FakeUserManager::GetLoggedInUsers() const { 80 const user_manager::UserList& FakeUserManager::GetLoggedInUsers() const {
79 return logged_in_users_; 81 return logged_in_users_;
80 } 82 }
81 83
82 void FakeUserManager::UserLoggedIn(const std::string& email, 84 void FakeUserManager::UserLoggedIn(const AccountId& account_id,
83 const std::string& username_hash, 85 const std::string& username_hash,
84 bool browser_restart) { 86 bool browser_restart) {
85 for (user_manager::UserList::const_iterator it = users_.begin(); 87 for (user_manager::UserList::const_iterator it = users_.begin();
86 it != users_.end(); ++it) { 88 it != users_.end(); ++it) {
87 if ((*it)->username_hash() == username_hash) { 89 if ((*it)->username_hash() == username_hash) {
88 (*it)->set_is_logged_in(true); 90 (*it)->set_is_logged_in(true);
89 (*it)->set_profile_is_created(); 91 (*it)->set_profile_is_created();
90 logged_in_users_.push_back(*it); 92 logged_in_users_.push_back(*it);
91 93
92 if (!primary_user_) 94 if (!primary_user_)
93 primary_user_ = *it; 95 primary_user_ = *it;
94 break; 96 break;
95 } 97 }
96 } 98 }
97 } 99 }
98 100
99 user_manager::User* FakeUserManager::GetActiveUserInternal() const { 101 user_manager::User* FakeUserManager::GetActiveUserInternal() const {
100 if (users_.size()) { 102 if (users_.size()) {
achuithb 2015/10/28 23:11:46 if (!users_.empty()) since you are here
Alexander Alekseev 2015/10/29 02:00:42 Done.
101 if (!active_user_id_.empty()) { 103 if (active_account_id_.is_valid()) {
102 for (user_manager::UserList::const_iterator it = users_.begin(); 104 for (user_manager::UserList::const_iterator it = users_.begin();
103 it != users_.end(); ++it) { 105 it != users_.end(); ++it) {
104 if ((*it)->email() == active_user_id_) 106 // TODO (alemate): Chenge this to GetAccountId(), once a real AccountId
107 // is
108 // passed. crbug.com/546876
109 if ((*it)->GetEmail() == active_account_id_.GetUserEmail())
105 return *it; 110 return *it;
106 } 111 }
107 } 112 }
108 return users_[0]; 113 return users_[0];
109 } 114 }
110 return NULL; 115 return NULL;
111 } 116 }
112 117
113 const user_manager::User* FakeUserManager::GetActiveUser() const { 118 const user_manager::User* FakeUserManager::GetActiveUser() const {
114 return GetActiveUserInternal(); 119 return GetActiveUserInternal();
115 } 120 }
116 121
117 user_manager::User* FakeUserManager::GetActiveUser() { 122 user_manager::User* FakeUserManager::GetActiveUser() {
118 return GetActiveUserInternal(); 123 return GetActiveUserInternal();
119 } 124 }
120 125
121 void FakeUserManager::SwitchActiveUser(const std::string& email) { 126 void FakeUserManager::SwitchActiveUser(const AccountId& account_id) {}
122 }
123 127
124 void FakeUserManager::SaveUserDisplayName(const std::string& username, 128 void FakeUserManager::SaveUserDisplayName(const AccountId& account_id,
125 const base::string16& display_name) { 129 const base::string16& display_name) {
126 for (user_manager::UserList::iterator it = users_.begin(); it != users_.end(); 130 for (user_manager::UserList::iterator it = users_.begin(); it != users_.end();
127 ++it) { 131 ++it) {
128 if ((*it)->email() == username) { 132 // TODO (alemate): Chenge this to GetAccountId(), once a real AccountId is
133 // passed. crbug.com/546876
134 if ((*it)->GetEmail() == account_id.GetUserEmail()) {
129 (*it)->set_display_name(display_name); 135 (*it)->set_display_name(display_name);
130 return; 136 return;
131 } 137 }
132 } 138 }
133 } 139 }
134 140
135 const user_manager::UserList& FakeUserManager::GetLRULoggedInUsers() const { 141 const user_manager::UserList& FakeUserManager::GetLRULoggedInUsers() const {
136 return users_; 142 return users_;
137 } 143 }
138 144
139 user_manager::UserList FakeUserManager::GetUnlockUsers() const { 145 user_manager::UserList FakeUserManager::GetUnlockUsers() const {
140 return users_; 146 return users_;
141 } 147 }
142 148
143 const std::string& FakeUserManager::GetOwnerEmail() const { 149 const AccountId& FakeUserManager::GetOwnerAccountId() const {
144 return owner_email_; 150 return owner_account_id_;
145 } 151 }
146 152
147 bool FakeUserManager::IsKnownUser(const std::string& email) const { 153 bool FakeUserManager::IsKnownUser(const AccountId& account_id) const {
148 return true; 154 return true;
149 } 155 }
150 156
151 const user_manager::User* FakeUserManager::FindUser( 157 const user_manager::User* FakeUserManager::FindUser(
152 const std::string& email) const { 158 const AccountId& account_id) const {
153 const user_manager::UserList& users = GetUsers(); 159 const user_manager::UserList& users = GetUsers();
154 for (user_manager::UserList::const_iterator it = users.begin(); 160 for (user_manager::UserList::const_iterator it = users.begin();
155 it != users.end(); ++it) { 161 it != users.end(); ++it) {
156 if ((*it)->email() == email) 162 // TODO (alemate): Chenge this to GetAccountId(), once a real AccountId is
163 // passed. crbug.com/546876
164 if ((*it)->GetEmail() == account_id.GetUserEmail())
157 return *it; 165 return *it;
158 } 166 }
159 return NULL; 167 return NULL;
160 } 168 }
161 169
162 user_manager::User* FakeUserManager::FindUserAndModify( 170 user_manager::User* FakeUserManager::FindUserAndModify(
163 const std::string& email) { 171 const AccountId& account_id) {
164 return NULL; 172 return NULL;
165 } 173 }
166 174
167 const user_manager::User* FakeUserManager::GetLoggedInUser() const { 175 const user_manager::User* FakeUserManager::GetLoggedInUser() const {
168 return NULL; 176 return NULL;
169 } 177 }
170 178
171 user_manager::User* FakeUserManager::GetLoggedInUser() { 179 user_manager::User* FakeUserManager::GetLoggedInUser() {
172 return NULL; 180 return NULL;
173 } 181 }
174 182
175 const user_manager::User* FakeUserManager::GetPrimaryUser() const { 183 const user_manager::User* FakeUserManager::GetPrimaryUser() const {
176 return primary_user_; 184 return primary_user_;
177 } 185 }
178 186
179 base::string16 FakeUserManager::GetUserDisplayName( 187 base::string16 FakeUserManager::GetUserDisplayName(
180 const std::string& username) const { 188 const AccountId& account_id) const {
181 return base::string16(); 189 return base::string16();
182 } 190 }
183 191
184 std::string FakeUserManager::GetUserDisplayEmail( 192 std::string FakeUserManager::GetUserDisplayEmail(
185 const std::string& username) const { 193 const AccountId& account_id) const {
186 return std::string(); 194 return std::string();
187 } 195 }
188 196
189 bool FakeUserManager::IsCurrentUserOwner() const { 197 bool FakeUserManager::IsCurrentUserOwner() const {
190 return false; 198 return false;
191 } 199 }
192 200
193 bool FakeUserManager::IsCurrentUserNew() const { 201 bool FakeUserManager::IsCurrentUserNew() const {
194 return false; 202 return false;
195 } 203 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 239
232 bool FakeUserManager::IsLoggedInAsStub() const { 240 bool FakeUserManager::IsLoggedInAsStub() const {
233 return false; 241 return false;
234 } 242 }
235 243
236 bool FakeUserManager::IsSessionStarted() const { 244 bool FakeUserManager::IsSessionStarted() const {
237 return false; 245 return false;
238 } 246 }
239 247
240 bool FakeUserManager::IsUserNonCryptohomeDataEphemeral( 248 bool FakeUserManager::IsUserNonCryptohomeDataEphemeral(
241 const std::string& email) const { 249 const AccountId& account_id) const {
242 return false; 250 return false;
243 } 251 }
244 252
245 bool FakeUserManager::AreSupervisedUsersAllowed() const { 253 bool FakeUserManager::AreSupervisedUsersAllowed() const {
246 return true; 254 return true;
247 } 255 }
248 256
249 bool FakeUserManager::AreEphemeralUsersEnabled() const { 257 bool FakeUserManager::AreEphemeralUsersEnabled() const {
250 return false; 258 return false;
251 } 259 }
252 260
253 const std::string& FakeUserManager::GetApplicationLocale() const { 261 const std::string& FakeUserManager::GetApplicationLocale() const {
254 static const std::string default_locale("en-US"); 262 static const std::string default_locale("en-US");
255 return default_locale; 263 return default_locale;
256 } 264 }
257 265
258 PrefService* FakeUserManager::GetLocalState() const { 266 PrefService* FakeUserManager::GetLocalState() const {
259 return NULL; 267 return NULL;
260 } 268 }
261 269
262 bool FakeUserManager::IsEnterpriseManaged() const { 270 bool FakeUserManager::IsEnterpriseManaged() const {
263 return false; 271 return false;
264 } 272 }
265 273
266 bool FakeUserManager::IsDemoApp(const std::string& user_id) const { 274 bool FakeUserManager::IsDemoApp(const AccountId& account_id) const {
267 return false; 275 return false;
268 } 276 }
269 277
270 bool FakeUserManager::IsKioskApp(const std::string& user_id) const { 278 bool FakeUserManager::IsKioskApp(const AccountId& account_id) const {
271 return false; 279 return false;
272 } 280 }
273 281
274 bool FakeUserManager::IsPublicAccountMarkedForRemoval( 282 bool FakeUserManager::IsPublicAccountMarkedForRemoval(
275 const std::string& user_id) const { 283 const AccountId& account_id) const {
276 return false; 284 return false;
277 } 285 }
278 286
279 } // namespace user_manager 287 } // namespace user_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698