Skip to content

Commit

Permalink
Preserve the orginal behaviour of IdentityGetAccountsFunction::Run
Browse files Browse the repository at this point in the history
https://crrev.com/c/1456058 ported IdentityGetAccountsFunction::Run to
talk to the IdentityManager C++ instead of Mojo. In doing so, it changed
the returned account list order. This CL reworks the code to keep the
primary account as the first account in the list.

Bug: 928184
Change-Id: Ic6d305154fc4c46641e0ef2a3d58022ddfeb5de6
Reviewed-on: https://chromium-review.googlesource.com/c/1457316
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Reviewed-by: Colin Blundell <blundell@chromium.org>
Reviewed-by: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630281}
  • Loading branch information
hferreiro authored and Commit Bot committed Feb 8, 2019
1 parent 87f4290 commit ea16947
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,21 @@ ExtensionFunction::ResponseAction IdentityGetAccountsFunction::Run() {

auto* identity_manager = IdentityManagerFactory::GetForProfile(profile);
api::identity::AccountInfo account_info;
if (primary_account_only) {
// If extensions are restricted to the primary account, only return the
// account info when there is a valid primary account.
if (identity_manager->HasPrimaryAccountWithRefreshToken()) {
account_info.id = identity_manager->GetPrimaryAccountInfo().gaia;
infos->Append(account_info.ToValue());
}
} else {

// Ensure that the primary account is inserted first; even though this
// semantics isn't documented, the implementation has always ensured it and it
// shouldn't be changed without determining that it is safe to do so.
if (identity_manager->HasPrimaryAccountWithRefreshToken()) {
account_info.id = identity_manager->GetPrimaryAccountInfo().gaia;
infos->Append(account_info.ToValue());
}

// If secondary accounts are supported, add all the secondary accounts as
// well.
if (!primary_account_only) {
for (const auto& account : accounts) {
if (account.account_id == identity_manager->GetPrimaryAccountId())
continue;
account_info.id = account.gaia;
infos->Append(account_info.ToValue());
}
Expand Down

0 comments on commit ea16947

Please sign in to comment.