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