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

Side by Side Diff: chrome/browser/chromeos/login/users/fake_chrome_user_manager.cc

Issue 2504513002: Make FakeChromeUserManager subclass of ChromeUserManager (Closed)
Patch Set: Addressed comment Created 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" 5 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/sys_info.h" 9 #include "base/sys_info.h"
10 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" 10 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
11 #include "chrome/browser/chromeos/login/users/chrome_user_manager_util.h" 11 #include "chrome/browser/chromeos/login/users/chrome_user_manager_util.h"
12 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h" 12 #include "chrome/browser/chromeos/login/users/fake_supervised_user_manager.h"
13 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 13 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
14 #include "chrome/browser/chromeos/profiles/profile_helper.h" 14 #include "chrome/browser/chromeos/profiles/profile_helper.h"
15 #include "chrome/browser/chromeos/settings/cros_settings.h" 15 #include "chrome/browser/chromeos/settings/cros_settings.h"
16 #include "chrome/grit/theme_resources.h" 16 #include "chrome/grit/theme_resources.h"
17 #include "chromeos/chromeos_switches.h" 17 #include "chromeos/chromeos_switches.h"
18 #include "chromeos/login/login_state.h" 18 #include "chromeos/login/login_state.h"
19 #include "components/user_manager/user_image/user_image.h" 19 #include "components/user_manager/user_image/user_image.h"
20 #include "components/user_manager/user_names.h" 20 #include "components/user_manager/user_names.h"
21 #include "components/user_manager/user_type.h" 21 #include "components/user_manager/user_type.h"
22 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/gfx/image/image_skia.h" 23 #include "ui/gfx/image/image_skia.h"
24 24
25 namespace {
26
27 class FakeTaskRunner : public base::TaskRunner {
28 public:
29 FakeTaskRunner() = default;
30
31 protected:
32 ~FakeTaskRunner() override {}
33
34 private:
35 // base::TaskRunner overrides.
36 bool PostDelayedTask(const tracked_objects::Location& from_here,
37 const base::Closure& task,
38 base::TimeDelta delay) override {
39 task.Run();
40 return true;
41 }
42 bool RunsTasksOnCurrentThread() const override { return true; }
43
44 DISALLOW_COPY_AND_ASSIGN(FakeTaskRunner);
45 };
46
47 } // namespace
48
25 namespace chromeos { 49 namespace chromeos {
26 50
27 class FakeSupervisedUserManager; 51 class FakeSupervisedUserManager;
28 52
29 FakeChromeUserManager::FakeChromeUserManager() 53 FakeChromeUserManager::FakeChromeUserManager()
30 : supervised_user_manager_(new FakeSupervisedUserManager), 54 : ChromeUserManager(new FakeTaskRunner()),
31 bootstrap_manager_(NULL), 55 supervised_user_manager_(new FakeSupervisedUserManager) {
32 multi_profile_user_controller_(NULL) {
33 ProfileHelper::SetProfileToUserForTestingEnabled(true); 56 ProfileHelper::SetProfileToUserForTestingEnabled(true);
34 } 57 }
35 58
36 FakeChromeUserManager::~FakeChromeUserManager() { 59 FakeChromeUserManager::~FakeChromeUserManager() {
37 ProfileHelper::SetProfileToUserForTestingEnabled(false); 60 ProfileHelper::SetProfileToUserForTestingEnabled(false);
38 } 61 }
39 62
40 const user_manager::User* FakeChromeUserManager::AddUser( 63 const user_manager::User* FakeChromeUserManager::AddUser(
41 const AccountId& account_id) { 64 const AccountId& account_id) {
42 return AddUserWithAffiliation(account_id, false); 65 return AddUserWithAffiliation(account_id, false);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 193
171 void FakeChromeUserManager::OnSessionStarted() {} 194 void FakeChromeUserManager::OnSessionStarted() {}
172 195
173 void FakeChromeUserManager::RemoveUser( 196 void FakeChromeUserManager::RemoveUser(
174 const AccountId& account_id, 197 const AccountId& account_id,
175 user_manager::RemoveUserDelegate* delegate) {} 198 user_manager::RemoveUserDelegate* delegate) {}
176 199
177 void FakeChromeUserManager::RemoveUserFromList(const AccountId& account_id) { 200 void FakeChromeUserManager::RemoveUserFromList(const AccountId& account_id) {
178 WallpaperManager::Get()->RemoveUserWallpaperInfo(account_id); 201 WallpaperManager::Get()->RemoveUserWallpaperInfo(account_id);
179 chromeos::ProfileHelper::Get()->RemoveUserFromListForTesting(account_id); 202 chromeos::ProfileHelper::Get()->RemoveUserFromListForTesting(account_id);
180 FakeUserManager::RemoveUserFromList(account_id); 203
204 const user_manager::UserList::iterator it =
205 std::find_if(users_.begin(), users_.end(),
206 [&account_id](const user_manager::User* user) {
207 return user->GetAccountId() == account_id;
208 });
209 if (it != users_.end()) {
210 if (primary_user_ == *it)
211 primary_user_ = nullptr;
212 if (active_user_ != *it)
213 delete *it;
214 users_.erase(it);
215 }
181 } 216 }
182 217
183 user_manager::UserList 218 user_manager::UserList
184 FakeChromeUserManager::GetUsersAllowedForSupervisedUsersCreation() const { 219 FakeChromeUserManager::GetUsersAllowedForSupervisedUsersCreation() const {
185 CrosSettings* cros_settings = CrosSettings::Get(); 220 CrosSettings* cros_settings = CrosSettings::Get();
186 bool allow_new_user = true; 221 bool allow_new_user = true;
187 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); 222 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user);
188 bool supervised_users_allowed = AreSupervisedUsersAllowed(); 223 bool supervised_users_allowed = AreSupervisedUsersAllowed();
189 224
190 // Restricted either by policy or by owner. 225 // Restricted either by policy or by owner.
191 if (!allow_new_user || !supervised_users_allowed) 226 if (!allow_new_user || !supervised_users_allowed)
192 return user_manager::UserList(); 227 return user_manager::UserList();
193 228
194 return ChromeUserManager::GetUsersAllowedAsSupervisedUserManagers(GetUsers()); 229 return GetUsersAllowedAsSupervisedUserManagers(GetUsers());
195 } 230 }
196 231
197 user_manager::UserList FakeChromeUserManager::GetUsersAllowedForMultiProfile() 232 user_manager::UserList FakeChromeUserManager::GetUsersAllowedForMultiProfile()
198 const { 233 const {
199 // Supervised users are not allowed to use multi-profiles. 234 // Supervised users are not allowed to use multi-profiles.
200 if (GetLoggedInUsers().size() == 1 && 235 if (GetLoggedInUsers().size() == 1 &&
201 GetPrimaryUser()->GetType() != user_manager::USER_TYPE_REGULAR) { 236 GetPrimaryUser()->GetType() != user_manager::USER_TYPE_REGULAR) {
202 return user_manager::UserList(); 237 return user_manager::UserList();
203 } 238 }
204 239
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 std::string* out_resolved_locale) const { 322 std::string* out_resolved_locale) const {
288 NOTIMPLEMENTED(); 323 NOTIMPLEMENTED();
289 return; 324 return;
290 } 325 }
291 326
292 bool FakeChromeUserManager::IsValidDefaultUserImageId(int image_index) const { 327 bool FakeChromeUserManager::IsValidDefaultUserImageId(int image_index) const {
293 NOTIMPLEMENTED(); 328 NOTIMPLEMENTED();
294 return false; 329 return false;
295 } 330 }
296 331
332 // UserManager implementation:
333 void FakeChromeUserManager::Initialize() {
334 return ChromeUserManager::Initialize();
335 }
336
337 void FakeChromeUserManager::Shutdown() {
338 return ChromeUserManager::Shutdown();
339 }
340
341 const user_manager::UserList& FakeChromeUserManager::GetUsers() const {
342 return users_;
343 }
344
345 const user_manager::UserList& FakeChromeUserManager::GetLoggedInUsers() const {
346 return logged_in_users_;
347 }
348
349 const user_manager::UserList& FakeChromeUserManager::GetLRULoggedInUsers()
350 const {
351 return users_;
352 }
353
354 user_manager::UserList FakeChromeUserManager::GetUnlockUsers() const {
355 return users_;
356 }
357
358 void FakeChromeUserManager::UserLoggedIn(const AccountId& account_id,
359 const std::string& username_hash,
360 bool browser_restart) {
361 for (const auto& user : users_) {
362 if (user->username_hash() == username_hash) {
363 user->set_is_logged_in(true);
364 user->set_profile_is_created();
365 logged_in_users_.push_back(user);
366
367 if (!primary_user_)
368 primary_user_ = user;
369 break;
370 }
371 }
372 }
373
374 void FakeChromeUserManager::SwitchToLastActiveUser() {
375 NOTREACHED();
376 }
377
378 bool FakeChromeUserManager::IsKnownUser(const AccountId& account_id) const {
379 return true;
380 }
381
382 const user_manager::User* FakeChromeUserManager::FindUser(
383 const AccountId& account_id) const {
384 if (active_user_ != nullptr && active_user_->GetAccountId() == account_id)
385 return active_user_;
386
387 const user_manager::UserList& users = GetUsers();
388 for (const auto& user : users) {
389 if (user->GetAccountId() == account_id)
390 return user;
391 }
392
393 return nullptr;
394 }
395
396 user_manager::User* FakeChromeUserManager::FindUserAndModify(
397 const AccountId& account_id) {
398 return nullptr;
399 }
400
401 const user_manager::User* FakeChromeUserManager::GetActiveUser() const {
402 return GetActiveUserInternal();
403 }
404
405 user_manager::User* FakeChromeUserManager::GetActiveUser() {
406 return GetActiveUserInternal();
407 }
408
409 const user_manager::User* FakeChromeUserManager::GetPrimaryUser() const {
410 return primary_user_;
411 }
412
413 void FakeChromeUserManager::SaveUserOAuthStatus(
414 const AccountId& account_id,
415 user_manager::User::OAuthTokenStatus oauth_token_status) {
416 NOTREACHED();
417 }
418
419 void FakeChromeUserManager::SaveForceOnlineSignin(const AccountId& account_id,
420 bool force_online_signin) {
421 NOTREACHED();
422 }
423
424 void FakeChromeUserManager::SaveUserDisplayName(
425 const AccountId& account_id,
426 const base::string16& display_name) {
427 for (const auto& user : users_) {
428 if (user->GetAccountId() == account_id) {
429 user->set_display_name(display_name);
430 return;
431 }
432 }
433 }
434
435 base::string16 FakeChromeUserManager::GetUserDisplayName(
436 const AccountId& account_id) const {
437 return base::string16();
438 }
439
440 void FakeChromeUserManager::SaveUserDisplayEmail(
441 const AccountId& account_id,
442 const std::string& display_email) {
443 NOTREACHED();
444 }
445
446 std::string FakeChromeUserManager::GetUserDisplayEmail(
447 const AccountId& account_id) const {
448 return std::string();
449 }
450
451 void FakeChromeUserManager::SaveUserType(
452 const AccountId& account_id,
453 const user_manager::UserType& user_type) {
454 NOTREACHED();
455 }
456
457 void FakeChromeUserManager::UpdateUserAccountData(
458 const AccountId& account_id,
459 const UserAccountData& account_data) {
460 NOTREACHED();
461 }
462
463 bool FakeChromeUserManager::IsCurrentUserOwner() const {
464 return false;
465 }
466
467 bool FakeChromeUserManager::IsCurrentUserNew() const {
468 return false;
469 }
470
471 bool FakeChromeUserManager::IsCurrentUserNonCryptohomeDataEphemeral() const {
472 return false;
473 }
474
475 bool FakeChromeUserManager::CanCurrentUserLock() const {
476 return false;
477 }
478
479 bool FakeChromeUserManager::IsUserLoggedIn() const {
480 return logged_in_users_.size() > 0;
481 }
482
483 bool FakeChromeUserManager::IsLoggedInAsUserWithGaiaAccount() const {
484 return true;
485 }
486
487 bool FakeChromeUserManager::IsLoggedInAsChildUser() const {
488 NOTREACHED();
489 return false;
490 }
491
492 bool FakeChromeUserManager::IsLoggedInAsPublicAccount() const {
493 return false;
494 }
495
496 bool FakeChromeUserManager::IsLoggedInAsGuest() const {
497 return false;
498 }
499
500 bool FakeChromeUserManager::IsLoggedInAsSupervisedUser() const {
501 return false;
502 }
503
504 bool FakeChromeUserManager::IsLoggedInAsKioskApp() const {
505 const user_manager::User* active_user = GetActiveUser();
506 return active_user
507 ? active_user->GetType() == user_manager::USER_TYPE_KIOSK_APP
508 : false;
509 }
510
511 bool FakeChromeUserManager::IsLoggedInAsArcKioskApp() const {
512 const user_manager::User* active_user = GetActiveUser();
513 return active_user
514 ? active_user->GetType() == user_manager::USER_TYPE_ARC_KIOSK_APP
515 : false;
516 }
517
518 bool FakeChromeUserManager::IsLoggedInAsStub() const {
519 return false;
520 }
521
522 bool FakeChromeUserManager::IsUserNonCryptohomeDataEphemeral(
523 const AccountId& account_id) const {
524 return false;
525 }
526
527 void FakeChromeUserManager::AddObserver(UserManager::Observer* obs) {
528 NOTREACHED();
529 }
530
531 void FakeChromeUserManager::RemoveObserver(UserManager::Observer* obs) {
532 NOTREACHED();
533 }
534
535 void FakeChromeUserManager::AddSessionStateObserver(
536 UserManager::UserSessionStateObserver* obs) {}
537
538 void FakeChromeUserManager::RemoveSessionStateObserver(
539 UserManager::UserSessionStateObserver* obs) {}
540
541 void FakeChromeUserManager::NotifyLocalStateChanged() {
542 NOTREACHED();
543 }
544
545 void FakeChromeUserManager::ChangeUserChildStatus(user_manager::User* user,
546 bool is_child) {
547 NOTREACHED();
548 }
549
550 bool FakeChromeUserManager::AreSupervisedUsersAllowed() const {
551 return true;
552 }
553
554 PrefService* FakeChromeUserManager::GetLocalState() const {
555 return nullptr;
556 }
557
558 void FakeChromeUserManager::SetIsCurrentUserNew(bool is_new) {
559 NOTREACHED();
560 }
561
562 const std::string& FakeChromeUserManager::GetApplicationLocale() const {
563 static const std::string default_locale("en-US");
564 return default_locale;
565 }
566
567 void FakeChromeUserManager::HandleUserOAuthTokenStatusChange(
568 const AccountId& account_id,
569 user_manager::User::OAuthTokenStatus status) const {
570 NOTREACHED();
571 }
572
573 void FakeChromeUserManager::LoadDeviceLocalAccounts(
574 std::set<AccountId>* users_set) {
575 NOTREACHED();
576 }
577
578 bool FakeChromeUserManager::IsEnterpriseManaged() const {
579 return false;
580 }
581
582 void FakeChromeUserManager::PerformPreUserListLoadingActions() {
583 NOTREACHED();
584 }
585
586 void FakeChromeUserManager::PerformPostUserListLoadingActions() {
587 NOTREACHED();
588 }
589
590 void FakeChromeUserManager::PerformPostUserLoggedInActions(
591 bool browser_restart) {
592 NOTREACHED();
593 }
594
595 bool FakeChromeUserManager::IsDemoApp(const AccountId& account_id) const {
596 return account_id == user_manager::DemoAccountId();
597 }
598
599 bool FakeChromeUserManager::IsDeviceLocalAccountMarkedForRemoval(
600 const AccountId& account_id) const {
601 return false;
602 }
603
604 void FakeChromeUserManager::DemoAccountLoggedIn() {
605 NOTREACHED();
606 }
607
608 void FakeChromeUserManager::KioskAppLoggedIn(user_manager::User* user) {}
609
610 void FakeChromeUserManager::ArcKioskAppLoggedIn(user_manager::User* user) {}
611
612 void FakeChromeUserManager::PublicAccountUserLoggedIn(
613 user_manager::User* user) {
614 NOTREACHED();
615 }
616
617 void FakeChromeUserManager::SupervisedUserLoggedIn(
618 const AccountId& account_id) {
619 NOTREACHED();
620 }
621
622 void FakeChromeUserManager::OnUserRemoved(const AccountId& account_id) {
623 NOTREACHED();
624 }
625
626 void FakeChromeUserManager::SetUserAffiliation(
627 const std::string& user_email,
628 const AffiliationIDSet& user_affiliation_ids) {}
629
630 bool FakeChromeUserManager::ShouldReportUser(const std::string& user_id) const {
631 return false;
632 }
633
634 user_manager::User* FakeChromeUserManager::GetActiveUserInternal() const {
635 if (active_user_ != nullptr)
636 return active_user_;
637
638 if (users_.empty())
639 return nullptr;
640 if (active_account_id_.is_valid()) {
641 for (const auto& user : users_) {
642 if (user->GetAccountId() == active_account_id_)
643 return user;
644 }
645 }
646 return users_[0];
647 }
648
297 } // namespace chromeos 649 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698