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

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

Issue 1865133002: kiosk: Fix kiosk session restart (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: restore "PublicAccounts" local state Created 4 years, 8 months 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 "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h" 5 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <cstddef> 8 #include <cstddef>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 20 matching lines...) Expand all
31 #include "chrome/browser/chromeos/login/signin/auth_sync_observer.h" 31 #include "chrome/browser/chromeos/login/signin/auth_sync_observer.h"
32 #include "chrome/browser/chromeos/login/signin/auth_sync_observer_factory.h" 32 #include "chrome/browser/chromeos/login/signin/auth_sync_observer_factory.h"
33 #include "chrome/browser/chromeos/login/users/affiliation.h" 33 #include "chrome/browser/chromeos/login/users/affiliation.h"
34 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h" 34 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h"
35 #include "chrome/browser/chromeos/login/users/chrome_user_manager_util.h" 35 #include "chrome/browser/chromeos/login/users/chrome_user_manager_util.h"
36 #include "chrome/browser/chromeos/login/users/default_user_image/default_user_im ages.h" 36 #include "chrome/browser/chromeos/login/users/default_user_image/default_user_im ages.h"
37 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" 37 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h"
38 #include "chrome/browser/chromeos/login/users/supervised_user_manager_impl.h" 38 #include "chrome/browser/chromeos/login/users/supervised_user_manager_impl.h"
39 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 39 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
40 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 40 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
41 #include "chrome/browser/chromeos/policy/device_local_account.h"
42 #include "chrome/browser/chromeos/profiles/multiprofiles_session_aborted_dialog. h" 41 #include "chrome/browser/chromeos/profiles/multiprofiles_session_aborted_dialog. h"
43 #include "chrome/browser/chromeos/profiles/profile_helper.h" 42 #include "chrome/browser/chromeos/profiles/profile_helper.h"
44 #include "chrome/browser/chromeos/session_length_limiter.h" 43 #include "chrome/browser/chromeos/session_length_limiter.h"
45 #include "chrome/browser/chromeos/settings/cros_settings.h" 44 #include "chrome/browser/chromeos/settings/cros_settings.h"
46 #include "chrome/browser/chromeos/system/timezone_util.h" 45 #include "chrome/browser/chromeos/system/timezone_util.h"
47 #include "chrome/browser/profiles/profile.h" 46 #include "chrome/browser/profiles/profile.h"
48 #include "chrome/browser/signin/easy_unlock_service.h" 47 #include "chrome/browser/signin/easy_unlock_service.h"
49 #include "chrome/browser/supervised_user/chromeos/manager_password_service_facto ry.h" 48 #include "chrome/browser/supervised_user/chromeos/manager_password_service_facto ry.h"
50 #include "chrome/browser/supervised_user/chromeos/supervised_user_password_servi ce_factory.h" 49 #include "chrome/browser/supervised_user/chromeos/supervised_user_password_servi ce_factory.h"
51 #include "chrome/common/chrome_constants.h" 50 #include "chrome/common/chrome_constants.h"
(...skipping 28 matching lines...) Expand all
80 79
81 using content::BrowserThread; 80 using content::BrowserThread;
82 81
83 namespace chromeos { 82 namespace chromeos {
84 namespace { 83 namespace {
85 84
86 // A vector pref of the the regular users known on this device, arranged in LRU 85 // A vector pref of the the regular users known on this device, arranged in LRU
87 // order. 86 // order.
88 const char kRegularUsers[] = "LoggedInUsers"; 87 const char kRegularUsers[] = "LoggedInUsers";
89 88
90 // A vector pref of the public accounts defined on this device. 89 // A vector pref of the device local accounts defined on this device.
91 const char kPublicAccounts[] = "PublicAccounts"; 90 const char kDeviceLocalAccounts[] = "PublicAccounts";
92 91
93 // Key for list of users that should be reported. 92 // Key for list of users that should be reported.
94 const char kReportingUsers[] = "reporting_users"; 93 const char kReportingUsers[] = "reporting_users";
95 94
96 // A string pref that gets set when a public account is removed but a user is 95 // A string pref that gets set when a public account is removed but a user is
bartfab (slow) 2016/04/12 15:08:13 Nit: s/public/device local/
xiyuan 2016/04/12 16:22:51 Done.
97 // currently logged into that account, requiring the account's data to be 96 // currently logged into that account, requiring the account's data to be
98 // removed after logout. 97 // removed after logout.
99 const char kPublicAccountPendingDataRemoval[] = 98 const char kDeviceLocalAccountPendingDataRemoval[] =
100 "PublicAccountPendingDataRemoval"; 99 "PublicAccountPendingDataRemoval";
101 100
102 bool FakeOwnership() { 101 bool FakeOwnership() {
103 return base::CommandLine::ForCurrentProcess()->HasSwitch( 102 return base::CommandLine::ForCurrentProcess()->HasSwitch(
104 switches::kStubCrosSettings); 103 switches::kStubCrosSettings);
105 } 104 }
106 105
107 std::string FullyCanonicalize(const std::string& email) { 106 std::string FullyCanonicalize(const std::string& email) {
108 return gaia::CanonicalizeEmail(gaia::SanitizeEmail(email)); 107 return gaia::CanonicalizeEmail(gaia::SanitizeEmail(email));
109 } 108 }
110 109
111 // Callback that is called after user removal is complete. 110 // Callback that is called after user removal is complete.
112 void OnRemoveUserComplete(const AccountId& account_id, 111 void OnRemoveUserComplete(const AccountId& account_id,
113 bool success, 112 bool success,
114 cryptohome::MountError return_code) { 113 cryptohome::MountError return_code) {
115 // Log the error, but there's not much we can do. 114 // Log the error, but there's not much we can do.
116 if (!success) { 115 if (!success) {
117 LOG(ERROR) << "Removal of cryptohome for " << account_id.Serialize() 116 LOG(ERROR) << "Removal of cryptohome for " << account_id.Serialize()
118 << " failed, return code: " << return_code; 117 << " failed, return code: " << return_code;
119 } 118 }
120 } 119 }
121 120
122 // Runs on SequencedWorkerPool thread. Passes resolved locale to UI thread. 121 // Runs on SequencedWorkerPool thread. Passes resolved locale to UI thread.
123 void ResolveLocale(const std::string& raw_locale, 122 void ResolveLocale(const std::string& raw_locale,
124 std::string* resolved_locale) { 123 std::string* resolved_locale) {
125 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale)); 124 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale));
126 } 125 }
127 126
127 bool IsDeviceLocalAccountUser(const user_manager::User* user) {
bartfab (slow) 2016/04/12 15:08:13 This should be a getter on User, where it can be i
xiyuan 2016/04/12 16:22:51 Done.
128 return user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT ||
129 user->GetType() == user_manager::USER_TYPE_KIOSK_APP;
130 }
131
128 } // namespace 132 } // namespace
129 133
130 // static 134 // static
131 void ChromeUserManagerImpl::RegisterPrefs(PrefRegistrySimple* registry) { 135 void ChromeUserManagerImpl::RegisterPrefs(PrefRegistrySimple* registry) {
132 ChromeUserManager::RegisterPrefs(registry); 136 ChromeUserManager::RegisterPrefs(registry);
133 137
134 registry->RegisterListPref(kPublicAccounts); 138 registry->RegisterListPref(kDeviceLocalAccounts);
135 registry->RegisterStringPref(kPublicAccountPendingDataRemoval, std::string()); 139 registry->RegisterStringPref(kDeviceLocalAccountPendingDataRemoval,
140 std::string());
136 registry->RegisterListPref(kReportingUsers); 141 registry->RegisterListPref(kReportingUsers);
137 142
138 SupervisedUserManager::RegisterPrefs(registry); 143 SupervisedUserManager::RegisterPrefs(registry);
139 SessionLengthLimiter::RegisterPrefs(registry); 144 SessionLengthLimiter::RegisterPrefs(registry);
140 BootstrapManager::RegisterPrefs(registry); 145 BootstrapManager::RegisterPrefs(registry);
141 } 146 }
142 147
143 // static 148 // static
144 scoped_ptr<ChromeUserManager> ChromeUserManagerImpl::CreateChromeUserManager() { 149 scoped_ptr<ChromeUserManager> ChromeUserManagerImpl::CreateChromeUserManager() {
145 return scoped_ptr<ChromeUserManager>(new ChromeUserManagerImpl()); 150 return scoped_ptr<ChromeUserManager>(new ChromeUserManagerImpl());
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 user_manager::User::OAuthTokenStatus status) const { 563 user_manager::User::OAuthTokenStatus status) const {
559 GetUserFlow(account_id)->HandleOAuthTokenStatusChange(status); 564 GetUserFlow(account_id)->HandleOAuthTokenStatusChange(status);
560 } 565 }
561 566
562 bool ChromeUserManagerImpl::IsEnterpriseManaged() const { 567 bool ChromeUserManagerImpl::IsEnterpriseManaged() const {
563 policy::BrowserPolicyConnectorChromeOS* connector = 568 policy::BrowserPolicyConnectorChromeOS* connector =
564 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 569 g_browser_process->platform_part()->browser_policy_connector_chromeos();
565 return connector->IsEnterpriseManaged(); 570 return connector->IsEnterpriseManaged();
566 } 571 }
567 572
568 void ChromeUserManagerImpl::LoadPublicAccounts( 573 void ChromeUserManagerImpl::LoadDeviceLocalAccounts(
569 std::set<AccountId>* public_sessions_set) { 574 std::set<AccountId>* device_local_accounts_set) {
570 const base::ListValue* prefs_public_sessions = 575 const base::ListValue* prefs_device_local_accounts =
571 GetLocalState()->GetList(kPublicAccounts); 576 GetLocalState()->GetList(kDeviceLocalAccounts);
572 std::vector<AccountId> public_sessions; 577 std::vector<AccountId> device_local_accounts;
573 ParseUserList(*prefs_public_sessions, std::set<AccountId>(), &public_sessions, 578 ParseUserList(*prefs_device_local_accounts, std::set<AccountId>(),
574 public_sessions_set); 579 &device_local_accounts, device_local_accounts_set);
575 for (const AccountId& account_id : public_sessions) { 580 for (const AccountId& account_id : device_local_accounts) {
576 users_.push_back(user_manager::User::CreatePublicAccountUser(account_id)); 581 policy::DeviceLocalAccount::Type type;
577 UpdatePublicAccountDisplayName(account_id.GetUserEmail()); 582 if (!policy::IsDeviceLocalAccountUser(account_id.GetUserEmail(), &type)) {
583 NOTREACHED();
584 continue;
585 }
586
587 users_.push_back(CreateUserFromDeviceLocalAccount(account_id, type));
588 if (type == policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION)
589 UpdatePublicAccountDisplayName(account_id.GetUserEmail());
578 } 590 }
579 } 591 }
580 592
581 void ChromeUserManagerImpl::PerformPreUserListLoadingActions() { 593 void ChromeUserManagerImpl::PerformPreUserListLoadingActions() {
582 // Clean up user list first. All code down the path should be synchronous, 594 // Clean up user list first. All code down the path should be synchronous,
583 // so that local state after transaction rollback is in consistent state. 595 // so that local state after transaction rollback is in consistent state.
584 // This process also should not trigger EnsureUsersLoaded again. 596 // This process also should not trigger EnsureUsersLoaded again.
585 if (supervised_user_manager_->HasFailedUserCreationTransaction()) 597 if (supervised_user_manager_->HasFailedUserCreationTransaction())
586 supervised_user_manager_->RollbackUserCreationTransaction(); 598 supervised_user_manager_->RollbackUserCreationTransaction();
587 599
(...skipping 14 matching lines...) Expand all
602 // Initialize the session length limiter and start it only if 614 // Initialize the session length limiter and start it only if
603 // session limit is defined by the policy. 615 // session limit is defined by the policy.
604 session_length_limiter_.reset( 616 session_length_limiter_.reset(
605 new SessionLengthLimiter(NULL, browser_restart)); 617 new SessionLengthLimiter(NULL, browser_restart));
606 } 618 }
607 619
608 bool ChromeUserManagerImpl::IsDemoApp(const AccountId& account_id) const { 620 bool ChromeUserManagerImpl::IsDemoApp(const AccountId& account_id) const {
609 return DemoAppLauncher::IsDemoAppSession(account_id); 621 return DemoAppLauncher::IsDemoAppSession(account_id);
610 } 622 }
611 623
612 bool ChromeUserManagerImpl::IsKioskApp(const AccountId& account_id) const {
613 policy::DeviceLocalAccount::Type device_local_account_type;
614 return policy::IsDeviceLocalAccountUser(account_id.GetUserEmail(),
615 &device_local_account_type) &&
616 device_local_account_type ==
617 policy::DeviceLocalAccount::TYPE_KIOSK_APP;
618 }
619
620 bool ChromeUserManagerImpl::IsPublicAccountMarkedForRemoval( 624 bool ChromeUserManagerImpl::IsPublicAccountMarkedForRemoval(
621 const AccountId& account_id) const { 625 const AccountId& account_id) const {
622 return account_id == AccountId::FromUserEmail(GetLocalState()->GetString( 626 return account_id == AccountId::FromUserEmail(GetLocalState()->GetString(
623 kPublicAccountPendingDataRemoval)); 627 kDeviceLocalAccountPendingDataRemoval));
624 } 628 }
625 629
626 void ChromeUserManagerImpl::RetrieveTrustedDevicePolicies() { 630 void ChromeUserManagerImpl::RetrieveTrustedDevicePolicies() {
627 // Local state may not be initialized in unit_tests. 631 // Local state may not be initialized in unit_tests.
628 if (!GetLocalState()) 632 if (!GetLocalState())
629 return; 633 return;
630 634
631 SetEphemeralUsersEnabled(false); 635 SetEphemeralUsersEnabled(false);
632 SetOwnerId(EmptyAccountId()); 636 SetOwnerId(EmptyAccountId());
633 637
634 // Schedule a callback if device policy has not yet been verified. 638 // Schedule a callback if device policy has not yet been verified.
635 if (CrosSettingsProvider::TRUSTED != 639 if (CrosSettingsProvider::TRUSTED !=
636 cros_settings_->PrepareTrustedValues( 640 cros_settings_->PrepareTrustedValues(
637 base::Bind(&ChromeUserManagerImpl::RetrieveTrustedDevicePolicies, 641 base::Bind(&ChromeUserManagerImpl::RetrieveTrustedDevicePolicies,
638 weak_factory_.GetWeakPtr()))) { 642 weak_factory_.GetWeakPtr()))) {
639 return; 643 return;
640 } 644 }
641 645
642 bool ephemeral_users_enabled = false; 646 bool ephemeral_users_enabled = false;
643 cros_settings_->GetBoolean(kAccountsPrefEphemeralUsersEnabled, 647 cros_settings_->GetBoolean(kAccountsPrefEphemeralUsersEnabled,
644 &ephemeral_users_enabled); 648 &ephemeral_users_enabled);
645 SetEphemeralUsersEnabled(ephemeral_users_enabled); 649 SetEphemeralUsersEnabled(ephemeral_users_enabled);
646 650
647 std::string owner_email; 651 std::string owner_email;
648 cros_settings_->GetString(kDeviceOwner, &owner_email); 652 cros_settings_->GetString(kDeviceOwner, &owner_email);
649 SetOwnerId(AccountId::FromUserEmail(owner_email)); 653 SetOwnerId(AccountId::FromUserEmail(owner_email));
650 654
651 EnsureUsersLoaded(); 655 EnsureUsersLoaded();
652 656
653 bool changed = UpdateAndCleanUpPublicAccounts( 657 bool changed = UpdateAndCleanUpDeviceLocalAccounts(
654 policy::GetDeviceLocalAccounts(cros_settings_)); 658 policy::GetDeviceLocalAccounts(cros_settings_));
655 659
656 // If ephemeral users are enabled and we are on the login screen, take this 660 // If ephemeral users are enabled and we are on the login screen, take this
657 // opportunity to clean up by removing all regular users except the owner. 661 // opportunity to clean up by removing all regular users except the owner.
658 if (GetEphemeralUsersEnabled() && !IsUserLoggedIn()) { 662 if (GetEphemeralUsersEnabled() && !IsUserLoggedIn()) {
659 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); 663 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers);
660 prefs_users_update->Clear(); 664 prefs_users_update->Clear();
661 for (user_manager::UserList::iterator it = users_.begin(); 665 for (user_manager::UserList::iterator it = users_.begin();
662 it != users_.end();) { 666 it != users_.end();) {
663 const AccountId account_id = (*it)->GetAccountId(); 667 const AccountId account_id = (*it)->GetAccountId();
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 SetIsCurrentUserNew(true); 783 SetIsCurrentUserNew(true);
780 active_user_ = user; 784 active_user_ = user;
781 785
782 // The UserImageManager chooses a random avatar picture when a user logs in 786 // The UserImageManager chooses a random avatar picture when a user logs in
783 // for the first time. Tell the UserImageManager that this user is not new to 787 // for the first time. Tell the UserImageManager that this user is not new to
784 // prevent the avatar from getting changed. 788 // prevent the avatar from getting changed.
785 GetUserImageManager(user->GetAccountId())->UserLoggedIn(false, true); 789 GetUserImageManager(user->GetAccountId())->UserLoggedIn(false, true);
786 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); 790 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded();
787 } 791 }
788 792
789 void ChromeUserManagerImpl::KioskAppLoggedIn( 793 void ChromeUserManagerImpl::KioskAppLoggedIn(user_manager::User* user) {
790 const AccountId& kiosk_app_account_id) {
791 DCHECK_CURRENTLY_ON(BrowserThread::UI); 794 DCHECK_CURRENTLY_ON(BrowserThread::UI);
792 policy::DeviceLocalAccount::Type device_local_account_type;
793 DCHECK(policy::IsDeviceLocalAccountUser(kiosk_app_account_id.GetUserEmail(),
794 &device_local_account_type));
795 DCHECK_EQ(policy::DeviceLocalAccount::TYPE_KIOSK_APP,
796 device_local_account_type);
797 795
798 active_user_ = user_manager::User::CreateKioskAppUser(kiosk_app_account_id); 796 active_user_ = user;
799 active_user_->SetStubImage( 797 active_user_->SetStubImage(
800 user_manager::UserImage( 798 user_manager::UserImage(
801 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 799 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
802 IDR_PROFILE_PICTURE_LOADING)), 800 IDR_PROFILE_PICTURE_LOADING)),
803 user_manager::User::USER_IMAGE_INVALID, 801 user_manager::User::USER_IMAGE_INVALID,
804 false); 802 false);
805 803
804 const AccountId& kiosk_app_account_id = user->GetAccountId();
806 WallpaperManager::Get()->SetUserWallpaperNow(kiosk_app_account_id); 805 WallpaperManager::Get()->SetUserWallpaperNow(kiosk_app_account_id);
807 806
808 // TODO(bartfab): Add KioskAppUsers to the users_ list and keep metadata like 807 // TODO(bartfab): Add KioskAppUsers to the users_ list and keep metadata like
809 // the kiosk_app_id in these objects, removing the need to re-parse the 808 // the kiosk_app_id in these objects, removing the need to re-parse the
810 // device-local account list here to extract the kiosk_app_id. 809 // device-local account list here to extract the kiosk_app_id.
811 const std::vector<policy::DeviceLocalAccount> device_local_accounts = 810 const std::vector<policy::DeviceLocalAccount> device_local_accounts =
812 policy::GetDeviceLocalAccounts(cros_settings_); 811 policy::GetDeviceLocalAccounts(cros_settings_);
813 const policy::DeviceLocalAccount* account = NULL; 812 const policy::DeviceLocalAccount* account = NULL;
814 for (std::vector<policy::DeviceLocalAccount>::const_iterator it = 813 for (std::vector<policy::DeviceLocalAccount>::const_iterator it =
815 device_local_accounts.begin(); 814 device_local_accounts.begin();
816 it != device_local_accounts.end(); 815 it != device_local_accounts.end();
817 ++it) { 816 ++it) {
818 if (it->user_id == kiosk_app_account_id.GetUserEmail()) { 817 if (it->user_id == kiosk_app_account_id.GetUserEmail()) {
819 account = &*it; 818 account = &*it;
820 break; 819 break;
821 } 820 }
822 } 821 }
823 std::string kiosk_app_name; 822 std::string kiosk_app_id;
824 if (account) { 823 if (account) {
825 kiosk_app_name = account->kiosk_app_id; 824 kiosk_app_id = account->kiosk_app_id;
826 } else { 825 } else {
827 LOG(ERROR) << "Logged into nonexistent kiosk-app account: " 826 LOG(ERROR) << "Logged into nonexistent kiosk-app account: "
828 << kiosk_app_account_id.GetUserEmail(); 827 << kiosk_app_account_id.GetUserEmail();
829 NOTREACHED(); 828 NOTREACHED();
830 } 829 }
831 830
832 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 831 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
833 command_line->AppendSwitch(::switches::kForceAppMode); 832 command_line->AppendSwitch(::switches::kForceAppMode);
834 command_line->AppendSwitchASCII(::switches::kAppId, kiosk_app_name); 833 command_line->AppendSwitchASCII(::switches::kAppId, kiosk_app_id);
835 834
836 // Disable window animation since kiosk app runs in a single full screen 835 // Disable window animation since kiosk app runs in a single full screen
837 // window and window animation causes start-up janks. 836 // window and window animation causes start-up janks.
838 command_line->AppendSwitch(wm::switches::kWindowAnimationsDisabled); 837 command_line->AppendSwitch(wm::switches::kWindowAnimationsDisabled);
839 } 838 }
840 839
841 void ChromeUserManagerImpl::DemoAccountLoggedIn() { 840 void ChromeUserManagerImpl::DemoAccountLoggedIn() {
842 DCHECK_CURRENTLY_ON(BrowserThread::UI); 841 DCHECK_CURRENTLY_ON(BrowserThread::UI);
843 active_user_ = user_manager::User::CreateKioskAppUser(login::DemoAccountId()); 842 active_user_ = user_manager::User::CreateKioskAppUser(login::DemoAccountId());
844 active_user_->SetStubImage( 843 active_user_->SetStubImage(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 WallpaperManager::Get()->RemoveUserWallpaperInfo(account_id); 892 WallpaperManager::Get()->RemoveUserWallpaperInfo(account_id);
894 GetUserImageManager(account_id)->DeleteUserImage(); 893 GetUserImageManager(account_id)->DeleteUserImage();
895 894
896 supervised_user_manager_->RemoveNonCryptohomeData(account_id.GetUserEmail()); 895 supervised_user_manager_->RemoveNonCryptohomeData(account_id.GetUserEmail());
897 896
898 multi_profile_user_controller_->RemoveCachedValues(account_id.GetUserEmail()); 897 multi_profile_user_controller_->RemoveCachedValues(account_id.GetUserEmail());
899 898
900 EasyUnlockService::ResetLocalStateForUser(account_id); 899 EasyUnlockService::ResetLocalStateForUser(account_id);
901 } 900 }
902 901
903 void 902 void ChromeUserManagerImpl::
904 ChromeUserManagerImpl::CleanUpPublicAccountNonCryptohomeDataPendingRemoval() { 903 CleanUpDeviceLocalAccountNonCryptohomeDataPendingRemoval() {
905 PrefService* local_state = GetLocalState(); 904 PrefService* local_state = GetLocalState();
906 const std::string public_account_pending_data_removal = 905 const std::string device_local_account_pending_data_removal =
907 local_state->GetString(kPublicAccountPendingDataRemoval); 906 local_state->GetString(kDeviceLocalAccountPendingDataRemoval);
908 if (public_account_pending_data_removal.empty() || 907 if (device_local_account_pending_data_removal.empty() ||
909 (IsUserLoggedIn() && 908 (IsUserLoggedIn() &&
910 public_account_pending_data_removal == GetActiveUser()->email())) { 909 device_local_account_pending_data_removal == GetActiveUser()->email())) {
911 return; 910 return;
912 } 911 }
913 912
914 RemoveNonCryptohomeData( 913 RemoveNonCryptohomeData(
915 AccountId::FromUserEmail(public_account_pending_data_removal)); 914 AccountId::FromUserEmail(device_local_account_pending_data_removal));
916 local_state->ClearPref(kPublicAccountPendingDataRemoval); 915 local_state->ClearPref(kDeviceLocalAccountPendingDataRemoval);
917 } 916 }
918 917
919 void ChromeUserManagerImpl::CleanUpPublicAccountNonCryptohomeData( 918 void ChromeUserManagerImpl::CleanUpDeviceLocalAccountNonCryptohomeData(
920 const std::vector<std::string>& old_public_accounts) { 919 const std::vector<std::string>& old_public_accounts) {
921 std::set<std::string> users; 920 std::set<std::string> users;
922 for (user_manager::UserList::const_iterator it = users_.begin(); 921 for (user_manager::UserList::const_iterator it = users_.begin();
923 it != users_.end(); 922 it != users_.end();
924 ++it) 923 ++it)
925 users.insert((*it)->email()); 924 users.insert((*it)->email());
926 925
927 // If the user is logged into a public account that has been removed from the 926 // If the user is logged into a public account that has been removed from the
bartfab (slow) 2016/04/12 15:08:13 Nit: s/public/device local/
xiyuan 2016/04/12 16:22:51 Done.
928 // user list, mark the account's data as pending removal after logout. 927 // user list, mark the account's data as pending removal after logout.
929 if (IsLoggedInAsPublicAccount()) { 928 if (IsLoggedInAsPublicAccount()) {
bartfab (slow) 2016/04/12 15:08:13 This will need changing to catch all device-local
xiyuan 2016/04/12 16:22:51 Done.
930 const std::string active_user_id = GetActiveUser()->email(); 929 const std::string active_user_id = GetActiveUser()->email();
931 if (users.find(active_user_id) == users.end()) { 930 if (users.find(active_user_id) == users.end()) {
932 GetLocalState()->SetString(kPublicAccountPendingDataRemoval, 931 GetLocalState()->SetString(kDeviceLocalAccountPendingDataRemoval,
933 active_user_id); 932 active_user_id);
934 users.insert(active_user_id); 933 users.insert(active_user_id);
935 } 934 }
936 } 935 }
937 936
938 // Remove the data belonging to any other public accounts that are no longer 937 // Remove the data belonging to any other public accounts that are no longer
939 // found on the user list. 938 // found on the user list.
940 for (std::vector<std::string>::const_iterator it = 939 for (std::vector<std::string>::const_iterator it =
941 old_public_accounts.begin(); 940 old_public_accounts.begin();
942 it != old_public_accounts.end(); 941 it != old_public_accounts.end();
943 ++it) { 942 ++it) {
944 if (users.find(*it) == users.end()) 943 if (users.find(*it) == users.end())
945 RemoveNonCryptohomeData(AccountId::FromUserEmail(*it)); 944 RemoveNonCryptohomeData(AccountId::FromUserEmail(*it));
946 } 945 }
947 } 946 }
948 947
949 bool ChromeUserManagerImpl::UpdateAndCleanUpPublicAccounts( 948 bool ChromeUserManagerImpl::UpdateAndCleanUpDeviceLocalAccounts(
950 const std::vector<policy::DeviceLocalAccount>& device_local_accounts) { 949 const std::vector<policy::DeviceLocalAccount>& device_local_accounts) {
951 // Try to remove any public account data marked as pending removal. 950 // Try to remove any public account data marked as pending removal.
bartfab (slow) 2016/04/12 15:08:13 Nit: s/public/device local/
xiyuan 2016/04/12 16:22:51 Done.
952 CleanUpPublicAccountNonCryptohomeDataPendingRemoval(); 951 CleanUpDeviceLocalAccountNonCryptohomeDataPendingRemoval();
953 952
954 // Get the current list of public accounts. 953 // Get the current list of device local accounts.
955 std::vector<std::string> old_public_accounts; 954 std::vector<std::string> old_accounts;
956 for (user_manager::UserList::const_iterator it = users_.begin(); 955 for (const auto& user : users_) {
957 it != users_.end(); 956 if (IsDeviceLocalAccountUser(user))
958 ++it) { 957 old_accounts.push_back(user->email());
959 if ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT)
960 old_public_accounts.push_back((*it)->email());
961 } 958 }
962 959
963 // Get the new list of public accounts from policy. 960 // If the list of device local accounts has not changed, return.
964 std::vector<std::string> new_public_accounts; 961 if (device_local_accounts.size() == old_accounts.size()) {
965 for (std::vector<policy::DeviceLocalAccount>::const_iterator it =
966 device_local_accounts.begin();
967 it != device_local_accounts.end();
968 ++it) {
969 // TODO(mnissler, nkostylev, bartfab): Process Kiosk Apps within the
970 // standard login framework: http://crbug.com/234694
971 if (it->type == policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION)
972 new_public_accounts.push_back(it->user_id);
973 }
974
975 // If the list of public accounts has not changed, return.
976 if (new_public_accounts.size() == old_public_accounts.size()) {
977 bool changed = false; 962 bool changed = false;
978 for (size_t i = 0; i < new_public_accounts.size(); ++i) { 963 for (size_t i = 0; i < device_local_accounts.size(); ++i) {
979 if (new_public_accounts[i] != old_public_accounts[i]) { 964 if (device_local_accounts[i].user_id != old_accounts[i]) {
980 changed = true; 965 changed = true;
981 break; 966 break;
982 } 967 }
983 } 968 }
984 if (!changed) 969 if (!changed)
985 return false; 970 return false;
986 } 971 }
987 972
988 // Persist the new list of public accounts in a pref. 973 // Persist the new list of device local accounts in a pref.
989 ListPrefUpdate prefs_public_accounts_update(GetLocalState(), kPublicAccounts); 974 ListPrefUpdate prefs_device_local_accounts_update(GetLocalState(),
990 prefs_public_accounts_update->Clear(); 975 kDeviceLocalAccounts);
991 for (std::vector<std::string>::const_iterator it = 976 prefs_device_local_accounts_update->Clear();
992 new_public_accounts.begin(); 977 for (const auto& account : device_local_accounts)
993 it != new_public_accounts.end(); 978 prefs_device_local_accounts_update->AppendString(account.user_id);
994 ++it) {
995 prefs_public_accounts_update->AppendString(*it);
996 }
997 979
998 // Remove the old public accounts from the user list. 980 // Remove the old device local accounts from the user list.
999 for (user_manager::UserList::iterator it = users_.begin(); 981 for (user_manager::UserList::iterator it = users_.begin();
1000 it != users_.end();) { 982 it != users_.end();) {
1001 if ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT) { 983 if (IsDeviceLocalAccountUser(*it)) {
1002 if (*it != GetLoggedInUser()) 984 if (*it != GetLoggedInUser())
1003 DeleteUser(*it); 985 DeleteUser(*it);
1004 it = users_.erase(it); 986 it = users_.erase(it);
1005 } else { 987 } else {
1006 ++it; 988 ++it;
1007 } 989 }
1008 } 990 }
1009 991
1010 // Add the new public accounts to the front of the user list. 992 // Add the new device local accounts to the front of the user list.
1011 for (std::vector<std::string>::const_reverse_iterator it = 993 const bool is_device_local_account_session =
1012 new_public_accounts.rbegin(); 994 IsLoggedInAsPublicAccount() || IsLoggedInAsKioskApp();
bartfab (slow) 2016/04/12 15:08:13 It would be more future-proof to either create an
xiyuan 2016/04/12 16:22:51 Done.
1013 it != new_public_accounts.rend(); 995 for (auto it = device_local_accounts.rbegin();
1014 ++it) { 996 it != device_local_accounts.rend(); ++it) {
1015 if (IsLoggedInAsPublicAccount() && *it == GetActiveUser()->email()) 997 if (is_device_local_account_session &&
1016 users_.insert(users_.begin(), GetLoggedInUser()); 998 AccountId::FromUserEmail(it->user_id) ==
1017 else 999 GetActiveUser()->GetAccountId()) {
1018 users_.insert(users_.begin(), user_manager::User::CreatePublicAccountUser( 1000 users_.insert(users_.begin(), GetActiveUser());
1019 AccountId::FromUserEmail(*it))); 1001 } else {
1020 UpdatePublicAccountDisplayName(*it); 1002 users_.insert(users_.begin(),
1003 CreateUserFromDeviceLocalAccount(
1004 AccountId::FromUserEmail(it->user_id), it->type));
1005 }
1006 if (it->type == policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION) {
1007 UpdatePublicAccountDisplayName(it->user_id);
1008 }
1021 } 1009 }
1022 1010
1023 for (user_manager::UserList::iterator 1011 for (user_manager::UserList::iterator
1024 ui = users_.begin(), 1012 ui = users_.begin(),
1025 ue = users_.begin() + new_public_accounts.size(); 1013 ue = users_.begin() + device_local_accounts.size();
1026 ui != ue; 1014 ui != ue; ++ui) {
1027 ++ui) {
1028 GetUserImageManager((*ui)->GetAccountId())->LoadUserImage(); 1015 GetUserImageManager((*ui)->GetAccountId())->LoadUserImage();
1029 } 1016 }
1030 1017
1031 // Remove data belonging to public accounts that are no longer found on the 1018 // Remove data belonging to device local accounts that are no longer found on
1032 // user list. 1019 // the user list.
1033 CleanUpPublicAccountNonCryptohomeData(old_public_accounts); 1020 CleanUpDeviceLocalAccountNonCryptohomeData(old_accounts);
1034 1021
1035 return true; 1022 return true;
1036 } 1023 }
1037 1024
1038 void ChromeUserManagerImpl::UpdatePublicAccountDisplayName( 1025 void ChromeUserManagerImpl::UpdatePublicAccountDisplayName(
1039 const std::string& user_id) { 1026 const std::string& user_id) {
1040 std::string display_name; 1027 std::string display_name;
1041 1028
1042 if (device_local_account_policy_service_) { 1029 if (device_local_account_policy_service_) {
1043 policy::DeviceLocalAccountPolicyBroker* broker = 1030 policy::DeviceLocalAccountPolicyBroker* broker =
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 FROM_HERE, 1281 FROM_HERE,
1295 base::Bind(ResolveLocale, locale, base::Unretained(out_resolved_locale)), 1282 base::Bind(ResolveLocale, locale, base::Unretained(out_resolved_locale)),
1296 on_resolved_callback); 1283 on_resolved_callback);
1297 } 1284 }
1298 1285
1299 bool ChromeUserManagerImpl::IsValidDefaultUserImageId(int image_index) const { 1286 bool ChromeUserManagerImpl::IsValidDefaultUserImageId(int image_index) const {
1300 return image_index >= 0 && 1287 return image_index >= 0 &&
1301 image_index < chromeos::default_user_image::kDefaultImagesCount; 1288 image_index < chromeos::default_user_image::kDefaultImagesCount;
1302 } 1289 }
1303 1290
1291 user_manager::User* ChromeUserManagerImpl::CreateUserFromDeviceLocalAccount(
1292 const AccountId& account_id,
1293 const policy::DeviceLocalAccount::Type type) const {
1294 user_manager::User* user = nullptr;
bartfab (slow) 2016/04/12 15:08:13 Nit: Use a unique_ptr.
xiyuan 2016/04/12 16:22:51 Done.
1295 switch (type) {
1296 case policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION:
1297 user = user_manager::User::CreatePublicAccountUser(account_id);
1298 break;
1299 case policy::DeviceLocalAccount::TYPE_KIOSK_APP:
1300 user = user_manager::User::CreateKioskAppUser(account_id);
1301 break;
1302 default:
1303 NOTREACHED();
1304 break;
1305 }
1306
1307 return user;
1308 }
1309
1304 } // namespace chromeos 1310 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698