Commit 4671054f authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Simplify AuthenticationService implementation

Change internal implementation of two methods of AuthenticationService
to remove unnecessary allocations.

1.  AuthenticationService::MigrateAccountsStoredInPrefsIfNeeded is
    only interested in whether the system has stored refresh token
    for an account by account_id, so use HasAccountWithRefreshToken
    instead of fetching the whole AccountInfo

2.  AuthenticationService::ReloadCredentialsFromIdentities only need
    to check whether the system has a primary account set, and is not
    interested in the email address, so use IsAuthenticated instead
    of GetAuthenticatedUserEmail

Bug: none
Change-Id: If5de15711ef2d2d96dc935162b11aa17c4b245fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1569122
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652542}
parent a7690542
......@@ -253,14 +253,8 @@ void AuthenticationService::MigrateAccountsStoredInPrefsIfNeeded() {
std::vector<std::string> account_ids = GetAccountsInPrefs();
base::ListValue accounts_pref_value;
for (const std::string& account_id : account_ids) {
auto maybe_account =
identity_manager_->FindAccountInfoForAccountWithRefreshTokenByAccountId(
account_id);
AccountInfo account_info =
maybe_account.has_value() ? maybe_account.value() : AccountInfo();
if (!account_info.email.empty()) {
DCHECK(!account_info.gaia.empty());
accounts_pref_value.AppendString(account_info.account_id);
if (identity_manager_->HasAccountWithRefreshToken(account_id)) {
accounts_pref_value.AppendString(account_id);
} else {
// The account for |email| was removed since the last application cold
// start. Insert |kFakeAccountIdForRemovedAccount| to ensure
......@@ -559,7 +553,7 @@ void AuthenticationService::ReloadCredentialsFromIdentities(
base::AutoReset<bool> auto_reset(&is_reloading_credentials_, true);
HandleForgottenIdentity(nil, should_prompt);
if (GetAuthenticatedUserEmail()) {
if (IsAuthenticated()) {
// TODO(crbug.com/930094): Eliminate this.
identity_manager_->LegacyReloadAccountsFromSystem();
}
......
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