Skip to content

Commit

Permalink
This CL replaces e-mail with AccountId in easy unlock/signin code.
Browse files Browse the repository at this point in the history
This is part of transition to AccountId.

BUG=462823
TEST=manual

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

Cr-Commit-Position: refs/heads/master@{#364223}
  • Loading branch information
alemate authored and Commit bot committed Dec 9, 2015
1 parent cb93d1c commit 546380c
Show file tree
Hide file tree
Showing 80 changed files with 723 additions and 699 deletions.
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/login/app_launch_signin_screen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void AppLaunchSigninScreen::HandleGetUsers() {

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

bool AppLaunchSigninScreen::IsUserWhitelisted(const std::string& user_id) {
bool AppLaunchSigninScreen::IsUserWhitelisted(const AccountId& account_id) {
NOTREACHED();
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/login/app_launch_signin_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class AppLaunchSigninScreen : public SigninScreenHandlerDelegate,
void Signout() override;
void HandleGetUsers() override;
void CheckUserStatus(const AccountId& account_id) override;
bool IsUserWhitelisted(const std::string& user_id) override;
bool IsUserWhitelisted(const AccountId& account_id) override;

// AuthStatusConsumer implementation:
void OnAuthFailure(const AuthFailure& error) override;
Expand Down
32 changes: 16 additions & 16 deletions chrome/browser/chromeos/login/auth/chrome_login_performer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ void ChromeLoginPerformer::DidRunTrustedCheck(const base::Closure& callback) {
}
}

bool ChromeLoginPerformer::IsUserWhitelisted(const std::string& user_id,
bool ChromeLoginPerformer::IsUserWhitelisted(const AccountId& account_id,
bool* wildcard_match) {
return CrosSettings::IsWhitelisted(user_id, wildcard_match);
return CrosSettings::IsWhitelisted(account_id.GetUserEmail(), wildcard_match);
}

void ChromeLoginPerformer::RunOnlineWhitelistCheck(
const std::string& user_id,
const AccountId& account_id,
bool wildcard_match,
const std::string& refresh_token,
const base::Closure& success_callback,
Expand All @@ -99,7 +99,7 @@ void ChromeLoginPerformer::RunOnlineWhitelistCheck(
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
if (connector->IsEnterpriseManaged() && wildcard_match &&
!connector->IsNonEnterpriseUser(user_id)) {
!connector->IsNonEnterpriseUser(account_id.GetUserEmail())) {
wildcard_login_checker_.reset(new policy::WildcardLoginChecker());
if (refresh_token.empty()) {
wildcard_login_checker_->StartWithSigninContext(
Expand Down Expand Up @@ -143,27 +143,27 @@ UserContext ChromeLoginPerformer::TransformSupervisedKey(
return authentication->TransformKey(context);
}

void ChromeLoginPerformer::SetupSupervisedUserFlow(const std::string& user_id) {
SupervisedUserLoginFlow* new_flow = new SupervisedUserLoginFlow(user_id);
new_flow->SetHost(ChromeUserManager::Get()
->GetUserFlow(AccountId::FromUserEmail(user_id))
->host());
ChromeUserManager::Get()->SetUserFlow(AccountId::FromUserEmail(user_id),
new_flow);
void ChromeLoginPerformer::SetupSupervisedUserFlow(
const AccountId& account_id) {
SupervisedUserLoginFlow* new_flow = new SupervisedUserLoginFlow(account_id);
new_flow->SetHost(ChromeUserManager::Get()->GetUserFlow(account_id)->host());
ChromeUserManager::Get()->SetUserFlow(account_id, new_flow);
}

void ChromeLoginPerformer::SetupEasyUnlockUserFlow(const std::string& user_id) {
ChromeUserManager::Get()->SetUserFlow(AccountId::FromUserEmail(user_id),
new EasyUnlockUserLoginFlow(user_id));
void ChromeLoginPerformer::SetupEasyUnlockUserFlow(
const AccountId& account_id) {
ChromeUserManager::Get()->SetUserFlow(
account_id, new EasyUnlockUserLoginFlow(account_id));
}

bool ChromeLoginPerformer::CheckPolicyForUser(const std::string& user_id) {
bool ChromeLoginPerformer::CheckPolicyForUser(const AccountId& account_id) {
// Login is not allowed if policy could not be loaded for the account.
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
policy::DeviceLocalAccountPolicyService* policy_service =
connector->GetDeviceLocalAccountPolicyService();
return policy_service && policy_service->IsPolicyAvailableForUser(user_id);
return policy_service &&
policy_service->IsPolicyAvailableForUser(account_id.GetUserEmail());
}
////////////////////////////////////////////////////////////////////////////////
// ChromeLoginPerformer, private:
Expand Down
12 changes: 7 additions & 5 deletions chrome/browser/chromeos/login/auth/chrome_login_performer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "content/public/browser/notification_registrar.h"
#include "google_apis/gaia/google_service_auth_error.h"

class AccountId;

namespace policy {
class WildcardLoginChecker;
}
Expand All @@ -33,14 +35,14 @@ class ChromeLoginPerformer : public LoginPerformer {
explicit ChromeLoginPerformer(Delegate* delegate);
~ChromeLoginPerformer() override;

bool IsUserWhitelisted(const std::string& user_id,
bool IsUserWhitelisted(const AccountId& account_id,
bool* wildcard_match) override;

protected:
bool RunTrustedCheck(const base::Closure& callback) override;
void DidRunTrustedCheck(const base::Closure& callback);

void RunOnlineWhitelistCheck(const std::string& user_id,
void RunOnlineWhitelistCheck(const AccountId& account_id,
bool wildcard_match,
const std::string& refresh_token,
const base::Closure& success_callback,
Expand All @@ -52,12 +54,12 @@ class ChromeLoginPerformer : public LoginPerformer {

UserContext TransformSupervisedKey(const UserContext& context) override;

void SetupSupervisedUserFlow(const std::string& user_id) override;
void SetupSupervisedUserFlow(const AccountId& account_id) override;

void SetupEasyUnlockUserFlow(const std::string& user_id) override;
void SetupEasyUnlockUserFlow(const AccountId& account_id) override;

scoped_refptr<Authenticator> CreateAuthenticator() override;
bool CheckPolicyForUser(const std::string& user_id) override;
bool CheckPolicyForUser(const AccountId& account_id) override;
content::BrowserContext* GetSigninContext() override;
net::URLRequestContextGetter* GetSigninRequestContext() override;

Expand Down
27 changes: 16 additions & 11 deletions chrome/browser/chromeos/login/easy_unlock/bootstrap_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,22 @@ BootstrapManager::BootstrapManager(Delegate* delegate)
BootstrapManager::~BootstrapManager() {
}

void BootstrapManager::AddPendingBootstrap(const std::string& user_id) {
DCHECK(!user_id.empty());
void BootstrapManager::AddPendingBootstrap(const AccountId& account_id) {
DCHECK(account_id.is_valid());
PrefService* local_state = g_browser_process->local_state();

ListPrefUpdate update(local_state, kPendingEasyBootstrapUsers);
update->AppendString(user_id);
update->AppendString(account_id.GetUserEmail());
}

void BootstrapManager::FinishPendingBootstrap(const std::string& user_id) {
void BootstrapManager::FinishPendingBootstrap(const AccountId& account_id) {
PrefService* local_state = g_browser_process->local_state();

ListPrefUpdate update(local_state, kPendingEasyBootstrapUsers);
for (size_t i = 0; i < update->GetSize(); ++i) {
std::string current_user;
if (update->GetString(i, &current_user) && user_id == current_user) {
std::string current_user_email;
if (update->GetString(i, &current_user_email) &&
account_id.GetUserEmail() == current_user_email) {
update->Remove(i, NULL);
break;
}
Expand All @@ -58,23 +59,27 @@ void BootstrapManager::RemoveAllPendingBootstrap() {
const base::ListValue* users =
local_state->GetList(kPendingEasyBootstrapUsers);
for (size_t i = 0; i < users->GetSize(); ++i) {
std::string current_user;
if (users->GetString(i, &current_user))
delegate_->RemovePendingBootstrapUser(current_user);
std::string current_user_email;
if (users->GetString(i, &current_user_email)) {
delegate_->RemovePendingBootstrapUser(
user_manager::UserManager::Get()->GetKnownUserAccountId(
current_user_email, std::string() /* gaia_id */));
}
}

local_state->ClearPref(kPendingEasyBootstrapUsers);
local_state->CommitPendingWrite();
}

bool BootstrapManager::HasPendingBootstrap(const std::string& user_id) const {
bool BootstrapManager::HasPendingBootstrap(const AccountId& account_id) const {
PrefService* local_state = g_browser_process->local_state();

const base::ListValue* users =
local_state->GetList(kPendingEasyBootstrapUsers);
for (size_t i = 0; i < users->GetSize(); ++i) {
std::string current_user;
if (users->GetString(i, &current_user) && user_id == current_user)
if (users->GetString(i, &current_user) &&
account_id.GetUserEmail() == current_user)
return true;
}
return false;
Expand Down
9 changes: 5 additions & 4 deletions chrome/browser/chromeos/login/easy_unlock/bootstrap_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "base/macros.h"

class AccountId;
class PrefRegistrySimple;

namespace chromeos {
Expand All @@ -21,7 +22,7 @@ class BootstrapManager {

class Delegate {
public:
virtual void RemovePendingBootstrapUser(const std::string& user_id) = 0;
virtual void RemovePendingBootstrapUser(const AccountId& account_id) = 0;

protected:
virtual ~Delegate() {}
Expand All @@ -30,11 +31,11 @@ class BootstrapManager {
explicit BootstrapManager(Delegate* delegate);
~BootstrapManager();

void AddPendingBootstrap(const std::string& user_id);
void FinishPendingBootstrap(const std::string& user_id);
void AddPendingBootstrap(const AccountId& account_id);
void FinishPendingBootstrap(const AccountId& account_id);
void RemoveAllPendingBootstrap();

bool HasPendingBootstrap(const std::string& user_id) const;
bool HasPendingBootstrap(const AccountId& account_id) const;

private:
Delegate* delegate_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ void BootstrapUserContextInitializer::OnGetEasyUnlockData(
service->AddObserver(this);

static_cast<EasyUnlockServiceSignin*>(service)
->SetCurrentUser(user_context_.GetAccountId().GetUserEmail());
->SetCurrentUser(user_context_.GetAccountId());
OnScreenlockStateChanged(service->GetScreenlockState());
}

void BootstrapUserContextInitializer::OnEasyUnlockAuthenticated(
EasyUnlockAuthAttempt::Type auth_attempt_type,
bool success,
const std::string& user_id,
const AccountId& account_id,
const std::string& key_secret,
const std::string& key_label) {
DCHECK_EQ(EasyUnlockAuthAttempt::TYPE_SIGNIN, auth_attempt_type);
Expand Down Expand Up @@ -202,7 +202,7 @@ void BootstrapUserContextInitializer::OnScreenlockStateChanged(
service->RemoveObserver(this);

service->AttemptAuth(
user_context_.GetAccountId().GetUserEmail(),
user_context_.GetAccountId(),
base::Bind(&BootstrapUserContextInitializer::OnEasyUnlockAuthenticated,
weak_ptr_factory_.GetWeakPtr()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "chromeos/login/auth/user_context.h"
#include "google_apis/gaia/gaia_oauth_client.h"

class AccountId;

namespace chromeos {

// Performs initialization work for adding a new account via Easy bootstrap.
Expand Down Expand Up @@ -52,7 +54,7 @@ class BootstrapUserContextInitializer final
const EasyUnlockDeviceKeyDataList& data_list);
void OnEasyUnlockAuthenticated(EasyUnlockAuthAttempt::Type auth_attempt_type,
bool success,
const std::string& user_id,
const AccountId& account_id,
const std::string& key_secret,
const std::string& key_label);
void CreateRandomKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ namespace chromeos {

BootstrapUserFlow::BootstrapUserFlow(const UserContext& user_context,
bool is_new_account)
: ExtendedUserFlow(user_context.GetAccountId().GetUserEmail()),
: ExtendedUserFlow(user_context.GetAccountId()),
user_context_(user_context),
is_new_account_(is_new_account),
finished_(false),
user_profile_(nullptr),
weak_ptr_factory_(this) {
ChromeUserManager::Get()->GetBootstrapManager()->AddPendingBootstrap(
user_context_.GetAccountId().GetUserEmail());
user_context_.GetAccountId());
}

BootstrapUserFlow::~BootstrapUserFlow() {
Expand Down Expand Up @@ -111,7 +111,7 @@ void BootstrapUserFlow::Finish() {
finished_ = true;

ChromeUserManager::Get()->GetBootstrapManager()->FinishPendingBootstrap(
user_context_.GetAccountId().GetUserEmail());
user_context_.GetAccountId());
UserSessionManager::GetInstance()->DoBrowserLaunch(user_profile_, host());

user_profile_ = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const char kSalt[] =
EasyUnlockChallengeWrapper::EasyUnlockChallengeWrapper(
const std::string& challenge,
const std::string& channel_binding_data,
const std::string& user_id,
const AccountId& account_id,
EasyUnlockTpmKeyManager* key_manager)
: challenge_(challenge),
channel_binding_data_(channel_binding_data),
user_id_(user_id),
account_id_(account_id),
key_manager_(key_manager),
weak_ptr_factory_(this) {}

Expand Down Expand Up @@ -62,7 +62,7 @@ void EasyUnlockChallengeWrapper::WrapChallenge(
void EasyUnlockChallengeWrapper::SignUsingTpmKey(
const std::string& data_to_sign,
const base::Callback<void(const std::string&)>& callback) {
key_manager_->SignUsingTpmKey(user_id_, data_to_sign, callback);
key_manager_->SignUsingTpmKey(account_id_, data_to_sign, callback);
}

void EasyUnlockChallengeWrapper::OnChannelBindingDataSigned(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "components/signin/core/account_id/account_id.h"

class EasyUnlockTpmKeyManager;

Expand All @@ -24,12 +25,12 @@ class EasyUnlockChallengeWrapper {
// |challenge|: The raw challenge to wrap.
// |channel_binding_data|: Data unique to the current secure channel such that
// we can bind with a TPM signature.
// |user_id|: The id of the user who owns both devices.
// |account_id|: The id of the user who owns both devices.
// |key_manager|: Responsible for signing some piece of data with the TPM.
// Not owned and should outlive this instance.
EasyUnlockChallengeWrapper(const std::string& challenge,
const std::string& channel_binding_data,
const std::string& user_id,
const AccountId& account_id,
EasyUnlockTpmKeyManager* key_manager);
virtual ~EasyUnlockChallengeWrapper();

Expand Down Expand Up @@ -59,7 +60,7 @@ class EasyUnlockChallengeWrapper {
const std::string channel_binding_data_;

// The id of the user who owns both devices.
const std::string user_id_;
const AccountId account_id_;

// Responsible for signing data with the TPM. Not owned.
EasyUnlockTpmKeyManager* key_manager_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TestableEasyUnlockChallengeWrapper : public EasyUnlockChallengeWrapper {
TestableEasyUnlockChallengeWrapper()
: EasyUnlockChallengeWrapper(kChallenge,
kChannelBindingData,
kUserId,
AccountId::FromUserEmail(kUserId),
nullptr) {}
~TestableEasyUnlockChallengeWrapper() override {}

Expand Down
Loading

0 comments on commit 546380c

Please sign in to comment.