Chromium Code Reviews| Index: chrome/browser/chromeos/login/screens/user_selection_screen.cc |
| diff --git a/chrome/browser/chromeos/login/screens/user_selection_screen.cc b/chrome/browser/chromeos/login/screens/user_selection_screen.cc |
| index 8e0c8c560739f467f38cac373d0ad2ce07ab331a..c34b7dba68ea968a93a49e006c0dc6133daef2b8 100644 |
| --- a/chrome/browser/chromeos/login/screens/user_selection_screen.cc |
| +++ b/chrome/browser/chromeos/login/screens/user_selection_screen.cc |
| @@ -14,6 +14,7 @@ |
| #include "base/location.h" |
| #include "base/logging.h" |
| #include "base/memory/ptr_util.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "base/values.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/browser_process_platform_part.h" |
| @@ -31,6 +32,7 @@ |
| #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" |
| #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
| #include "chrome/grit/generated_resources.h" |
| +#include "chrome/grit/theme_resources.h" |
| #include "chromeos/chromeos_switches.h" |
| #include "chromeos/cryptohome/cryptohome_parameters.h" |
| #include "chromeos/dbus/cryptohome_client.h" |
| @@ -44,6 +46,7 @@ |
| #include "components/user_manager/user_manager.h" |
| #include "components/user_manager/user_type.h" |
| #include "ui/base/l10n/l10n_util.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| #include "ui/base/user_activity/user_activity_detector.h" |
| namespace chromeos { |
| @@ -130,7 +133,7 @@ void AddPublicSessionDetailsToUserDictionaryEntry( |
| // Returns true if the fingerprint icon should be displayed for the given |
| // |user|. |
| -bool AllowFingerprintForUser(user_manager::User* user) { |
| +bool AllowFingerprintForUser(const user_manager::User* user) { |
| if (!user->is_logged_in()) |
| return false; |
| @@ -156,6 +159,61 @@ bool IsUserAllowedForARC(const AccountId& account_id) { |
| user_manager::UserManager::Get()->FindUser(account_id)); |
| } |
| +AccountId GetOwnerAccountId() { |
| + std::string owner_email; |
| + chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, |
| + &owner_email); |
| + const AccountId owner = user_manager::known_user::GetAccountId( |
| + owner_email, std::string() /* id */, AccountType::UNKNOWN); |
| + return owner; |
| +} |
| + |
| +bool IsEnterpriseManaged() { |
| + policy::BrowserPolicyConnectorChromeOS* connector = |
| + g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| + return connector->IsEnterpriseManaged(); |
| +} |
| + |
| +bool IsSigninToAdd() { |
| + return LoginDisplayHost::default_host() && |
| + user_manager::UserManager::Get()->IsUserLoggedIn(); |
| +} |
| + |
| +bool CanRemoveUser(bool is_single_user, const user_manager::User* user) { |
| + // Single user check here is necessary because owner info might not be |
| + // available when running into login screen on first boot. |
| + // See http://crosbug.com/12723 |
| + if (is_single_user && !IsEnterpriseManaged()) |
| + return false; |
| + if (!user->GetAccountId().is_valid()) |
| + return false; |
| + if (user->GetAccountId() == GetOwnerAccountId()) |
| + return false; |
| + if (user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT || |
| + user->is_logged_in() || IsSigninToAdd()) |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| +void GetMultiProfilePolicy(const user_manager::User* user, |
| + bool* out_is_allowed, |
| + std::string* out_policy) { |
| + const std::string& user_id = user->GetAccountId().GetUserEmail(); |
| + MultiProfileUserController* multi_profile_user_controller = |
| + ChromeUserManager::Get()->GetMultiProfileUserController(); |
| + MultiProfileUserController::UserAllowedInSessionReason is_user_allowed_reason; |
| + *out_is_allowed = multi_profile_user_controller->IsUserAllowedInSession( |
| + user_id, &is_user_allowed_reason); |
| + switch (is_user_allowed_reason) { |
| + case MultiProfileUserController::NOT_ALLOWED_OWNER_AS_SECONDARY: |
|
jdufault
2017/06/14 02:20:42
An if/else is probably simpler.
xiaoyinh(OOO Sep 11-29)
2017/06/15 18:39:37
Done.
|
| + *out_policy = MultiProfileUserController::kBehaviorOwnerPrimaryOnly; |
| + break; |
| + default: |
| + *out_policy = multi_profile_user_controller->GetCachedValue(user_id); |
|
jdufault
2017/06/14 02:20:42
nit: break
xiaoyinh(OOO Sep 11-29)
2017/06/15 18:39:37
Changed to if/else.
|
| + } |
| +} |
| + |
| } // namespace |
| // Helper class to call cryptohome to check whether a user needs dircrypto |
| @@ -319,28 +377,16 @@ void UserSelectionScreen::FillMultiProfileUserPrefs( |
| user_manager::User* user, |
| base::DictionaryValue* user_dict, |
| bool is_signin_to_add) { |
| - const std::string& user_id = user->GetAccountId().GetUserEmail(); |
| - |
| - if (is_signin_to_add) { |
| - MultiProfileUserController* multi_profile_user_controller = |
| - ChromeUserManager::Get()->GetMultiProfileUserController(); |
| - MultiProfileUserController::UserAllowedInSessionReason isUserAllowedReason; |
| - bool isUserAllowed = multi_profile_user_controller->IsUserAllowedInSession( |
| - user_id, &isUserAllowedReason); |
| - user_dict->SetBoolean(kKeyMultiProfilesAllowed, isUserAllowed); |
| - |
| - std::string behavior; |
| - switch (isUserAllowedReason) { |
| - case MultiProfileUserController::NOT_ALLOWED_OWNER_AS_SECONDARY: |
| - behavior = MultiProfileUserController::kBehaviorOwnerPrimaryOnly; |
| - break; |
| - default: |
| - behavior = multi_profile_user_controller->GetCachedValue(user_id); |
| - } |
| - user_dict->SetString(kKeyMultiProfilesPolicy, behavior); |
| - } else { |
| + if (!is_signin_to_add) { |
| user_dict->SetBoolean(kKeyMultiProfilesAllowed, true); |
| + return; |
| } |
| + |
| + bool is_user_allowed; |
| + std::string policy; |
| + GetMultiProfilePolicy(user, &is_user_allowed, &policy); |
| + user_dict->SetBoolean(kKeyMultiProfilesAllowed, is_user_allowed); |
| + user_dict->SetString(kKeyMultiProfilesPolicy, policy); |
| } |
| // static |
| @@ -384,6 +430,43 @@ bool UserSelectionScreen::ShouldForceOnlineSignIn( |
| token_status == user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN)); |
| } |
| +// static |
| +void UserSelectionScreen::FillUserMojoStruct( |
| + const user_manager::User* user, |
| + bool is_owner, |
| + bool is_signin_to_add, |
| + AuthType auth_type, |
| + ash::mojom::LoginUserInfo* user_info) { |
| + user_info->basic_user_info = ash::mojom::UserInfo::New(); |
| + user_info->basic_user_info->type = user->GetType(); |
| + user_info->basic_user_info->account_id = user->GetAccountId(); |
| + user_info->basic_user_info->display_name = |
| + base::UTF16ToUTF8(user->GetDisplayName()); |
| + user_info->basic_user_info->display_email = user->display_email(); |
| + user_info->basic_user_info->avatar = user->GetImage(); |
| + if (user_info->basic_user_info->avatar.isNull()) { |
| + user_info->basic_user_info->avatar = |
| + *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| + IDR_PROFILE_PICTURE_LOADING); |
| + } |
| + user_info->is_desktop_user = false; |
| + user_info->auth_type = static_cast<ash::mojom::AuthType>(auth_type); |
| + user_info->is_signed_in = user->is_logged_in(); |
| + user_info->is_owner = is_owner; |
| + user_info->allow_fingerprint_unlock = AllowFingerprintForUser(user); |
| + |
| + // Fill multi-profile data. |
| + if (!is_signin_to_add) { |
| + user_info->is_multiprofile_allowed = true; |
| + } else { |
| + bool is_user_allowed; |
| + std::string policy; |
| + GetMultiProfilePolicy(user, &is_user_allowed, &policy); |
| + user_info->is_multiprofile_allowed = is_user_allowed; |
|
jdufault
2017/06/14 02:20:42
Instead of using temporaries just write directly t
xiaoyinh(OOO Sep 11-29)
2017/06/15 18:39:37
Done.
|
| + user_info->multiprofile_policy = policy; |
| + } |
| +} |
| + |
| void UserSelectionScreen::SetHandler(LoginDisplayWebUIHandler* handler) { |
| handler_ = handler; |
| @@ -482,7 +565,7 @@ const user_manager::UserList UserSelectionScreen::PrepareUserListForSending( |
| } |
| void UserSelectionScreen::SendUserList() { |
| - std::unique_ptr<base::ListValue> users_list = PrepareUserList(); |
| + std::unique_ptr<base::ListValue> users_list = UpdateAndReturnUserList(); |
| handler_->LoadUsers(users_to_send_, *users_list); |
| } |
| @@ -626,24 +709,16 @@ void UserSelectionScreen::RecordClickOnLockIcon(const AccountId& account_id) { |
| service->RecordClickOnLockIcon(); |
| } |
| -std::unique_ptr<base::ListValue> UserSelectionScreen::PrepareUserList() { |
| +std::unique_ptr<base::ListValue> |
| +UserSelectionScreen::UpdateAndReturnUserList() { |
| std::unique_ptr<base::ListValue> users_list = |
| base::MakeUnique<base::ListValue>(); |
| // TODO(nkostylev): Move to a separate method in UserManager. |
| // http://crbug.com/230852 |
| - bool single_user = users_.size() == 1; |
| - bool is_signin_to_add = LoginDisplayHost::default_host() && |
| - user_manager::UserManager::Get()->IsUserLoggedIn(); |
| - std::string owner_email; |
| - chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, |
| - &owner_email); |
| - const AccountId owner = user_manager::known_user::GetAccountId( |
| - owner_email, std::string() /* id */, AccountType::UNKNOWN); |
| - |
| - policy::BrowserPolicyConnectorChromeOS* connector = |
| - g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| - bool is_enterprise_managed = connector->IsEnterpriseManaged(); |
| + const bool single_user = users_.size() == 1; |
| + const AccountId owner = GetOwnerAccountId(); |
| + const bool is_signin_to_add = IsSigninToAdd(); |
| users_to_send_ = PrepareUserListForSending(users_, owner, is_signin_to_add); |
| @@ -670,21 +745,47 @@ std::unique_ptr<base::ListValue> UserSelectionScreen::PrepareUserList() { |
| : &public_session_recommended_locales_[account_id]; |
| FillUserDictionary(*it, is_owner, is_signin_to_add, initial_auth_type, |
| public_session_recommended_locales, user_dict.get()); |
| - bool signed_in = (*it)->is_logged_in(); |
| - |
| - // Single user check here is necessary because owner info might not be |
| - // available when running into login screen on first boot. |
| - // See http://crosbug.com/12723 |
| - bool can_remove_user = |
| - ((!single_user || is_enterprise_managed) && account_id.is_valid() && |
| - !is_owner && !is_public_account && !signed_in && !is_signin_to_add); |
| - user_dict->SetBoolean(kKeyCanRemove, can_remove_user); |
| + user_dict->SetBoolean(kKeyCanRemove, CanRemoveUser(single_user, *it)); |
| users_list->Append(std::move(user_dict)); |
| } |
| return users_list; |
| } |
| +std::vector<ash::mojom::LoginUserInfoPtr> |
| +UserSelectionScreen::UpdateAndReturnUserListForMojo() { |
| + std::vector<ash::mojom::LoginUserInfoPtr> user_info_list; |
| + |
| + const bool single_user = users_.size() == 1; |
| + const AccountId owner = GetOwnerAccountId(); |
| + const bool is_signin_to_add = IsSigninToAdd(); |
| + users_to_send_ = PrepareUserListForSending(users_, owner, is_signin_to_add); |
| + |
| + user_auth_type_map_.clear(); |
| + |
| + for (user_manager::UserList::const_iterator it = users_to_send_.begin(); |
| + it != users_to_send_.end(); ++it) { |
| + const AccountId& account_id = (*it)->GetAccountId(); |
| + bool is_owner = owner == account_id; |
| + const bool is_public_account = |
| + ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT); |
| + const AuthType initial_auth_type = |
| + is_public_account ? EXPAND_THEN_USER_CLICK |
| + : (ShouldForceOnlineSignIn(*it) ? ONLINE_SIGN_IN |
| + : OFFLINE_PASSWORD); |
| + user_auth_type_map_[account_id] = initial_auth_type; |
| + |
| + ash::mojom::LoginUserInfoPtr login_user_info = |
| + ash::mojom::LoginUserInfo::New(); |
| + FillUserMojoStruct(*it, is_owner, is_signin_to_add, initial_auth_type, |
| + login_user_info.get()); |
| + login_user_info->can_remove = CanRemoveUser(single_user, *it); |
| + user_info_list.push_back(std::move(login_user_info)); |
| + } |
| + |
| + return user_info_list; |
| +} |
| + |
| EasyUnlockService* UserSelectionScreen::GetEasyUnlockServiceForUser( |
| const AccountId& account_id) const { |
| if (GetScreenType() == OTHER_SCREEN) |