forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync: Move DetermineAccountToUse into new sync_auth_util.h/cc
This is a followup to https://crrev.com/c/1350984. In particular, this moves the code from /components/browser_sync/ into /components/sync/, where autofill code can actually access it. Bug: 903290 Change-Id: Id7b90cf5c1344cb4404d9a672d057a67e74d35b9 Reviewed-on: https://chromium-review.googlesource.com/c/1352160 Reviewed-by: Sebastien Seguin-Gagnon <sebsg@chromium.org> Reviewed-by: Jan Krcal <jkrcal@chromium.org> Commit-Queue: Marc Treib <treib@chromium.org> Cr-Commit-Position: refs/heads/master@{#611277}
- Loading branch information
Marc Treib
authored and
Commit Bot
committed
Nov 27, 2018
1 parent
52f0d91
commit 2b0e8e6
Showing
5 changed files
with
89 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2018 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/sync/driver/sync_auth_util.h" | ||
|
||
#include <vector> | ||
|
||
#include "services/identity/public/cpp/identity_manager.h" | ||
|
||
namespace syncer { | ||
|
||
SyncAccountInfo::SyncAccountInfo() = default; | ||
|
||
SyncAccountInfo::SyncAccountInfo(const AccountInfo& account_info, | ||
bool is_primary) | ||
: account_info(account_info), is_primary(is_primary) {} | ||
|
||
SyncAccountInfo DetermineAccountToUse( | ||
identity::IdentityManager* identity_manager, | ||
bool allow_secondary_accounts) { | ||
// If there is a "primary account", i.e. the user explicitly chose to | ||
// sign-in to Chrome, then always use that account. | ||
if (identity_manager->HasPrimaryAccount()) { | ||
return SyncAccountInfo(identity_manager->GetPrimaryAccountInfo(), | ||
/*is_primary=*/true); | ||
} | ||
|
||
// Otherwise, fall back to the default content area signed-in account. | ||
if (allow_secondary_accounts) { | ||
// Check if there is a content area signed-in account, and we have a refresh | ||
// token for it. | ||
std::vector<AccountInfo> cookie_accounts = | ||
identity_manager->GetAccountsInCookieJar(); | ||
if (!cookie_accounts.empty() && | ||
identity_manager->HasAccountWithRefreshToken( | ||
cookie_accounts[0].account_id)) { | ||
return SyncAccountInfo(cookie_accounts[0], /*is_primary=*/false); | ||
} | ||
} | ||
return SyncAccountInfo(); | ||
} | ||
|
||
} // namespace syncer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2018 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. | ||
|
||
#ifndef COMPONENTS_SYNC_DRIVER_SYNC_AUTH_UTIL_H_ | ||
#define COMPONENTS_SYNC_DRIVER_SYNC_AUTH_UTIL_H_ | ||
|
||
#include "components/signin/core/browser/account_info.h" | ||
|
||
namespace identity { | ||
class IdentityManager; | ||
} // namespace identity | ||
|
||
namespace syncer { | ||
|
||
struct SyncAccountInfo { | ||
SyncAccountInfo(); | ||
SyncAccountInfo(const AccountInfo& account_info, bool is_primary); | ||
|
||
AccountInfo account_info; | ||
bool is_primary = false; | ||
}; | ||
|
||
// Determines which account should be used for Sync and returns the | ||
// corresponding SyncAccountInfo. This is exposed so that autofill metrics | ||
// code can use it. | ||
SyncAccountInfo DetermineAccountToUse( | ||
identity::IdentityManager* identity_manager, | ||
bool allow_secondary_accounts); | ||
|
||
} // namespace syncer | ||
|
||
#endif // COMPONENTS_SYNC_DRIVER_SYNC_AUTH_UTIL_H_ |