OLD | NEW |
---|---|
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 Loading... | |
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/23 00:08:52
in class member initialization
Alexander Alekseev
2015/10/23 09:11:24
Done.
| |
35 owner_email_(std::string()) { | 35 active_user_id_(EmptyAccountId()), |
36 } | 36 owner_id_(EmptyAccountId()) {} |
37 | 37 |
38 FakeUserManager::~FakeUserManager() { | 38 FakeUserManager::~FakeUserManager() { |
39 } | 39 } |
40 | 40 |
41 const user_manager::User* FakeUserManager::AddUser(const std::string& email) { | 41 const user_manager::User* FakeUserManager::AddUser(const AccountId& account) { |
42 return AddUserWithAffiliation(email, false); | 42 return AddUserWithAffiliation(account, false); |
43 } | 43 } |
44 | 44 |
45 const user_manager::User* FakeUserManager::AddUserWithAffiliation( | 45 const user_manager::User* FakeUserManager::AddUserWithAffiliation( |
46 const std::string& email, bool is_affiliated) { | 46 const AccountId& account, |
47 user_manager::User* user = user_manager::User::CreateRegularUser(email); | 47 bool is_affiliated) { |
48 user_manager::User* user = user_manager::User::CreateRegularUser(account); | |
48 user->set_affiliation(is_affiliated); | 49 user->set_affiliation(is_affiliated); |
49 users_.push_back(user); | 50 users_.push_back(user); |
50 return user; | 51 return user; |
51 } | 52 } |
52 | 53 |
53 void FakeUserManager::RemoveUserFromList(const std::string& email) { | 54 void FakeUserManager::RemoveUserFromList(const AccountId& account) { |
54 user_manager::UserList::iterator it = users_.begin(); | 55 user_manager::UserList::iterator it = users_.begin(); |
55 while (it != users_.end() && (*it)->email() != email) | 56 // TODO (alemate): Chenge this to GetUserID(), once a real AccountId is |
achuithb
2015/10/23 00:08:52
s/Chenge/Change
Please reference a bug.
same bel
Alexander Alekseev
2015/10/23 09:11:24
Done.
| |
57 // passed. | |
58 while (it != users_.end() && (*it)->GetEmail() != account.GetUserEmail()) | |
56 ++it; | 59 ++it; |
57 if (it != users_.end()) { | 60 if (it != users_.end()) { |
58 delete *it; | 61 delete *it; |
59 users_.erase(it); | 62 users_.erase(it); |
60 } | 63 } |
61 } | 64 } |
62 | 65 |
63 const user_manager::UserList& FakeUserManager::GetUsers() const { | 66 const user_manager::UserList& FakeUserManager::GetUsers() const { |
64 return users_; | 67 return users_; |
65 } | 68 } |
66 | 69 |
67 user_manager::UserList FakeUserManager::GetUsersAllowedForMultiProfile() const { | 70 user_manager::UserList FakeUserManager::GetUsersAllowedForMultiProfile() const { |
68 user_manager::UserList result; | 71 user_manager::UserList result; |
69 for (user_manager::UserList::const_iterator it = users_.begin(); | 72 for (user_manager::UserList::const_iterator it = users_.begin(); |
70 it != users_.end(); ++it) { | 73 it != users_.end(); ++it) { |
71 if ((*it)->GetType() == user_manager::USER_TYPE_REGULAR && | 74 if ((*it)->GetType() == user_manager::USER_TYPE_REGULAR && |
72 !(*it)->is_logged_in()) | 75 !(*it)->is_logged_in()) |
73 result.push_back(*it); | 76 result.push_back(*it); |
74 } | 77 } |
75 return result; | 78 return result; |
76 } | 79 } |
77 | 80 |
78 const user_manager::UserList& FakeUserManager::GetLoggedInUsers() const { | 81 const user_manager::UserList& FakeUserManager::GetLoggedInUsers() const { |
79 return logged_in_users_; | 82 return logged_in_users_; |
80 } | 83 } |
81 | 84 |
82 void FakeUserManager::UserLoggedIn(const std::string& email, | 85 void FakeUserManager::UserLoggedIn(const AccountId& account, |
83 const std::string& username_hash, | 86 const std::string& username_hash, |
84 bool browser_restart) { | 87 bool browser_restart) { |
85 for (user_manager::UserList::const_iterator it = users_.begin(); | 88 for (user_manager::UserList::const_iterator it = users_.begin(); |
86 it != users_.end(); ++it) { | 89 it != users_.end(); ++it) { |
87 if ((*it)->username_hash() == username_hash) { | 90 if ((*it)->username_hash() == username_hash) { |
88 (*it)->set_is_logged_in(true); | 91 (*it)->set_is_logged_in(true); |
89 (*it)->set_profile_is_created(); | 92 (*it)->set_profile_is_created(); |
90 logged_in_users_.push_back(*it); | 93 logged_in_users_.push_back(*it); |
91 | 94 |
92 if (!primary_user_) | 95 if (!primary_user_) |
93 primary_user_ = *it; | 96 primary_user_ = *it; |
94 break; | 97 break; |
95 } | 98 } |
96 } | 99 } |
97 } | 100 } |
98 | 101 |
99 user_manager::User* FakeUserManager::GetActiveUserInternal() const { | 102 user_manager::User* FakeUserManager::GetActiveUserInternal() const { |
100 if (users_.size()) { | 103 if (users_.size()) { |
101 if (!active_user_id_.empty()) { | 104 if (!active_user_id_.empty()) { |
102 for (user_manager::UserList::const_iterator it = users_.begin(); | 105 for (user_manager::UserList::const_iterator it = users_.begin(); |
103 it != users_.end(); ++it) { | 106 it != users_.end(); ++it) { |
104 if ((*it)->email() == active_user_id_) | 107 // TODO (alemate): Chenge this to GetUserID(), once a real AccountId is |
108 // passed. | |
109 if ((*it)->GetEmail() == active_user_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) {} |
122 } | |
123 | 127 |
124 void FakeUserManager::SaveUserDisplayName(const std::string& username, | 128 void FakeUserManager::SaveUserDisplayName(const AccountId& user_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 GetUserID(), once a real AccountId is |
133 // passed. | |
134 if ((*it)->GetEmail() == user_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::GetOwnerId() const { |
144 return owner_email_; | 150 return owner_id_; |
145 } | 151 } |
146 | 152 |
147 bool FakeUserManager::IsKnownUser(const std::string& email) const { | 153 bool FakeUserManager::IsKnownUser(const AccountId& account) 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) 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 GetUserID(), once a real AccountId is |
163 // passed. | |
164 if ((*it)->GetEmail() == account.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) { |
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& user_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& user_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 Loading... | |
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) 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& user_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& user_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& user_id) const { |
276 return false; | 284 return false; |
277 } | 285 } |
278 | 286 |
279 } // namespace user_manager | 287 } // namespace user_manager |
OLD | NEW |