Commit 31a8d2d3 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

SyncAuthManager: Expose static DetermineAccountToUse

This will be used by some autofill metrics.

Bug: 903290
Change-Id: I40df75f93a3b25d1beb2ba77cb231a227b44c8ab
Reviewed-on: https://chromium-review.googlesource.com/c/1350984Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611116}
parent ce93e49d
...@@ -351,27 +351,25 @@ void SyncAuthManager::ResetRequestAccessTokenBackoffForTest() { ...@@ -351,27 +351,25 @@ void SyncAuthManager::ResetRequestAccessTokenBackoffForTest() {
request_access_token_backoff_.Reset(); request_access_token_backoff_.Reset();
} }
SyncAuthManager::SyncAccountInfo SyncAuthManager::DetermineAccountToUse() // static
const { SyncAuthManager::SyncAccountInfo SyncAuthManager::DetermineAccountToUse(
DCHECK(registered_for_auth_notifications_); identity::IdentityManager* identity_manager,
bool allow_secondary_accounts) {
// If there is a "primary account", i.e. the user explicitly chose to // If there is a "primary account", i.e. the user explicitly chose to
// sign-in to Chrome, then always use that account. // sign-in to Chrome, then always use that account.
if (identity_manager_->HasPrimaryAccount()) { if (identity_manager->HasPrimaryAccount()) {
return SyncAccountInfo(identity_manager_->GetPrimaryAccountInfo(), return SyncAccountInfo(identity_manager->GetPrimaryAccountInfo(),
/*is_primary=*/true); /*is_primary=*/true);
} }
// Otherwise, fall back to the default content area signed-in account. // Otherwise, fall back to the default content area signed-in account.
// TODO(crbug.com/871221): Add tests for this code path. if (allow_secondary_accounts) {
if (base::FeatureList::IsEnabled(switches::kSyncStandaloneTransport) &&
base::FeatureList::IsEnabled(switches::kSyncSupportSecondaryAccount)) {
// Check if there is a content area signed-in account, and we have a refresh // Check if there is a content area signed-in account, and we have a refresh
// token for it. // token for it.
std::vector<AccountInfo> cookie_accounts = std::vector<AccountInfo> cookie_accounts =
identity_manager_->GetAccountsInCookieJar(); identity_manager->GetAccountsInCookieJar();
if (!cookie_accounts.empty() && if (!cookie_accounts.empty() &&
identity_manager_->HasAccountWithRefreshToken( identity_manager->HasAccountWithRefreshToken(
cookie_accounts[0].account_id)) { cookie_accounts[0].account_id)) {
return SyncAccountInfo(cookie_accounts[0], /*is_primary=*/false); return SyncAccountInfo(cookie_accounts[0], /*is_primary=*/false);
} }
...@@ -379,6 +377,15 @@ SyncAuthManager::SyncAccountInfo SyncAuthManager::DetermineAccountToUse() ...@@ -379,6 +377,15 @@ SyncAuthManager::SyncAccountInfo SyncAuthManager::DetermineAccountToUse()
return SyncAccountInfo(); return SyncAccountInfo();
} }
SyncAuthManager::SyncAccountInfo SyncAuthManager::DetermineAccountToUse()
const {
DCHECK(registered_for_auth_notifications_);
return DetermineAccountToUse(
identity_manager_,
base::FeatureList::IsEnabled(switches::kSyncStandaloneTransport) &&
base::FeatureList::IsEnabled(switches::kSyncSupportSecondaryAccount));
}
bool SyncAuthManager::UpdateSyncAccountIfNecessary() { bool SyncAuthManager::UpdateSyncAccountIfNecessary() {
SyncAccountInfo new_account = DetermineAccountToUse(); SyncAccountInfo new_account = DetermineAccountToUse();
// If we're already using this account and its |is_primary| bit hasn't changed // If we're already using this account and its |is_primary| bit hasn't changed
......
...@@ -109,9 +109,14 @@ class SyncAuthManager : public identity::IdentityManager::Observer { ...@@ -109,9 +109,14 @@ class SyncAuthManager : public identity::IdentityManager::Observer {
bool IsRetryingAccessTokenFetchForTest() const; bool IsRetryingAccessTokenFetchForTest() const;
void ResetRequestAccessTokenBackoffForTest(); void ResetRequestAccessTokenBackoffForTest();
private:
// Determines which account should be used for Sync and returns the // Determines which account should be used for Sync and returns the
// corresponding AccountInfo. // corresponding SyncAccountInfo. This is exposed so that autofill metrics
// code can use it.
static SyncAccountInfo DetermineAccountToUse(
identity::IdentityManager* identity_manager,
bool allow_secondary_accounts);
private:
SyncAccountInfo DetermineAccountToUse() const; SyncAccountInfo DetermineAccountToUse() const;
// Updates |sync_account_| to the appropriate account (i.e. // Updates |sync_account_| to the appropriate account (i.e.
......
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