Commit a7b1bf60 authored by David Roger's avatar David Roger Committed by Commit Bot

[signin] Implement Mice reconciliation for Android

The strategy for reconciliation is to always reconcile, and keep
the current default Gaia account if there is one, otherwise the first
system account. This strategy can be refined later.

Change-Id: Ia1e0e1d08e5f071159b07474ab6d56a169822316
Reviewed-on: https://chromium-review.googlesource.com/c/1475405
Commit-Queue: David Roger <droger@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635575}
parent 6ea29c73
......@@ -261,6 +261,7 @@ source_set("unit_tests") {
"dice_account_reconcilor_delegate_unittest.cc",
"gaia_cookie_manager_service_unittest.cc",
"identity_utils_unittest.cc",
"mice_account_reconcilor_delegate_unittest.cc",
"mutable_profile_oauth2_token_service_delegate_unittest.cc",
"signin_error_controller_unittest.cc",
"signin_header_helper_unittest.cc",
......
......@@ -25,11 +25,6 @@ gaia::GaiaSource MiceAccountReconcilorDelegate::GetGaiaApiSource() const {
return gaia::GaiaSource::kAccountReconcilorMirror;
}
bool MiceAccountReconcilorDelegate::ShouldAbortReconcileIfPrimaryHasError()
const {
return false;
}
std::string MiceAccountReconcilorDelegate::GetFirstGaiaAccountForReconcile(
const std::vector<std::string>& chrome_accounts,
const std::vector<gaia::ListedAccount>& gaia_accounts,
......@@ -48,7 +43,23 @@ MiceAccountReconcilorDelegate::GetChromeAccountsForReconcile(
const std::string& primary_account,
const std::vector<gaia::ListedAccount>& gaia_accounts,
const gaia::MultiloginMode mode) const {
return chrome_accounts;
if (chrome_accounts.empty())
return {};
// First account, by priority order:
// - primary account
// - first account on the device.
// Warning: As a result, the reconciliation may change the default Gaia
// account. It should be ensured that this is not surprising for the user.
std::string new_first_account =
base::ContainsValue(chrome_accounts, primary_account)
? primary_account
: chrome_accounts[0];
// Minimize account shuffling and ensure that the number of accounts does not
// exceed the limit.
return ReorderChromeAccountsForReconcile(chrome_accounts, new_first_account,
gaia_accounts);
}
gaia::MultiloginMode MiceAccountReconcilorDelegate::CalculateModeForReconcile(
......
......@@ -24,7 +24,6 @@ class MiceAccountReconcilorDelegate : public AccountReconcilorDelegate {
bool IsReconcileEnabled() const override;
bool IsAccountConsistencyEnforced() const override;
gaia::GaiaSource GetGaiaApiSource() const override;
bool ShouldAbortReconcileIfPrimaryHasError() const override;
std::string GetFirstGaiaAccountForReconcile(
const std::vector<std::string>& chrome_accounts,
const std::vector<gaia::ListedAccount>& gaia_accounts,
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/signin/core/browser/mice_account_reconcilor_delegate.h"
#include <vector>
#include "google_apis/gaia/gaia_auth_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace signin {
namespace {
// Returns a gaia::ListedAccount with the specified account id.
gaia::ListedAccount BuildTestListedAccount(const std::string account_id,
bool valid) {
gaia::ListedAccount account;
account.id = account_id;
account.valid = valid;
return account;
}
} // namespace
TEST(MiceAccountReconcilorDelegate, CalculateParametersForMultilogin) {
MiceAccountReconcilorDelegate mice_delegate;
const gaia::ListedAccount kA = BuildTestListedAccount("A", /*valid=*/true);
const gaia::ListedAccount kB = BuildTestListedAccount("B", /*valid=*/false);
struct TestParams {
std::vector<std::string> chrome_accounts;
std::string primary_account;
std::vector<gaia::ListedAccount> gaia_accounts;
std::vector<std::string> expected_accounts;
};
// clang-format off
TestParams cases[] = {
// chrome_accounts, primary_account, gaia_accounts, expected_accounts
{{}, "", {}, {}},
{{}, "", {kA, kB}, {}},
{{"A"}, "", {}, {"A"}},
{{"A"}, "", {kA, kB}, {"A"}},
{{"A"}, "", {kB, kA}, {"A"}},
{{"A", "B"}, "", {}, {"A", "B"}},
{{"A", "B"}, "", {kA}, {"A", "B"}},
{{"A", "B"}, "", {kB}, {"A", "B"}},
{{"B", "C"}, "", {kA}, {"B", "C"}},
{{"A", "B"}, "", {kA, kB}, {"A", "B"}},
{{"A", "B"}, "", {kB, kA}, {"A", "B"}},
{{"B", "C"}, "", {kA, kB}, {"B", "C"}},
// Tests the reordering: B remains in 2nd place.
{{"C", "D", "B"}, "", {kA, kB}, {"C", "B", "D"}},
// With primary account.
{{"A", "B"}, "B", {}, {"B", "A"}},
{{"B", "A"}, "A", {kB, kA}, {"A", "B"}},
{{"A", "B"}, "B", {kB, kA}, {"B", "A"}},
};
// clang-format on
for (const auto& test : cases) {
MultiloginParameters multilogin_parameters =
mice_delegate.CalculateParametersForMultilogin(
test.chrome_accounts, test.primary_account, test.gaia_accounts,
false, false);
EXPECT_EQ(gaia::MultiloginMode::MULTILOGIN_UPDATE_COOKIE_ACCOUNTS_ORDER,
multilogin_parameters.mode);
EXPECT_EQ(test.expected_accounts, multilogin_parameters.accounts_to_send);
}
}
} // namespace signin
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