Skip to content

Commit

Permalink
This CL replaces e-mail with AccountId on user selection screen.
Browse files Browse the repository at this point in the history
This CL replaces e-mail with serialized AccountId on user selection screen.
It also adds simple AccountId Serialize/Deserialize methods suitable for
passing AccountId to JS code.

This is part of transition to AccountId.

BUG=462823, 552034
TEST=manual

Review URL: https://codereview.chromium.org/1440583002

Cr-Commit-Position: refs/heads/master@{#360319}
  • Loading branch information
alemate authored and Commit bot committed Nov 18, 2015
1 parent a370ef5 commit 1e24fe5
Show file tree
Hide file tree
Showing 40 changed files with 416 additions and 246 deletions.
2 changes: 1 addition & 1 deletion ash/test/test_session_state_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class MockUserInfo : public user_manager::UserInfo {

std::string GetEmail() const override { return display_email_; }

AccountId GetAccountId() const override { return account_id_; }
const AccountId& GetAccountId() const override { return account_id_; }

const gfx::ImageSkia& GetImage() const override { return user_image_; }

Expand Down
3 changes: 1 addition & 2 deletions chrome/browser/chromeos/login/app_launch_signin_screen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ void AppLaunchSigninScreen::HandleGetUsers() {
webui_handler_->LoadUsers(users_list, false);
}

void AppLaunchSigninScreen::CheckUserStatus(const std::string& user_id) {
}
void AppLaunchSigninScreen::CheckUserStatus(const AccountId& account_id) {}

bool AppLaunchSigninScreen::IsUserWhitelisted(const std::string& user_id) {
NOTREACHED();
Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/chromeos/login/app_launch_signin_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"

class AccountId;

namespace chromeos {

class OobeUI;
Expand Down Expand Up @@ -77,7 +79,7 @@ class AppLaunchSigninScreen : public SigninScreenHandlerDelegate,
void SetDisplayEmail(const std::string& email) override;
void Signout() override;
void HandleGetUsers() override;
void CheckUserStatus(const std::string& user_id) override;
void CheckUserStatus(const AccountId& account_id) override;
bool IsUserWhitelisted(const std::string& user_id) override;

// AuthStatusConsumer implementation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,20 @@ void ChromeUserSelectionScreen::OnDeviceLocalAccountsChanged() {

void ChromeUserSelectionScreen::CheckForPublicSessionDisplayNameChange(
policy::DeviceLocalAccountPolicyBroker* broker) {
const std::string& user_id = broker->user_id();
const AccountId& account_id = GetAccountIdOfKnownUser(broker->user_id());
DCHECK(account_id.is_valid());
const std::string& display_name = broker->GetDisplayName();
if (display_name == public_session_display_names_[user_id])
if (display_name == public_session_display_names_[account_id])
return;

public_session_display_names_[user_id] = display_name;
public_session_display_names_[account_id] = display_name;

if (!handler_initialized_)
return;

if (!display_name.empty()) {
// If a new display name was set by policy, notify the UI about it.
view_->SetPublicSessionDisplayName(user_id, display_name);
view_->SetPublicSessionDisplayName(account_id, display_name);
return;
}

Expand All @@ -101,13 +102,13 @@ void ChromeUserSelectionScreen::CheckForPublicSessionDisplayNameChange(
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&ChromeUserSelectionScreen::SetPublicSessionDisplayName,
weak_factory_.GetWeakPtr(),
user_id));
weak_factory_.GetWeakPtr(), account_id));
}

void ChromeUserSelectionScreen::CheckForPublicSessionLocalePolicyChange(
policy::DeviceLocalAccountPolicyBroker* broker) {
const std::string& user_id = broker->user_id();
const AccountId& account_id = GetAccountIdOfKnownUser(broker->user_id());
DCHECK(account_id.is_valid());
const policy::PolicyMap::Entry* entry =
broker->core()->store()->policy_map().Get(policy::key::kSessionLocales);

Expand All @@ -131,30 +132,30 @@ void ChromeUserSelectionScreen::CheckForPublicSessionLocalePolicyChange(
}

std::vector<std::string>& recommended_locales =
public_session_recommended_locales_[user_id];
public_session_recommended_locales_[account_id];

if (new_recommended_locales != recommended_locales)
SetPublicSessionLocales(user_id, new_recommended_locales);
SetPublicSessionLocales(account_id, new_recommended_locales);

if (new_recommended_locales.empty())
public_session_recommended_locales_.erase(user_id);
public_session_recommended_locales_.erase(account_id);
else
recommended_locales = new_recommended_locales;
}

void ChromeUserSelectionScreen::SetPublicSessionDisplayName(
const std::string& user_id) {
const user_manager::User* user = user_manager::UserManager::Get()->FindUser(
AccountId::FromUserEmail(user_id));
const AccountId& account_id) {
const user_manager::User* user =
user_manager::UserManager::Get()->FindUser(account_id);
if (!user || user->GetType() != user_manager::USER_TYPE_PUBLIC_ACCOUNT)
return;

view_->SetPublicSessionDisplayName(user_id,
view_->SetPublicSessionDisplayName(account_id,
base::UTF16ToUTF8(user->GetDisplayName()));
}

void ChromeUserSelectionScreen::SetPublicSessionLocales(
const std::string& user_id,
const AccountId& account_id,
const std::vector<std::string>& recommended_locales) {
if (!handler_initialized_)
return;
Expand All @@ -178,7 +179,7 @@ void ChromeUserSelectionScreen::SetPublicSessionLocales(
const bool two_or_more_recommended_locales = recommended_locales.size() >= 2;

// Notify the UI.
view_->SetPublicSessionLocales(user_id, available_locales.Pass(),
view_->SetPublicSessionLocales(account_id, available_locales.Pass(),
default_locale,
two_or_more_recommended_locales);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "chrome/browser/chromeos/login/screens/user_selection_screen.h"
#include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"

class AccountId;

namespace chromeos {

class ChromeUserSelectionScreen
Expand Down Expand Up @@ -45,20 +47,20 @@ class ChromeUserSelectionScreen

// Notify the UI that the display name for a public session has changed,
// taking the display name from the |User| owned by |UserManager|.
void SetPublicSessionDisplayName(const std::string& user_id);
void SetPublicSessionDisplayName(const AccountId& account_id);

// Send an updated list of locales for a public session to the UI, consisting
// of the |recommended_locales| followed by all other available locales.
void SetPublicSessionLocales(
const std::string& user_id,
const AccountId& account_id,
const std::vector<std::string>& recommended_locales);

bool handler_initialized_;

policy::DeviceLocalAccountPolicyService* device_local_account_policy_service_;

// Map from public session user IDs to their display names set by policy.
typedef std::map<std::string, std::string> DisplayNamesMap;
// Map from public session account IDs to their display names set by policy.
typedef std::map<AccountId, std::string> DisplayNamesMap;
DisplayNamesMap public_session_display_names_;

base::WeakPtrFactory<ChromeUserSelectionScreen> weak_factory_;
Expand Down
96 changes: 60 additions & 36 deletions chrome/browser/chromeos/login/screens/user_selection_screen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
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;
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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);
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);
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
Expand All @@ -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);
view_->ShowUserPodCustomIcon(account_id, *icon);
}

void UserSelectionScreen::HideUserPodCustomIcon(const std::string& user_id) {
view_->HideUserPodCustomIcon(user_id);
const AccountId account_id = GetAccountIdOfKnownUser(user_id);
view_->HideUserPodCustomIcon(account_id);
}

void UserSelectionScreen::EnableInput() {
Expand All @@ -499,44 +523,44 @@ 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);

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;
}
Expand Down
Loading

0 comments on commit 1e24fe5

Please sign in to comment.