Chromium Code Reviews| 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 #include <cstddef> | 8 #include <cstddef> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 | 80 |
| 81 using content::BrowserThread; | 81 using content::BrowserThread; |
| 82 | 82 |
| 83 namespace chromeos { | 83 namespace chromeos { |
| 84 namespace { | 84 namespace { |
| 85 | 85 |
| 86 // A vector pref of the the regular users known on this device, arranged in LRU | 86 // A vector pref of the the regular users known on this device, arranged in LRU |
| 87 // order. | 87 // order. |
| 88 const char kRegularUsers[] = "LoggedInUsers"; | 88 const char kRegularUsers[] = "LoggedInUsers"; |
| 89 | 89 |
| 90 // A vector pref of the public accounts defined on this device. | |
| 91 const char kPublicAccounts[] = "PublicAccounts"; | |
| 92 | |
| 93 // Key for list of users that should be reported. | 90 // Key for list of users that should be reported. |
| 94 const char kReportingUsers[] = "reporting_users"; | 91 const char kReportingUsers[] = "reporting_users"; |
| 95 | 92 |
| 96 // A string pref that gets set when a public account is removed but a user is | 93 // A string pref that gets set when a public account is removed but a user is |
| 97 // currently logged into that account, requiring the account's data to be | 94 // currently logged into that account, requiring the account's data to be |
| 98 // removed after logout. | 95 // removed after logout. |
| 99 const char kPublicAccountPendingDataRemoval[] = | 96 const char kPublicAccountPendingDataRemoval[] = |
| 100 "PublicAccountPendingDataRemoval"; | 97 "PublicAccountPendingDataRemoval"; |
| 101 | 98 |
| 102 bool FakeOwnership() { | 99 bool FakeOwnership() { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 124 std::string* resolved_locale) { | 121 std::string* resolved_locale) { |
| 125 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale)); | 122 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale)); |
| 126 } | 123 } |
| 127 | 124 |
| 128 } // namespace | 125 } // namespace |
| 129 | 126 |
| 130 // static | 127 // static |
| 131 void ChromeUserManagerImpl::RegisterPrefs(PrefRegistrySimple* registry) { | 128 void ChromeUserManagerImpl::RegisterPrefs(PrefRegistrySimple* registry) { |
| 132 ChromeUserManager::RegisterPrefs(registry); | 129 ChromeUserManager::RegisterPrefs(registry); |
| 133 | 130 |
| 134 registry->RegisterListPref(kPublicAccounts); | |
| 135 registry->RegisterStringPref(kPublicAccountPendingDataRemoval, std::string()); | 131 registry->RegisterStringPref(kPublicAccountPendingDataRemoval, std::string()); |
| 136 registry->RegisterListPref(kReportingUsers); | 132 registry->RegisterListPref(kReportingUsers); |
| 137 | 133 |
| 138 SupervisedUserManager::RegisterPrefs(registry); | 134 SupervisedUserManager::RegisterPrefs(registry); |
| 139 SessionLengthLimiter::RegisterPrefs(registry); | 135 SessionLengthLimiter::RegisterPrefs(registry); |
| 140 BootstrapManager::RegisterPrefs(registry); | 136 BootstrapManager::RegisterPrefs(registry); |
| 141 } | 137 } |
| 142 | 138 |
| 143 // static | 139 // static |
| 144 scoped_ptr<ChromeUserManager> ChromeUserManagerImpl::CreateChromeUserManager() { | 140 scoped_ptr<ChromeUserManager> ChromeUserManagerImpl::CreateChromeUserManager() { |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 558 user_manager::User::OAuthTokenStatus status) const { | 554 user_manager::User::OAuthTokenStatus status) const { |
| 559 GetUserFlow(account_id)->HandleOAuthTokenStatusChange(status); | 555 GetUserFlow(account_id)->HandleOAuthTokenStatusChange(status); |
| 560 } | 556 } |
| 561 | 557 |
| 562 bool ChromeUserManagerImpl::IsEnterpriseManaged() const { | 558 bool ChromeUserManagerImpl::IsEnterpriseManaged() const { |
| 563 policy::BrowserPolicyConnectorChromeOS* connector = | 559 policy::BrowserPolicyConnectorChromeOS* connector = |
| 564 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 560 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 565 return connector->IsEnterpriseManaged(); | 561 return connector->IsEnterpriseManaged(); |
| 566 } | 562 } |
| 567 | 563 |
| 568 void ChromeUserManagerImpl::LoadPublicAccounts( | 564 void ChromeUserManagerImpl::LoadDeviceLocalAccounts( |
| 569 std::set<AccountId>* public_sessions_set) { | 565 std::set<AccountId>* device_local_accounts_set) { |
| 570 const base::ListValue* prefs_public_sessions = | 566 const std::vector<policy::DeviceLocalAccount> device_local_accounts = |
|
bartfab (slow)
2016/04/08 09:44:15
We need to persist the current list of public sess
xiyuan
2016/04/08 15:52:14
We don't really need kPublicAccounts because devic
| |
| 571 GetLocalState()->GetList(kPublicAccounts); | 567 policy::GetDeviceLocalAccounts(cros_settings_); |
| 572 std::vector<AccountId> public_sessions; | 568 |
| 573 ParseUserList(*prefs_public_sessions, std::set<AccountId>(), &public_sessions, | 569 for (const auto& device_local_account : device_local_accounts) { |
| 574 public_sessions_set); | 570 const AccountId account_id = user_manager::known_user::GetAccountId( |
| 575 for (const AccountId& account_id : public_sessions) { | 571 device_local_account.user_id, std::string()); |
| 576 users_.push_back(user_manager::User::CreatePublicAccountUser(account_id)); | 572 if (!device_local_accounts_set->insert(account_id).second) { |
| 577 UpdatePublicAccountDisplayName(account_id.GetUserEmail()); | 573 LOG(ERROR) << "Duplicate device local account: id=" |
| 574 << account_id.GetUserEmail(); | |
| 575 continue; | |
| 576 } | |
| 577 | |
| 578 switch (device_local_account.type) { | |
| 579 case policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION: | |
| 580 users_.push_back( | |
| 581 user_manager::User::CreatePublicAccountUser(account_id)); | |
| 582 UpdatePublicAccountDisplayName(account_id.GetUserEmail()); | |
| 583 break; | |
| 584 case policy::DeviceLocalAccount::TYPE_KIOSK_APP: | |
| 585 users_.push_back(user_manager::User::CreateKioskAppUser(account_id)); | |
| 586 break; | |
| 587 default: | |
| 588 NOTREACHED(); | |
| 589 break; | |
| 590 } | |
| 578 } | 591 } |
| 579 } | 592 } |
| 580 | 593 |
| 581 void ChromeUserManagerImpl::PerformPreUserListLoadingActions() { | 594 void ChromeUserManagerImpl::PerformPreUserListLoadingActions() { |
| 582 // 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, |
| 583 // so that local state after transaction rollback is in consistent state. | 596 // so that local state after transaction rollback is in consistent state. |
| 584 // This process also should not trigger EnsureUsersLoaded again. | 597 // This process also should not trigger EnsureUsersLoaded again. |
| 585 if (supervised_user_manager_->HasFailedUserCreationTransaction()) | 598 if (supervised_user_manager_->HasFailedUserCreationTransaction()) |
| 586 supervised_user_manager_->RollbackUserCreationTransaction(); | 599 supervised_user_manager_->RollbackUserCreationTransaction(); |
| 587 | 600 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 602 // Initialize the session length limiter and start it only if | 615 // Initialize the session length limiter and start it only if |
| 603 // session limit is defined by the policy. | 616 // session limit is defined by the policy. |
| 604 session_length_limiter_.reset( | 617 session_length_limiter_.reset( |
| 605 new SessionLengthLimiter(NULL, browser_restart)); | 618 new SessionLengthLimiter(NULL, browser_restart)); |
| 606 } | 619 } |
| 607 | 620 |
| 608 bool ChromeUserManagerImpl::IsDemoApp(const AccountId& account_id) const { | 621 bool ChromeUserManagerImpl::IsDemoApp(const AccountId& account_id) const { |
| 609 return DemoAppLauncher::IsDemoAppSession(account_id); | 622 return DemoAppLauncher::IsDemoAppSession(account_id); |
| 610 } | 623 } |
| 611 | 624 |
| 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( | 625 bool ChromeUserManagerImpl::IsPublicAccountMarkedForRemoval( |
| 621 const AccountId& account_id) const { | 626 const AccountId& account_id) const { |
| 622 return account_id == AccountId::FromUserEmail(GetLocalState()->GetString( | 627 return account_id == AccountId::FromUserEmail(GetLocalState()->GetString( |
| 623 kPublicAccountPendingDataRemoval)); | 628 kPublicAccountPendingDataRemoval)); |
| 624 } | 629 } |
| 625 | 630 |
| 626 void ChromeUserManagerImpl::RetrieveTrustedDevicePolicies() { | 631 void ChromeUserManagerImpl::RetrieveTrustedDevicePolicies() { |
| 627 // Local state may not be initialized in unit_tests. | 632 // Local state may not be initialized in unit_tests. |
| 628 if (!GetLocalState()) | 633 if (!GetLocalState()) |
| 629 return; | 634 return; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 779 SetIsCurrentUserNew(true); | 784 SetIsCurrentUserNew(true); |
| 780 active_user_ = user; | 785 active_user_ = user; |
| 781 | 786 |
| 782 // The UserImageManager chooses a random avatar picture when a user logs in | 787 // 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 | 788 // for the first time. Tell the UserImageManager that this user is not new to |
| 784 // prevent the avatar from getting changed. | 789 // prevent the avatar from getting changed. |
| 785 GetUserImageManager(user->GetAccountId())->UserLoggedIn(false, true); | 790 GetUserImageManager(user->GetAccountId())->UserLoggedIn(false, true); |
| 786 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); | 791 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); |
| 787 } | 792 } |
| 788 | 793 |
| 789 void ChromeUserManagerImpl::KioskAppLoggedIn( | 794 void ChromeUserManagerImpl::KioskAppLoggedIn(user_manager::User* user) { |
| 790 const AccountId& kiosk_app_account_id) { | |
| 791 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 795 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 | 796 |
| 798 active_user_ = user_manager::User::CreateKioskAppUser(kiosk_app_account_id); | 797 active_user_ = user; |
| 799 active_user_->SetStubImage( | 798 active_user_->SetStubImage( |
| 800 user_manager::UserImage( | 799 user_manager::UserImage( |
| 801 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 800 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 802 IDR_PROFILE_PICTURE_LOADING)), | 801 IDR_PROFILE_PICTURE_LOADING)), |
| 803 user_manager::User::USER_IMAGE_INVALID, | 802 user_manager::User::USER_IMAGE_INVALID, |
| 804 false); | 803 false); |
| 805 | 804 |
| 805 const AccountId& kiosk_app_account_id = user->GetAccountId(); | |
| 806 WallpaperManager::Get()->SetUserWallpaperNow(kiosk_app_account_id); | 806 WallpaperManager::Get()->SetUserWallpaperNow(kiosk_app_account_id); |
| 807 | 807 |
| 808 // TODO(bartfab): Add KioskAppUsers to the users_ list and keep metadata like | 808 // 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 | 809 // 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. | 810 // device-local account list here to extract the kiosk_app_id. |
| 811 const std::vector<policy::DeviceLocalAccount> device_local_accounts = | 811 const std::vector<policy::DeviceLocalAccount> device_local_accounts = |
| 812 policy::GetDeviceLocalAccounts(cros_settings_); | 812 policy::GetDeviceLocalAccounts(cros_settings_); |
| 813 const policy::DeviceLocalAccount* account = NULL; | 813 const policy::DeviceLocalAccount* account = NULL; |
| 814 for (std::vector<policy::DeviceLocalAccount>::const_iterator it = | 814 for (std::vector<policy::DeviceLocalAccount>::const_iterator it = |
| 815 device_local_accounts.begin(); | 815 device_local_accounts.begin(); |
| 816 it != device_local_accounts.end(); | 816 it != device_local_accounts.end(); |
| 817 ++it) { | 817 ++it) { |
| 818 if (it->user_id == kiosk_app_account_id.GetUserEmail()) { | 818 if (it->user_id == kiosk_app_account_id.GetUserEmail()) { |
| 819 account = &*it; | 819 account = &*it; |
| 820 break; | 820 break; |
| 821 } | 821 } |
| 822 } | 822 } |
| 823 std::string kiosk_app_name; | 823 std::string kiosk_app_id; |
| 824 if (account) { | 824 if (account) { |
| 825 kiosk_app_name = account->kiosk_app_id; | 825 kiosk_app_id = account->kiosk_app_id; |
| 826 } else { | 826 } else { |
| 827 LOG(ERROR) << "Logged into nonexistent kiosk-app account: " | 827 LOG(ERROR) << "Logged into nonexistent kiosk-app account: " |
| 828 << kiosk_app_account_id.GetUserEmail(); | 828 << kiosk_app_account_id.GetUserEmail(); |
| 829 NOTREACHED(); | 829 NOTREACHED(); |
| 830 } | 830 } |
| 831 | 831 |
| 832 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 832 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 833 command_line->AppendSwitch(::switches::kForceAppMode); | 833 command_line->AppendSwitch(::switches::kForceAppMode); |
| 834 command_line->AppendSwitchASCII(::switches::kAppId, kiosk_app_name); | 834 command_line->AppendSwitchASCII(::switches::kAppId, kiosk_app_id); |
| 835 | 835 |
| 836 // Disable window animation since kiosk app runs in a single full screen | 836 // Disable window animation since kiosk app runs in a single full screen |
| 837 // window and window animation causes start-up janks. | 837 // window and window animation causes start-up janks. |
| 838 command_line->AppendSwitch(wm::switches::kWindowAnimationsDisabled); | 838 command_line->AppendSwitch(wm::switches::kWindowAnimationsDisabled); |
| 839 } | 839 } |
| 840 | 840 |
| 841 void ChromeUserManagerImpl::DemoAccountLoggedIn() { | 841 void ChromeUserManagerImpl::DemoAccountLoggedIn() { |
| 842 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 842 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 843 active_user_ = user_manager::User::CreateKioskAppUser(login::DemoAccountId()); | 843 active_user_ = user_manager::User::CreateKioskAppUser(login::DemoAccountId()); |
| 844 active_user_->SetStubImage( | 844 active_user_->SetStubImage( |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 978 for (size_t i = 0; i < new_public_accounts.size(); ++i) { | 978 for (size_t i = 0; i < new_public_accounts.size(); ++i) { |
| 979 if (new_public_accounts[i] != old_public_accounts[i]) { | 979 if (new_public_accounts[i] != old_public_accounts[i]) { |
| 980 changed = true; | 980 changed = true; |
| 981 break; | 981 break; |
| 982 } | 982 } |
| 983 } | 983 } |
| 984 if (!changed) | 984 if (!changed) |
| 985 return false; | 985 return false; |
| 986 } | 986 } |
| 987 | 987 |
| 988 // Persist the new list of public accounts in a pref. | |
| 989 ListPrefUpdate prefs_public_accounts_update(GetLocalState(), kPublicAccounts); | |
| 990 prefs_public_accounts_update->Clear(); | |
| 991 for (std::vector<std::string>::const_iterator it = | |
| 992 new_public_accounts.begin(); | |
| 993 it != new_public_accounts.end(); | |
| 994 ++it) { | |
| 995 prefs_public_accounts_update->AppendString(*it); | |
| 996 } | |
| 997 | |
| 998 // Remove the old public accounts from the user list. | 988 // Remove the old public accounts from the user list. |
| 999 for (user_manager::UserList::iterator it = users_.begin(); | 989 for (user_manager::UserList::iterator it = users_.begin(); |
| 1000 it != users_.end();) { | 990 it != users_.end();) { |
| 1001 if ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT) { | 991 if ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT) { |
| 1002 if (*it != GetLoggedInUser()) | 992 if (*it != GetLoggedInUser()) |
| 1003 DeleteUser(*it); | 993 DeleteUser(*it); |
| 1004 it = users_.erase(it); | 994 it = users_.erase(it); |
| 1005 } else { | 995 } else { |
| 1006 ++it; | 996 ++it; |
| 1007 } | 997 } |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1295 base::Bind(ResolveLocale, locale, base::Unretained(out_resolved_locale)), | 1285 base::Bind(ResolveLocale, locale, base::Unretained(out_resolved_locale)), |
| 1296 on_resolved_callback); | 1286 on_resolved_callback); |
| 1297 } | 1287 } |
| 1298 | 1288 |
| 1299 bool ChromeUserManagerImpl::IsValidDefaultUserImageId(int image_index) const { | 1289 bool ChromeUserManagerImpl::IsValidDefaultUserImageId(int image_index) const { |
| 1300 return image_index >= 0 && | 1290 return image_index >= 0 && |
| 1301 image_index < chromeos::default_user_image::kDefaultImagesCount; | 1291 image_index < chromeos::default_user_image::kDefaultImagesCount; |
| 1302 } | 1292 } |
| 1303 | 1293 |
| 1304 } // namespace chromeos | 1294 } // namespace chromeos |
| OLD | NEW |