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

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

Issue 2519823006: Chromad: Add authentication flow (Closed)
Patch Set: Created 4 years 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/user.h" 5 #include "components/user_manager/user.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 UserType GetType() const override; 46 UserType GetType() const override;
47 bool CanSyncImage() const override; 47 bool CanSyncImage() const override;
48 void SetIsChild(bool is_child) override; 48 void SetIsChild(bool is_child) override;
49 49
50 private: 50 private:
51 bool is_child_ = false; 51 bool is_child_ = false;
52 52
53 DISALLOW_COPY_AND_ASSIGN(RegularUser); 53 DISALLOW_COPY_AND_ASSIGN(RegularUser);
54 }; 54 };
55 55
56 class AdUser : public RegularUser {
57 public:
58 explicit AdUser(const AccountId& account_id);
59 ~AdUser() override;
60 // Overridden from User:
61 UserType GetType() const override;
62 };
63
56 class GuestUser : public User { 64 class GuestUser : public User {
57 public: 65 public:
58 explicit GuestUser(const AccountId& guest_account_id); 66 explicit GuestUser(const AccountId& guest_account_id);
59 ~GuestUser() override; 67 ~GuestUser() override;
60 68
61 // Overridden from User: 69 // Overridden from User:
62 UserType GetType() const override; 70 UserType GetType() const override;
63 71
64 private: 72 private:
65 DISALLOW_COPY_AND_ASSIGN(GuestUser); 73 DISALLOW_COPY_AND_ASSIGN(GuestUser);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 if (is_child) { 170 if (is_child) {
163 NOTREACHED() << "Calling SetIsChild(true) for base User class." 171 NOTREACHED() << "Calling SetIsChild(true) for base User class."
164 << "Base class cannot be set as child"; 172 << "Base class cannot be set as child";
165 } 173 }
166 } 174 }
167 175
168 bool User::HasGaiaAccount() const { 176 bool User::HasGaiaAccount() const {
169 return TypeHasGaiaAccount(GetType()); 177 return TypeHasGaiaAccount(GetType());
170 } 178 }
171 179
180 bool User::IsAdUser() const {
181 return GetType() == user_manager::USER_TYPE_AD;
182 }
183
172 bool User::IsSupervised() const { 184 bool User::IsSupervised() const {
173 UserType type = GetType(); 185 UserType type = GetType();
174 return type == USER_TYPE_SUPERVISED || 186 return type == USER_TYPE_SUPERVISED ||
175 type == USER_TYPE_CHILD; 187 type == USER_TYPE_CHILD;
176 } 188 }
177 189
178 std::string User::GetAccountName(bool use_display_email) const { 190 std::string User::GetAccountName(bool use_display_email) const {
179 if (use_display_email && !display_email_.empty()) 191 if (use_display_email && !display_email_.empty())
180 return GetUserName(display_email_); 192 return GetUserName(display_email_);
181 else 193 else
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 228
217 void User::SetAffiliation(bool is_affiliated) { 229 void User::SetAffiliation(bool is_affiliated) {
218 is_affiliated_ = is_affiliated; 230 is_affiliated_ = is_affiliated;
219 } 231 }
220 232
221 bool User::IsDeviceLocalAccount() const { 233 bool User::IsDeviceLocalAccount() const {
222 return false; 234 return false;
223 } 235 }
224 236
225 User* User::CreateRegularUser(const AccountId& account_id) { 237 User* User::CreateRegularUser(const AccountId& account_id) {
238 if (account_id.GetAccountType() == AccountId::kAd)
239 return new AdUser(account_id);
226 return new RegularUser(account_id); 240 return new RegularUser(account_id);
227 } 241 }
228 242
229 User* User::CreateGuestUser(const AccountId& guest_account_id) { 243 User* User::CreateGuestUser(const AccountId& guest_account_id) {
230 return new GuestUser(guest_account_id); 244 return new GuestUser(guest_account_id);
231 } 245 }
232 246
233 User* User::CreateKioskAppUser(const AccountId& kiosk_app_account_id) { 247 User* User::CreateKioskAppUser(const AccountId& kiosk_app_account_id) {
234 return new KioskAppUser(kiosk_app_account_id); 248 return new KioskAppUser(kiosk_app_account_id);
235 } 249 }
(...skipping 28 matching lines...) Expand all
264 278
265 void User::SetStubImage(std::unique_ptr<UserImage> stub_user_image, 279 void User::SetStubImage(std::unique_ptr<UserImage> stub_user_image,
266 int image_index, 280 int image_index,
267 bool is_loading) { 281 bool is_loading) {
268 user_image_ = std::move(stub_user_image); 282 user_image_ = std::move(stub_user_image);
269 image_index_ = image_index; 283 image_index_ = image_index;
270 image_is_stub_ = true; 284 image_is_stub_ = true;
271 image_is_loading_ = is_loading; 285 image_is_loading_ = is_loading;
272 } 286 }
273 287
288 UserType AdUser::GetType() const {
289 return user_manager::USER_TYPE_AD;
290 }
291
274 RegularUser::RegularUser(const AccountId& account_id) : User(account_id) { 292 RegularUser::RegularUser(const AccountId& account_id) : User(account_id) {
275 set_can_lock(true); 293 set_can_lock(true);
276 set_display_email(account_id.GetUserEmail()); 294 set_display_email(account_id.GetUserEmail());
277 } 295 }
278 296
297 AdUser::AdUser(const AccountId& account_id) : RegularUser(account_id) {}
298
279 RegularUser::~RegularUser() { 299 RegularUser::~RegularUser() {
280 } 300 }
281 301
302 AdUser::~AdUser() {}
303
282 UserType RegularUser::GetType() const { 304 UserType RegularUser::GetType() const {
283 return is_child_ ? user_manager::USER_TYPE_CHILD : 305 return is_child_ ? user_manager::USER_TYPE_CHILD :
284 user_manager::USER_TYPE_REGULAR; 306 user_manager::USER_TYPE_REGULAR;
285 } 307 }
286 308
287 bool RegularUser::CanSyncImage() const { 309 bool RegularUser::CanSyncImage() const {
288 return true; 310 return true;
289 } 311 }
290 312
291 void RegularUser::SetIsChild(bool is_child) { 313 void RegularUser::SetIsChild(bool is_child) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 : DeviceLocalAccountUserBase(account_id) {} 391 : DeviceLocalAccountUserBase(account_id) {}
370 392
371 PublicAccountUser::~PublicAccountUser() { 393 PublicAccountUser::~PublicAccountUser() {
372 } 394 }
373 395
374 UserType PublicAccountUser::GetType() const { 396 UserType PublicAccountUser::GetType() const {
375 return user_manager::USER_TYPE_PUBLIC_ACCOUNT; 397 return user_manager::USER_TYPE_PUBLIC_ACCOUNT;
376 } 398 }
377 399
378 bool User::has_gaia_account() const { 400 bool User::has_gaia_account() const {
379 static_assert(user_manager::NUM_USER_TYPES == 8, 401 static_assert(user_manager::NUM_USER_TYPES == 9,
380 "NUM_USER_TYPES should equal 8"); 402 "NUM_USER_TYPES should equal 9");
381 switch (GetType()) { 403 switch (GetType()) {
382 case user_manager::USER_TYPE_REGULAR: 404 case user_manager::USER_TYPE_REGULAR:
383 case user_manager::USER_TYPE_CHILD: 405 case user_manager::USER_TYPE_CHILD:
384 return true; 406 return true;
385 case user_manager::USER_TYPE_GUEST: 407 case user_manager::USER_TYPE_GUEST:
386 case user_manager::USER_TYPE_PUBLIC_ACCOUNT: 408 case user_manager::USER_TYPE_PUBLIC_ACCOUNT:
387 case user_manager::USER_TYPE_SUPERVISED: 409 case user_manager::USER_TYPE_SUPERVISED:
388 case user_manager::USER_TYPE_KIOSK_APP: 410 case user_manager::USER_TYPE_KIOSK_APP:
389 case user_manager::USER_TYPE_ARC_KIOSK_APP: 411 case user_manager::USER_TYPE_ARC_KIOSK_APP:
412 case user_manager::USER_TYPE_AD:
390 return false; 413 return false;
391 default: 414 default:
392 NOTREACHED(); 415 NOTREACHED();
393 } 416 }
394 return false; 417 return false;
395 } 418 }
396 419
397 } // namespace user_manager 420 } // namespace user_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698