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 14 matching lines...) Expand all Loading... |
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), |
35 owner_email_(std::string()) { | 35 owner_id_(UserID(std::string() /* gaia_id */, std::string() /* user_email
*/)) { |
36 } | 36 } |
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 user_manager::UserID& u
ser_id) { |
42 user_manager::User* user = user_manager::User::CreateRegularUser(email); | 42 user_manager::User* user = user_manager::User::CreateRegularUser(user_id); |
43 users_.push_back(user); | 43 users_.push_back(user); |
44 return user; | 44 return user; |
45 } | 45 } |
46 | 46 |
47 void FakeUserManager::RemoveUserFromList(const std::string& email) { | 47 void FakeUserManager::RemoveUserFromList(const UserID& user_id) { |
48 user_manager::UserList::iterator it = users_.begin(); | 48 user_manager::UserList::iterator it = users_.begin(); |
49 while (it != users_.end() && (*it)->email() != email) | 49 while (it != users_.end() && (*it)->GetUserID() != user_id) |
50 ++it; | 50 ++it; |
51 if (it != users_.end()) { | 51 if (it != users_.end()) { |
52 delete *it; | 52 delete *it; |
53 users_.erase(it); | 53 users_.erase(it); |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 const user_manager::UserList& FakeUserManager::GetUsers() const { | 57 const user_manager::UserList& FakeUserManager::GetUsers() const { |
58 return users_; | 58 return users_; |
59 } | 59 } |
60 | 60 |
61 user_manager::UserList FakeUserManager::GetUsersAllowedForMultiProfile() const { | 61 user_manager::UserList FakeUserManager::GetUsersAllowedForMultiProfile() const { |
62 user_manager::UserList result; | 62 user_manager::UserList result; |
63 for (user_manager::UserList::const_iterator it = users_.begin(); | 63 for (user_manager::UserList::const_iterator it = users_.begin(); |
64 it != users_.end(); ++it) { | 64 it != users_.end(); ++it) { |
65 if ((*it)->GetType() == user_manager::USER_TYPE_REGULAR && | 65 if ((*it)->GetType() == user_manager::USER_TYPE_REGULAR && |
66 !(*it)->is_logged_in()) | 66 !(*it)->is_logged_in()) |
67 result.push_back(*it); | 67 result.push_back(*it); |
68 } | 68 } |
69 return result; | 69 return result; |
70 } | 70 } |
71 | 71 |
72 const user_manager::UserList& FakeUserManager::GetLoggedInUsers() const { | 72 const user_manager::UserList& FakeUserManager::GetLoggedInUsers() const { |
73 return logged_in_users_; | 73 return logged_in_users_; |
74 } | 74 } |
75 | 75 |
76 void FakeUserManager::UserLoggedIn(const std::string& email, | 76 void FakeUserManager::UserLoggedIn(const UserId& user_id, |
77 const std::string& username_hash, | 77 const std::string& username_hash, |
78 bool browser_restart) { | 78 bool browser_restart) { |
79 for (user_manager::UserList::const_iterator it = users_.begin(); | 79 for (user_manager::UserList::const_iterator it = users_.begin(); |
80 it != users_.end(); ++it) { | 80 it != users_.end(); ++it) { |
81 if ((*it)->username_hash() == username_hash) { | 81 if ((*it)->username_hash() == username_hash) { |
82 (*it)->set_is_logged_in(true); | 82 (*it)->set_is_logged_in(true); |
83 (*it)->set_profile_is_created(); | 83 (*it)->set_profile_is_created(); |
84 logged_in_users_.push_back(*it); | 84 logged_in_users_.push_back(*it); |
85 | 85 |
86 if (!primary_user_) | 86 if (!primary_user_) |
87 primary_user_ = *it; | 87 primary_user_ = *it; |
88 break; | 88 break; |
89 } | 89 } |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 user_manager::User* FakeUserManager::GetActiveUserInternal() const { | 93 user_manager::User* FakeUserManager::GetActiveUserInternal() const { |
94 if (users_.size()) { | 94 if (users_.size()) { |
95 if (!active_user_id_.empty()) { | 95 if (!active_user_id_.empty()) { |
96 for (user_manager::UserList::const_iterator it = users_.begin(); | 96 for (user_manager::UserList::const_iterator it = users_.begin(); |
97 it != users_.end(); ++it) { | 97 it != users_.end(); ++it) { |
98 if ((*it)->email() == active_user_id_) | 98 if ((*it)->GetUserID() == active_user_id_) |
99 return *it; | 99 return *it; |
100 } | 100 } |
101 } | 101 } |
102 return users_[0]; | 102 return users_[0]; |
103 } | 103 } |
104 return NULL; | 104 return NULL; |
105 } | 105 } |
106 | 106 |
107 const user_manager::User* FakeUserManager::GetActiveUser() const { | 107 const user_manager::User* FakeUserManager::GetActiveUser() const { |
108 return GetActiveUserInternal(); | 108 return GetActiveUserInternal(); |
109 } | 109 } |
110 | 110 |
111 user_manager::User* FakeUserManager::GetActiveUser() { | 111 user_manager::User* FakeUserManager::GetActiveUser() { |
112 return GetActiveUserInternal(); | 112 return GetActiveUserInternal(); |
113 } | 113 } |
114 | 114 |
115 void FakeUserManager::SwitchActiveUser(const std::string& email) { | 115 void FakeUserManager::SwitchActiveUser(const UserID& user_id) { |
116 } | 116 } |
117 | 117 |
118 void FakeUserManager::SaveUserDisplayName(const std::string& username, | 118 void FakeUserManager::SaveUserDisplayName(const UserID& user_id, |
119 const base::string16& display_name) { | 119 const base::string16& display_name) { |
120 for (user_manager::UserList::iterator it = users_.begin(); it != users_.end(); | 120 for (user_manager::UserList::iterator it = users_.begin(); it != users_.end(); |
121 ++it) { | 121 ++it) { |
122 if ((*it)->email() == username) { | 122 if ((*it)->GetUserID() == user_id) { |
123 (*it)->set_display_name(display_name); | 123 (*it)->set_display_name(display_name); |
124 return; | 124 return; |
125 } | 125 } |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 const user_manager::UserList& FakeUserManager::GetLRULoggedInUsers() const { | 129 const user_manager::UserList& FakeUserManager::GetLRULoggedInUsers() const { |
130 return users_; | 130 return users_; |
131 } | 131 } |
132 | 132 |
133 user_manager::UserList FakeUserManager::GetUnlockUsers() const { | 133 user_manager::UserList FakeUserManager::GetUnlockUsers() const { |
134 return users_; | 134 return users_; |
135 } | 135 } |
136 | 136 |
137 const std::string& FakeUserManager::GetOwnerEmail() const { | 137 const user_manager::UserID& FakeUserManager::GetOwnerID() const { |
138 return owner_email_; | 138 return owner_id_; |
139 } | 139 } |
140 | 140 |
141 bool FakeUserManager::IsKnownUser(const std::string& email) const { | 141 bool FakeUserManager::IsKnownUser(const UserID& user_id) const { |
142 return true; | 142 return true; |
143 } | 143 } |
144 | 144 |
145 const user_manager::User* FakeUserManager::FindUser( | 145 const user_manager::User* FakeUserManager::FindUser( |
146 const std::string& email) const { | 146 const UserID& user_id) const { |
147 const user_manager::UserList& users = GetUsers(); | 147 const user_manager::UserList& users = GetUsers(); |
148 for (user_manager::UserList::const_iterator it = users.begin(); | 148 for (user_manager::UserList::const_iterator it = users.begin(); |
149 it != users.end(); ++it) { | 149 it != users.end(); ++it) { |
150 if ((*it)->email() == email) | 150 if ((*it)->GetUserID() == user_id) |
151 return *it; | 151 return *it; |
152 } | 152 } |
153 return NULL; | 153 return NULL; |
154 } | 154 } |
155 | 155 |
156 user_manager::User* FakeUserManager::FindUserAndModify( | 156 user_manager::User* FakeUserManager::FindUserAndModify( |
157 const std::string& email) { | 157 const const UserID& user_id) { |
158 return NULL; | 158 return NULL; |
159 } | 159 } |
160 | 160 |
161 const user_manager::User* FakeUserManager::GetLoggedInUser() const { | 161 const user_manager::User* FakeUserManager::GetLoggedInUser() const { |
162 return NULL; | 162 return NULL; |
163 } | 163 } |
164 | 164 |
165 user_manager::User* FakeUserManager::GetLoggedInUser() { | 165 user_manager::User* FakeUserManager::GetLoggedInUser() { |
166 return NULL; | 166 return NULL; |
167 } | 167 } |
168 | 168 |
169 const user_manager::User* FakeUserManager::GetPrimaryUser() const { | 169 const user_manager::User* FakeUserManager::GetPrimaryUser() const { |
170 return primary_user_; | 170 return primary_user_; |
171 } | 171 } |
172 | 172 |
173 base::string16 FakeUserManager::GetUserDisplayName( | 173 base::string16 FakeUserManager::GetUserDisplayName( |
174 const std::string& username) const { | 174 const UserID& user_id) const { |
175 return base::string16(); | 175 return base::string16(); |
176 } | 176 } |
177 | 177 |
178 std::string FakeUserManager::GetUserDisplayEmail( | 178 std::string FakeUserManager::GetUserDisplayEmail( |
179 const std::string& username) const { | 179 const user_manager::UserID& user_id) const { |
180 return std::string(); | 180 return std::string(); |
181 } | 181 } |
182 | 182 |
183 bool FakeUserManager::IsCurrentUserOwner() const { | 183 bool FakeUserManager::IsCurrentUserOwner() const { |
184 return false; | 184 return false; |
185 } | 185 } |
186 | 186 |
187 bool FakeUserManager::IsCurrentUserNew() const { | 187 bool FakeUserManager::IsCurrentUserNew() const { |
188 return false; | 188 return false; |
189 } | 189 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 225 |
226 bool FakeUserManager::IsLoggedInAsStub() const { | 226 bool FakeUserManager::IsLoggedInAsStub() const { |
227 return false; | 227 return false; |
228 } | 228 } |
229 | 229 |
230 bool FakeUserManager::IsSessionStarted() const { | 230 bool FakeUserManager::IsSessionStarted() const { |
231 return false; | 231 return false; |
232 } | 232 } |
233 | 233 |
234 bool FakeUserManager::IsUserNonCryptohomeDataEphemeral( | 234 bool FakeUserManager::IsUserNonCryptohomeDataEphemeral( |
235 const std::string& email) const { | 235 const UserID& user_id) const { |
236 return false; | 236 return false; |
237 } | 237 } |
238 | 238 |
239 bool FakeUserManager::AreSupervisedUsersAllowed() const { | 239 bool FakeUserManager::AreSupervisedUsersAllowed() const { |
240 return true; | 240 return true; |
241 } | 241 } |
242 | 242 |
243 bool FakeUserManager::AreEphemeralUsersEnabled() const { | 243 bool FakeUserManager::AreEphemeralUsersEnabled() const { |
244 return false; | 244 return false; |
245 } | 245 } |
246 | 246 |
247 const std::string& FakeUserManager::GetApplicationLocale() const { | 247 const std::string& FakeUserManager::GetApplicationLocale() const { |
248 static const std::string default_locale("en-US"); | 248 static const std::string default_locale("en-US"); |
249 return default_locale; | 249 return default_locale; |
250 } | 250 } |
251 | 251 |
252 PrefService* FakeUserManager::GetLocalState() const { | 252 PrefService* FakeUserManager::GetLocalState() const { |
253 return NULL; | 253 return NULL; |
254 } | 254 } |
255 | 255 |
256 bool FakeUserManager::IsEnterpriseManaged() const { | 256 bool FakeUserManager::IsEnterpriseManaged() const { |
257 return false; | 257 return false; |
258 } | 258 } |
259 | 259 |
260 bool FakeUserManager::IsDemoApp(const std::string& user_id) const { | 260 bool FakeUserManager::IsDemoApp(const UserID& user_id) const { |
261 return false; | 261 return false; |
262 } | 262 } |
263 | 263 |
264 bool FakeUserManager::IsKioskApp(const std::string& user_id) const { | 264 bool FakeUserManager::IsKioskApp(const UserID& user_id) const { |
265 return false; | 265 return false; |
266 } | 266 } |
267 | 267 |
268 bool FakeUserManager::IsPublicAccountMarkedForRemoval( | 268 bool FakeUserManager::IsPublicAccountMarkedForRemoval( |
269 const std::string& user_id) const { | 269 const UserID& user_id) const { |
270 return false; | 270 return false; |
271 } | 271 } |
272 | 272 |
273 } // namespace user_manager | 273 } // namespace user_manager |
OLD | NEW |