Commit db805cc6 authored by Monica Basta's avatar Monica Basta Committed by Commit Bot

[Signin]: Add consent level to GetPrimaryAccount*/HasPrimaryAccount.

The primary account can be butter or sync account depending on the
consent level. This CL adds consent level as a parameter to
GetPrimaryAccount* and HasPrimaryAccount to indicate the consent level
required by the caller. It can be |kNotRequired|, in that case it
returns the corresponding info of the primary account if it exists. If
consent is |kSync|, it returns the corresponding info if the primary
account exists and was granted sync consent.

Bug: 1046746
Change-Id: Id69f1f234228166f347e01f044672836fd88d5be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2033351
Commit-Queue: Monica Basta <msalama@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737791}
parent c023dcbf
...@@ -111,15 +111,22 @@ void IdentityManager::RemoveObserver(Observer* observer) { ...@@ -111,15 +111,22 @@ void IdentityManager::RemoveObserver(Observer* observer) {
} }
// TODO(862619) change return type to base::Optional<CoreAccountInfo> // TODO(862619) change return type to base::Optional<CoreAccountInfo>
CoreAccountInfo IdentityManager::GetPrimaryAccountInfo() const { CoreAccountInfo IdentityManager::GetPrimaryAccountInfo(
ConsentLevel consent) const {
if (consent == ConsentLevel::kNotRequired) {
return GetUnconsentedPrimaryAccountInfo();
}
return primary_account_manager_->GetAuthenticatedAccountInfo(); return primary_account_manager_->GetAuthenticatedAccountInfo();
} }
CoreAccountId IdentityManager::GetPrimaryAccountId() const { CoreAccountId IdentityManager::GetPrimaryAccountId(ConsentLevel consent) const {
return GetPrimaryAccountInfo().account_id; return GetPrimaryAccountInfo(consent).account_id;
} }
bool IdentityManager::HasPrimaryAccount() const { bool IdentityManager::HasPrimaryAccount(ConsentLevel consent) const {
if (consent == ConsentLevel::kNotRequired) {
return HasUnconsentedPrimaryAccount();
}
return primary_account_manager_->IsAuthenticated(); return primary_account_manager_->IsAuthenticated();
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "components/signin/internal/identity_manager/profile_oauth2_token_service_observer.h" #include "components/signin/internal/identity_manager/profile_oauth2_token_service_observer.h"
#include "components/signin/public/identity_manager/access_token_fetcher.h" #include "components/signin/public/identity_manager/access_token_fetcher.h"
#include "components/signin/public/identity_manager/account_info.h" #include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/consent_level.h"
#include "components/signin/public/identity_manager/identity_mutator.h" #include "components/signin/public/identity_manager/identity_mutator.h"
#include "components/signin/public/identity_manager/ubertoken_fetcher.h" #include "components/signin/public/identity_manager/ubertoken_fetcher.h"
#include "google_apis/gaia/oauth2_access_token_manager.h" #include "google_apis/gaia/oauth2_access_token_manager.h"
...@@ -161,19 +162,25 @@ class IdentityManager : public KeyedService, ...@@ -161,19 +162,25 @@ class IdentityManager : public KeyedService,
void RemoveObserver(Observer* observer); void RemoveObserver(Observer* observer);
// Provides access to the core information of the user's primary account. // Provides access to the core information of the user's primary account.
// The primary account may or may not be blessed with the sync consent.
// Returns an empty struct if no such info is available, either because there // Returns an empty struct if no such info is available, either because there
// is no primary account yet or because the user signed out. A non-empty // is no primary account yet or because the user signed out or the |consent|
// struct implies that the user has blessed this account for sync (see // level required |ConsentLevel::kSync| was not granted.
// ./README.md). // Returns a non-empty struct if the primary account exists and was granted
CoreAccountInfo GetPrimaryAccountInfo() const; // the required consent level.
// TODO(1046746): Update (./README.md).
CoreAccountInfo GetPrimaryAccountInfo(
ConsentLevel consent = ConsentLevel::kSync) const;
// Provides access to the account ID of the user's primary account. Simple // Provides access to the account ID of the user's primary account. Simple
// convenience wrapper over GetPrimaryAccountInfo().account_id. // convenience wrapper over GetPrimaryAccountInfo().account_id.
CoreAccountId GetPrimaryAccountId() const; CoreAccountId GetPrimaryAccountId(
ConsentLevel consent = ConsentLevel::kSync) const;
// Returns whether the user's primary account is available. True implies that // Returns whether the user's primary account is available. If consent is
// the user has blessed this account for sync (see ./README.md). // |ConsentLevel::kSyn| then true implies that the user has blessed this
bool HasPrimaryAccount() const; // account for sync.
bool HasPrimaryAccount(ConsentLevel consent = ConsentLevel::kSync) const;
// Provides access to the core information of the user's unconsented primary // Provides access to the core information of the user's unconsented primary
// account (see ./README.md). Returns an empty info, if there is no such // account (see ./README.md). Returns an empty info, if there is no such
......
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