Commit 898f2182 authored by Anastasiia N's avatar Anastasiia N Committed by Commit Bot

Add CheckDummyGaiaTokenForAllAccounts method to AccountManager

Migrate signin_error_notifier to the new method so it doesn't use
HasDummyGaiaTokenSync.

Bug: 1135980
Change-Id: I76bdd810bcfdb5952868469b23898b1b10644e99
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2454081
Commit-Queue: Anastasiia N <anastasiian@chromium.org>
Reviewed-by: default avatarKush Sinha <sinhak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817054}
parent 959dbe24
...@@ -65,10 +65,11 @@ void HandleDeviceAccountReauthNotificationClick( ...@@ -65,10 +65,11 @@ void HandleDeviceAccountReauthNotificationClick(
} }
bool AreAllAccountsMigrated( bool AreAllAccountsMigrated(
const chromeos::AccountManager* const account_manager, const std::vector<std::pair<chromeos::AccountManager::Account, bool>>&
const std::vector<chromeos::AccountManager::Account>& accounts) { account_dummy_token_list) {
for (const auto& account : accounts) { for (const auto& account : account_dummy_token_list) {
if (account_manager->HasDummyGaiaTokenSync(account.key)) { if (account.second) {
// Account has a dummy Gaia token.
return false; return false;
} }
} }
...@@ -77,13 +78,12 @@ bool AreAllAccountsMigrated( ...@@ -77,13 +78,12 @@ bool AreAllAccountsMigrated(
// Returns true if the child user has migrated at least one of their // Returns true if the child user has migrated at least one of their
// secondary edu accounts to ARC++. // secondary edu accounts to ARC++.
bool IsSecondaryEduAccountMigratedForChildUser( bool IsSecondaryEduAccountMigratedForChildUser(Profile* profile,
Profile* profile, int accounts_size) {
const std::vector<chromeos::AccountManager::Account>& accounts) {
// If the profile is not a child then there is no migration required. // If the profile is not a child then there is no migration required.
// If the profile is child but has only one account on device, then there is // If the profile is child but has only one account on device, then there is
// no migration required; i.e. there is no secondary edu account to migrate. // no migration required; i.e. there is no secondary edu account to migrate.
if (!profile->IsChild() || accounts.size() < 2) { if (!profile->IsChild() || accounts_size < 2) {
return true; return true;
} }
...@@ -251,12 +251,14 @@ void SigninErrorNotifier::HandleDeviceAccountError() { ...@@ -251,12 +251,14 @@ void SigninErrorNotifier::HandleDeviceAccountError() {
void SigninErrorNotifier::HandleSecondaryAccountError( void SigninErrorNotifier::HandleSecondaryAccountError(
const CoreAccountId& account_id) { const CoreAccountId& account_id) {
account_manager_->GetAccounts(base::BindOnce( account_manager_->CheckDummyGaiaTokenForAllAccounts(
&SigninErrorNotifier::OnGetAccounts, weak_factory_.GetWeakPtr())); base::BindOnce(&SigninErrorNotifier::OnCheckDummyGaiaTokenForAllAccounts,
weak_factory_.GetWeakPtr()));
} }
void SigninErrorNotifier::OnGetAccounts( void SigninErrorNotifier::OnCheckDummyGaiaTokenForAllAccounts(
const std::vector<chromeos::AccountManager::Account>& accounts) { const std::vector<std::pair<chromeos::AccountManager::Account, bool>>&
account_dummy_token_list) {
message_center::NotifierId notifier_id( message_center::NotifierId notifier_id(
message_center::NotifierType::SYSTEM_COMPONENT, message_center::NotifierType::SYSTEM_COMPONENT,
kProfileSigninNotificationId); kProfileSigninNotificationId);
...@@ -267,8 +269,9 @@ void SigninErrorNotifier::OnGetAccounts( ...@@ -267,8 +269,9 @@ void SigninErrorNotifier::OnGetAccounts(
multi_user_util::GetAccountIdFromProfile(profile_).GetUserEmail(); multi_user_util::GetAccountIdFromProfile(profile_).GetUserEmail();
const bool are_all_accounts_migrated = const bool are_all_accounts_migrated =
AreAllAccountsMigrated(account_manager_, accounts) && AreAllAccountsMigrated(account_dummy_token_list) &&
IsSecondaryEduAccountMigratedForChildUser(profile_, accounts); IsSecondaryEduAccountMigratedForChildUser(
profile_, account_dummy_token_list.size());
const base::string16 message_title = const base::string16 message_title =
are_all_accounts_migrated are_all_accounts_migrated
......
...@@ -54,9 +54,11 @@ class SigninErrorNotifier : public SigninErrorController::Observer, ...@@ -54,9 +54,11 @@ class SigninErrorNotifier : public SigninErrorController::Observer,
// for the Secondary Account which received an error. // for the Secondary Account which received an error.
void HandleSecondaryAccountError(const CoreAccountId& account_id); void HandleSecondaryAccountError(const CoreAccountId& account_id);
// |chromeos::AccountManager::GetAccounts| callback handler. // |chromeos::AccountManager::CheckDummyGaiaTokenForAllAccounts| callback
void OnGetAccounts( // handler.
const std::vector<chromeos::AccountManager::Account>& accounts); void OnCheckDummyGaiaTokenForAllAccounts(
const std::vector<std::pair<chromeos::AccountManager::Account, bool>>&
account_dummy_token_list);
void OnTokenHandleCheck(const AccountId& account_id, void OnTokenHandleCheck(const AccountId& account_id,
TokenHandleUtil::TokenHandleStatus status); TokenHandleUtil::TokenHandleStatus status);
......
...@@ -657,6 +657,25 @@ void AccountManager::HasDummyGaiaToken( ...@@ -657,6 +657,25 @@ void AccountManager::HasDummyGaiaToken(
it->second.token == kInvalidToken); it->second.token == kInvalidToken);
} }
void AccountManager::CheckDummyGaiaTokenForAllAccounts(
base::OnceCallback<void(const std::vector<std::pair<Account, bool>>&)>
callback) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// TODO(anastasiian): Remove this DCHECK and call |RunOnInitialization|
// instead.
DCHECK_EQ(init_state_, InitializationState::kInitialized);
std::vector<std::pair<Account, bool>> accounts_list;
accounts_list.reserve(accounts_.size());
for (const auto& key_val : accounts_) {
accounts_list.emplace_back(Account{key_val.first, key_val.second.raw_email},
key_val.second.token == kInvalidToken);
}
std::move(callback).Run(accounts_list);
}
void AccountManager::MaybeRevokeTokenOnServer(const AccountKey& account_key, void AccountManager::MaybeRevokeTokenOnServer(const AccountKey& account_key,
const std::string& old_token) { const std::string& old_token) {
if ((account_key.account_type == if ((account_key.account_type ==
......
...@@ -250,6 +250,14 @@ class COMPONENT_EXPORT(ACCOUNT_MANAGER) AccountManager { ...@@ -250,6 +250,14 @@ class COMPONENT_EXPORT(ACCOUNT_MANAGER) AccountManager {
void HasDummyGaiaToken(const AccountKey& account_key, void HasDummyGaiaToken(const AccountKey& account_key,
base::OnceCallback<void(bool)> callback) const; base::OnceCallback<void(bool)> callback) const;
// Calls the |callback| with a list of pairs of |account_key| and boolean
// which is set to true if the token stored against |account_key| is a dummy
// Gaia token, for all accounts stored in AccountManager. See
// |HasDummyGaiaToken|.
void CheckDummyGaiaTokenForAllAccounts(
base::OnceCallback<void(const std::vector<std::pair<Account, bool>>&)>
callback) const;
private: private:
enum InitializationState { enum InitializationState {
kNotStarted, // Initialize has not been called kNotStarted, // Initialize has not been called
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment