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 37bb77bf9cd5c5e1fd7236b4b4e9b7a4c8c43178..98d0f1852c16ee4c1ce3f702a10e23d8806a5b9b 100644 |
| --- a/chrome/browser/chromeos/login/screens/user_selection_screen.cc |
| +++ b/chrome/browser/chromeos/login/screens/user_selection_screen.cc |
| @@ -148,7 +148,7 @@ void UserSelectionScreen::FillUserDictionary( |
| user->GetType() == user_manager::USER_TYPE_SUPERVISED; |
| const bool is_child_user = user->GetType() == user_manager::USER_TYPE_CHILD; |
| - user_dict->SetString(kKeyUsername, user->GetAccountId().GetUserEmail()); |
| + user_dict->SetString(kKeyUsername, user->GetAccountId().Serialize()); |
| user_dict->SetString(kKeyEmailAddress, user->display_email()); |
| user_dict->SetString(kKeyDisplayName, user->GetDisplayName()); |
| user_dict->SetBoolean(kKeyPublicAccount, is_public_session); |
| @@ -246,6 +246,26 @@ bool UserSelectionScreen::ShouldForceOnlineSignIn( |
| (token_status == user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN); |
| } |
| +// static |
| +AccountId UserSelectionScreen::GetAccountIdOfKnownUser( |
| + const std::string& user_id) { |
| + if (user_id.empty()) |
| + return EmptyAccountId(); |
| + |
| + const AccountId initial_account_id(AccountId::FromUserEmail(user_id)); |
| + |
| + user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| + if (!user_manager) |
| + return initial_account_id; |
| + |
| + AccountId known_account_id(EmptyAccountId()); |
|
dzhioev (left Google)
2015/11/13 23:17:37
nit: 'AccountId known_account_id = EmptyAccountId(
Alexander Alekseev
2015/11/14 00:27:42
Done.
|
| + if (user_manager->GetKnownUserAccountId(initial_account_id, |
| + &known_account_id)) |
| + return known_account_id; |
| + |
| + return initial_account_id; |
| +} |
| + |
| void UserSelectionScreen::SetHandler(LoginDisplayWebUIHandler* handler) { |
| handler_ = handler; |
| } |
| @@ -306,18 +326,17 @@ void UserSelectionScreen::OnUserActivity(const ui::Event* event) { |
| // static |
| const user_manager::UserList UserSelectionScreen::PrepareUserListForSending( |
| const user_manager::UserList& users, |
| - std::string owner, |
| + const AccountId& owner, |
| bool is_signin_to_add) { |
| user_manager::UserList users_to_send; |
| - bool has_owner = owner.size() > 0; |
| + bool has_owner = owner.is_valid(); |
| size_t max_non_owner_users = has_owner ? kMaxUsers - 1 : kMaxUsers; |
| size_t non_owner_count = 0; |
| for (user_manager::UserList::const_iterator it = users.begin(); |
| it != users.end(); |
| ++it) { |
| - const std::string& user_id = (*it)->email(); |
| - bool is_owner = (user_id == owner); |
| + bool is_owner = ((*it)->GetAccountId() == owner); |
| bool is_public_account = |
| ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT); |
| @@ -347,8 +366,10 @@ void UserSelectionScreen::SendUserList() { |
| bool single_user = users_.size() == 1; |
| bool is_signin_to_add = LoginDisplayHostImpl::default_host() && |
| user_manager::UserManager::Get()->IsUserLoggedIn(); |
| - std::string owner; |
| - chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner); |
| + std::string owner_email; |
| + chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, |
| + &owner_email); |
| + const AccountId owner(GetAccountIdOfKnownUser(owner_email)); |
| policy::BrowserPolicyConnectorChromeOS* connector = |
| g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| @@ -363,22 +384,22 @@ void UserSelectionScreen::SendUserList() { |
| for (user_manager::UserList::const_iterator it = users_to_send.begin(); |
| it != users_to_send.end(); |
| ++it) { |
| - const std::string& user_id = (*it)->email(); |
| - bool is_owner = (user_id == owner); |
| + const AccountId& account_id = (*it)->GetAccountId(); |
| + bool is_owner = (account_id == owner); |
| 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_[user_id] = initial_auth_type; |
| + user_auth_type_map_[account_id] = initial_auth_type; |
| base::DictionaryValue* user_dict = new base::DictionaryValue(); |
| const std::vector<std::string>* public_session_recommended_locales = |
| - public_session_recommended_locales_.find(user_id) == |
| - public_session_recommended_locales_.end() ? |
| - &kEmptyRecommendedLocales : |
| - &public_session_recommended_locales_[user_id]; |
| + public_session_recommended_locales_.find(account_id) == |
| + public_session_recommended_locales_.end() |
| + ? &kEmptyRecommendedLocales |
| + : &public_session_recommended_locales_[account_id]; |
| FillUserDictionary(*it, |
| is_owner, |
| is_signin_to_add, |
| @@ -391,7 +412,7 @@ void UserSelectionScreen::SendUserList() { |
| // available when running into login screen on first boot. |
| // See http://crosbug.com/12723 |
| bool can_remove_user = |
| - ((!single_user || is_enterprise_managed) && !user_id.empty() && |
| + ((!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); |
| users_list.Append(user_dict); |
| @@ -404,7 +425,7 @@ void UserSelectionScreen::HandleGetUsers() { |
| SendUserList(); |
| } |
| -void UserSelectionScreen::CheckUserStatus(const std::string& user_email) { |
| +void UserSelectionScreen::CheckUserStatus(const AccountId& account_id) { |
| // No checks on lock screen. |
| if (ScreenLocker::default_screen_locker()) |
| return; |
| @@ -414,7 +435,6 @@ void UserSelectionScreen::CheckUserStatus(const std::string& user_email) { |
| new TokenHandleUtil(user_manager::UserManager::Get())); |
| } |
| - const AccountId account_id = AccountId::FromUserEmail(user_email); |
| if (token_handle_util_->HasToken(account_id)) { |
| token_handle_util_->CheckToken( |
| account_id, base::Bind(&UserSelectionScreen::OnUserStatusChecked, |
| @@ -437,19 +457,21 @@ void UserSelectionScreen::OnUserStatusChecked( |
| void UserSelectionScreen::SetAuthType(const std::string& user_id, |
| AuthType auth_type, |
| const base::string16& initial_value) { |
| - if (GetAuthType(user_id) == FORCE_OFFLINE_PASSWORD) |
| + const AccountId& account_id(GetAccountIdOfKnownUser(user_id)); |
|
dzhioev (left Google)
2015/11/13 23:17:37
ditto
Alexander Alekseev
2015/11/14 00:27:42
Done.
|
| + if (GetAuthType(account_id.GetUserEmail()) == FORCE_OFFLINE_PASSWORD) |
| return; |
| - DCHECK(GetAuthType(user_id) != FORCE_OFFLINE_PASSWORD || |
| + DCHECK(GetAuthType(account_id.GetUserEmail()) != FORCE_OFFLINE_PASSWORD || |
| auth_type == FORCE_OFFLINE_PASSWORD); |
| - user_auth_type_map_[user_id] = auth_type; |
| - view_->SetAuthType(user_id, auth_type, initial_value); |
| + user_auth_type_map_[account_id] = auth_type; |
| + view_->SetAuthType(account_id, auth_type, initial_value); |
| } |
| proximity_auth::ScreenlockBridge::LockHandler::AuthType |
| UserSelectionScreen::GetAuthType(const std::string& username) const { |
| - if (user_auth_type_map_.find(username) == user_auth_type_map_.end()) |
| + const AccountId& account_id(GetAccountIdOfKnownUser(username)); |
|
dzhioev (left Google)
2015/11/13 23:17:37
ditto
Alexander Alekseev
2015/11/14 00:27:42
Done.
|
| + if (user_auth_type_map_.find(account_id) == user_auth_type_map_.end()) |
| return OFFLINE_PASSWORD; |
| - return user_auth_type_map_.find(username)->second; |
| + return user_auth_type_map_.find(account_id)->second; |
| } |
| proximity_auth::ScreenlockBridge::LockHandler::ScreenType |
| @@ -474,11 +496,13 @@ void UserSelectionScreen::ShowUserPodCustomIcon( |
| scoped_ptr<base::DictionaryValue> icon = icon_options.ToDictionaryValue(); |
| if (!icon || icon->empty()) |
| return; |
| - view_->ShowUserPodCustomIcon(user_id, *icon); |
| + const AccountId account_id(GetAccountIdOfKnownUser(user_id)); |
|
dzhioev (left Google)
2015/11/13 23:17:37
ditto
Alexander Alekseev
2015/11/14 00:27:42
Done.
|
| + view_->ShowUserPodCustomIcon(account_id, *icon); |
| } |
| void UserSelectionScreen::HideUserPodCustomIcon(const std::string& user_id) { |
| - view_->HideUserPodCustomIcon(user_id); |
| + const AccountId account_id(GetAccountIdOfKnownUser(user_id)); |
|
dzhioev (left Google)
2015/11/13 23:17:37
ditto
Alexander Alekseev
2015/11/14 00:27:42
Done.
|
| + view_->HideUserPodCustomIcon(account_id); |
| } |
| void UserSelectionScreen::EnableInput() { |
| @@ -499,7 +523,7 @@ void UserSelectionScreen::AttemptEasySignin(const std::string& user_id, |
| const std::string& key_label) { |
| DCHECK_EQ(GetScreenType(), SIGNIN_SCREEN); |
| - UserContext user_context(AccountId::FromUserEmail(user_id)); |
| + UserContext user_context(GetAccountIdOfKnownUser(user_id)); |
| user_context.SetAuthFlow(UserContext::AUTH_FLOW_EASY_UNLOCK); |
| user_context.SetKey(Key(secret)); |
| user_context.GetKey()->SetLabel(key_label); |
| @@ -507,36 +531,36 @@ void UserSelectionScreen::AttemptEasySignin(const std::string& user_id, |
| login_display_delegate_->Login(user_context, SigninSpecifics()); |
| } |
| -void UserSelectionScreen::HardLockPod(const std::string& user_id) { |
| - view_->SetAuthType(user_id, OFFLINE_PASSWORD, base::string16()); |
| - EasyUnlockService* service = GetEasyUnlockServiceForUser(user_id); |
| +void UserSelectionScreen::HardLockPod(const AccountId& account_id) { |
| + view_->SetAuthType(account_id, OFFLINE_PASSWORD, base::string16()); |
| + EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id); |
| if (!service) |
| return; |
| service->SetHardlockState(EasyUnlockScreenlockStateHandler::USER_HARDLOCK); |
| } |
| -void UserSelectionScreen::AttemptEasyUnlock(const std::string& user_id) { |
| - EasyUnlockService* service = GetEasyUnlockServiceForUser(user_id); |
| +void UserSelectionScreen::AttemptEasyUnlock(const AccountId& account_id) { |
| + EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id); |
| if (!service) |
| return; |
| - service->AttemptAuth(user_id); |
| + service->AttemptAuth(account_id.GetUserEmail()); |
| } |
| -void UserSelectionScreen::RecordClickOnLockIcon(const std::string& user_id) { |
| - EasyUnlockService* service = GetEasyUnlockServiceForUser(user_id); |
| +void UserSelectionScreen::RecordClickOnLockIcon(const AccountId& account_id) { |
| + EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id); |
| if (!service) |
| return; |
| service->RecordClickOnLockIcon(); |
| } |
| EasyUnlockService* UserSelectionScreen::GetEasyUnlockServiceForUser( |
| - const std::string& user_id) const { |
| + const AccountId& account_id) const { |
| if (GetScreenType() == OTHER_SCREEN) |
| return nullptr; |
| const user_manager::User* unlock_user = nullptr; |
| for (const user_manager::User* user : users_) { |
| - if (user->email() == user_id) { |
| + if (user->GetAccountId() == account_id) { |
| unlock_user = user; |
| break; |
| } |