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_(nullptr) {} | 34 primary_user_(NULL), |
| 35 owner_email_(std::string()) { |
| 36 } |
35 | 37 |
36 FakeUserManager::~FakeUserManager() { | 38 FakeUserManager::~FakeUserManager() { |
37 } | 39 } |
38 | 40 |
39 const user_manager::User* FakeUserManager::AddUser( | 41 const user_manager::User* FakeUserManager::AddUser(const std::string& email) { |
40 const AccountId& account_id) { | 42 return AddUserWithAffiliation(email, false); |
41 return AddUserWithAffiliation(account_id, false); | |
42 } | 43 } |
43 | 44 |
44 const user_manager::User* FakeUserManager::AddUserWithAffiliation( | 45 const user_manager::User* FakeUserManager::AddUserWithAffiliation( |
45 const AccountId& account_id, | 46 const std::string& email, bool is_affiliated) { |
46 bool is_affiliated) { | 47 user_manager::User* user = user_manager::User::CreateRegularUser(email); |
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 AccountId& account_id) { | 53 void FakeUserManager::RemoveUserFromList(const std::string& email) { |
54 user_manager::UserList::iterator it = users_.begin(); | 54 user_manager::UserList::iterator it = users_.begin(); |
55 // TODO (alemate): Chenge this to GetAccountId(), once a real AccountId is | 55 while (it != users_.end() && (*it)->email() != email) |
56 // passed. crbug.com/546876 | |
57 while (it != users_.end() && (*it)->GetEmail() != account_id.GetUserEmail()) | |
58 ++it; | 56 ++it; |
59 if (it != users_.end()) { | 57 if (it != users_.end()) { |
60 delete *it; | 58 delete *it; |
61 users_.erase(it); | 59 users_.erase(it); |
62 } | 60 } |
63 } | 61 } |
64 | 62 |
65 const user_manager::UserList& FakeUserManager::GetUsers() const { | 63 const user_manager::UserList& FakeUserManager::GetUsers() const { |
66 return users_; | 64 return users_; |
67 } | 65 } |
68 | 66 |
69 user_manager::UserList FakeUserManager::GetUsersAllowedForMultiProfile() const { | 67 user_manager::UserList FakeUserManager::GetUsersAllowedForMultiProfile() const { |
70 user_manager::UserList result; | 68 user_manager::UserList result; |
71 for (user_manager::UserList::const_iterator it = users_.begin(); | 69 for (user_manager::UserList::const_iterator it = users_.begin(); |
72 it != users_.end(); ++it) { | 70 it != users_.end(); ++it) { |
73 if ((*it)->GetType() == user_manager::USER_TYPE_REGULAR && | 71 if ((*it)->GetType() == user_manager::USER_TYPE_REGULAR && |
74 !(*it)->is_logged_in()) | 72 !(*it)->is_logged_in()) |
75 result.push_back(*it); | 73 result.push_back(*it); |
76 } | 74 } |
77 return result; | 75 return result; |
78 } | 76 } |
79 | 77 |
80 const user_manager::UserList& FakeUserManager::GetLoggedInUsers() const { | 78 const user_manager::UserList& FakeUserManager::GetLoggedInUsers() const { |
81 return logged_in_users_; | 79 return logged_in_users_; |
82 } | 80 } |
83 | 81 |
84 void FakeUserManager::UserLoggedIn(const AccountId& account_id, | 82 void FakeUserManager::UserLoggedIn(const std::string& email, |
85 const std::string& username_hash, | 83 const std::string& username_hash, |
86 bool browser_restart) { | 84 bool browser_restart) { |
87 for (user_manager::UserList::const_iterator it = users_.begin(); | 85 for (user_manager::UserList::const_iterator it = users_.begin(); |
88 it != users_.end(); ++it) { | 86 it != users_.end(); ++it) { |
89 if ((*it)->username_hash() == username_hash) { | 87 if ((*it)->username_hash() == username_hash) { |
90 (*it)->set_is_logged_in(true); | 88 (*it)->set_is_logged_in(true); |
91 (*it)->set_profile_is_created(); | 89 (*it)->set_profile_is_created(); |
92 logged_in_users_.push_back(*it); | 90 logged_in_users_.push_back(*it); |
93 | 91 |
94 if (!primary_user_) | 92 if (!primary_user_) |
95 primary_user_ = *it; | 93 primary_user_ = *it; |
96 break; | 94 break; |
97 } | 95 } |
98 } | 96 } |
99 } | 97 } |
100 | 98 |
101 user_manager::User* FakeUserManager::GetActiveUserInternal() const { | 99 user_manager::User* FakeUserManager::GetActiveUserInternal() const { |
102 if (!users_.empty()) { | 100 if (users_.size()) { |
103 if (active_account_id_.is_valid()) { | 101 if (!active_user_id_.empty()) { |
104 for (user_manager::UserList::const_iterator it = users_.begin(); | 102 for (user_manager::UserList::const_iterator it = users_.begin(); |
105 it != users_.end(); ++it) { | 103 it != users_.end(); ++it) { |
106 // TODO (alemate): Chenge this to GetAccountId(), once a real AccountId | 104 if ((*it)->email() == active_user_id_) |
107 // is | |
108 // passed. crbug.com/546876 | |
109 if ((*it)->GetEmail() == active_account_id_.GetUserEmail()) | |
110 return *it; | 105 return *it; |
111 } | 106 } |
112 } | 107 } |
113 return users_[0]; | 108 return users_[0]; |
114 } | 109 } |
115 return nullptr; | 110 return NULL; |
116 } | 111 } |
117 | 112 |
118 const user_manager::User* FakeUserManager::GetActiveUser() const { | 113 const user_manager::User* FakeUserManager::GetActiveUser() const { |
119 return GetActiveUserInternal(); | 114 return GetActiveUserInternal(); |
120 } | 115 } |
121 | 116 |
122 user_manager::User* FakeUserManager::GetActiveUser() { | 117 user_manager::User* FakeUserManager::GetActiveUser() { |
123 return GetActiveUserInternal(); | 118 return GetActiveUserInternal(); |
124 } | 119 } |
125 | 120 |
126 void FakeUserManager::SwitchActiveUser(const AccountId& account_id) {} | 121 void FakeUserManager::SwitchActiveUser(const std::string& email) { |
| 122 } |
127 | 123 |
128 void FakeUserManager::SaveUserDisplayName(const AccountId& account_id, | 124 void FakeUserManager::SaveUserDisplayName(const std::string& username, |
129 const base::string16& display_name) { | 125 const base::string16& display_name) { |
130 for (user_manager::UserList::iterator it = users_.begin(); it != users_.end(); | 126 for (user_manager::UserList::iterator it = users_.begin(); it != users_.end(); |
131 ++it) { | 127 ++it) { |
132 // TODO (alemate): Chenge this to GetAccountId(), once a real AccountId is | 128 if ((*it)->email() == username) { |
133 // passed. crbug.com/546876 | |
134 if ((*it)->GetEmail() == account_id.GetUserEmail()) { | |
135 (*it)->set_display_name(display_name); | 129 (*it)->set_display_name(display_name); |
136 return; | 130 return; |
137 } | 131 } |
138 } | 132 } |
139 } | 133 } |
140 | 134 |
141 const user_manager::UserList& FakeUserManager::GetLRULoggedInUsers() const { | 135 const user_manager::UserList& FakeUserManager::GetLRULoggedInUsers() const { |
142 return users_; | 136 return users_; |
143 } | 137 } |
144 | 138 |
145 user_manager::UserList FakeUserManager::GetUnlockUsers() const { | 139 user_manager::UserList FakeUserManager::GetUnlockUsers() const { |
146 return users_; | 140 return users_; |
147 } | 141 } |
148 | 142 |
149 const AccountId& FakeUserManager::GetOwnerAccountId() const { | 143 const std::string& FakeUserManager::GetOwnerEmail() const { |
150 return owner_account_id_; | 144 return owner_email_; |
151 } | 145 } |
152 | 146 |
153 bool FakeUserManager::IsKnownUser(const AccountId& account_id) const { | 147 bool FakeUserManager::IsKnownUser(const std::string& email) const { |
154 return true; | 148 return true; |
155 } | 149 } |
156 | 150 |
157 const user_manager::User* FakeUserManager::FindUser( | 151 const user_manager::User* FakeUserManager::FindUser( |
158 const AccountId& account_id) const { | 152 const std::string& email) const { |
159 const user_manager::UserList& users = GetUsers(); | 153 const user_manager::UserList& users = GetUsers(); |
160 for (user_manager::UserList::const_iterator it = users.begin(); | 154 for (user_manager::UserList::const_iterator it = users.begin(); |
161 it != users.end(); ++it) { | 155 it != users.end(); ++it) { |
162 // TODO (alemate): Chenge this to GetAccountId(), once a real AccountId is | 156 if ((*it)->email() == email) |
163 // passed. crbug.com/546876 | |
164 if ((*it)->GetEmail() == account_id.GetUserEmail()) | |
165 return *it; | 157 return *it; |
166 } | 158 } |
167 return nullptr; | 159 return NULL; |
168 } | 160 } |
169 | 161 |
170 user_manager::User* FakeUserManager::FindUserAndModify( | 162 user_manager::User* FakeUserManager::FindUserAndModify( |
171 const AccountId& account_id) { | 163 const std::string& email) { |
172 return nullptr; | 164 return NULL; |
173 } | 165 } |
174 | 166 |
175 const user_manager::User* FakeUserManager::GetLoggedInUser() const { | 167 const user_manager::User* FakeUserManager::GetLoggedInUser() const { |
176 return nullptr; | 168 return NULL; |
177 } | 169 } |
178 | 170 |
179 user_manager::User* FakeUserManager::GetLoggedInUser() { | 171 user_manager::User* FakeUserManager::GetLoggedInUser() { |
180 return nullptr; | 172 return NULL; |
181 } | 173 } |
182 | 174 |
183 const user_manager::User* FakeUserManager::GetPrimaryUser() const { | 175 const user_manager::User* FakeUserManager::GetPrimaryUser() const { |
184 return primary_user_; | 176 return primary_user_; |
185 } | 177 } |
186 | 178 |
187 base::string16 FakeUserManager::GetUserDisplayName( | 179 base::string16 FakeUserManager::GetUserDisplayName( |
188 const AccountId& account_id) const { | 180 const std::string& username) const { |
189 return base::string16(); | 181 return base::string16(); |
190 } | 182 } |
191 | 183 |
192 std::string FakeUserManager::GetUserDisplayEmail( | 184 std::string FakeUserManager::GetUserDisplayEmail( |
193 const AccountId& account_id) const { | 185 const std::string& username) const { |
194 return std::string(); | 186 return std::string(); |
195 } | 187 } |
196 | 188 |
197 bool FakeUserManager::IsCurrentUserOwner() const { | 189 bool FakeUserManager::IsCurrentUserOwner() const { |
198 return false; | 190 return false; |
199 } | 191 } |
200 | 192 |
201 bool FakeUserManager::IsCurrentUserNew() const { | 193 bool FakeUserManager::IsCurrentUserNew() const { |
202 return false; | 194 return false; |
203 } | 195 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 231 |
240 bool FakeUserManager::IsLoggedInAsStub() const { | 232 bool FakeUserManager::IsLoggedInAsStub() const { |
241 return false; | 233 return false; |
242 } | 234 } |
243 | 235 |
244 bool FakeUserManager::IsSessionStarted() const { | 236 bool FakeUserManager::IsSessionStarted() const { |
245 return false; | 237 return false; |
246 } | 238 } |
247 | 239 |
248 bool FakeUserManager::IsUserNonCryptohomeDataEphemeral( | 240 bool FakeUserManager::IsUserNonCryptohomeDataEphemeral( |
249 const AccountId& account_id) const { | 241 const std::string& email) const { |
250 return false; | 242 return false; |
251 } | 243 } |
252 | 244 |
253 bool FakeUserManager::AreSupervisedUsersAllowed() const { | 245 bool FakeUserManager::AreSupervisedUsersAllowed() const { |
254 return true; | 246 return true; |
255 } | 247 } |
256 | 248 |
257 bool FakeUserManager::AreEphemeralUsersEnabled() const { | 249 bool FakeUserManager::AreEphemeralUsersEnabled() const { |
258 return false; | 250 return false; |
259 } | 251 } |
260 | 252 |
261 const std::string& FakeUserManager::GetApplicationLocale() const { | 253 const std::string& FakeUserManager::GetApplicationLocale() const { |
262 static const std::string default_locale("en-US"); | 254 static const std::string default_locale("en-US"); |
263 return default_locale; | 255 return default_locale; |
264 } | 256 } |
265 | 257 |
266 PrefService* FakeUserManager::GetLocalState() const { | 258 PrefService* FakeUserManager::GetLocalState() const { |
267 return nullptr; | 259 return NULL; |
268 } | 260 } |
269 | 261 |
270 bool FakeUserManager::IsEnterpriseManaged() const { | 262 bool FakeUserManager::IsEnterpriseManaged() const { |
271 return false; | 263 return false; |
272 } | 264 } |
273 | 265 |
274 bool FakeUserManager::IsDemoApp(const AccountId& account_id) const { | 266 bool FakeUserManager::IsDemoApp(const std::string& user_id) const { |
275 return false; | 267 return false; |
276 } | 268 } |
277 | 269 |
278 bool FakeUserManager::IsKioskApp(const AccountId& account_id) const { | 270 bool FakeUserManager::IsKioskApp(const std::string& user_id) const { |
279 return false; | 271 return false; |
280 } | 272 } |
281 | 273 |
282 bool FakeUserManager::IsPublicAccountMarkedForRemoval( | 274 bool FakeUserManager::IsPublicAccountMarkedForRemoval( |
283 const AccountId& account_id) const { | 275 const std::string& user_id) const { |
284 return false; | 276 return false; |
285 } | 277 } |
286 | 278 |
287 } // namespace user_manager | 279 } // namespace user_manager |
OLD | NEW |