Commit de2a6eda authored by Jan Krcal's avatar Jan Krcal Committed by Commit Bot

[Avatar button] Use the new unconsented primary account API

This CL updates the rest of the avatar toolbar button code to use the
new API for retrieving the unconsented primary account from
IdentityManager.

Bug: 983182
Change-Id: Ib1c2be250a49ecfbab7e15e52130d834b5320457
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1781690
Commit-Queue: Jan Krcal <jkrcal@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693159}
parent dbf3878b
...@@ -129,8 +129,8 @@ void AvatarToolbarButton::UpdateIcon() { ...@@ -129,8 +129,8 @@ void AvatarToolbarButton::UpdateIcon() {
gfx::Image gaia_image = GetGaiaImage(); gfx::Image gaia_image = GetGaiaImage();
SetImage(views::Button::STATE_NORMAL, GetAvatarIcon(gaia_image)); SetImage(views::Button::STATE_NORMAL, GetAvatarIcon(gaia_image));
// TODO(crbug.com/983182): Move this logic to OnExtendedAccountInfoUpdated() // TODO(crbug.com/990286): Get rid of this logic completely when we cache the
// once GetGaiaImage() is updated to use GetUnconsentedPrimaryAccountInfo(). // Google account image in the profile cache and thus it is always available.
if (waiting_for_image_to_show_user_email_ && !gaia_image.IsEmpty()) { if (waiting_for_image_to_show_user_email_ && !gaia_image.IsEmpty()) {
waiting_for_image_to_show_user_email_ = false; waiting_for_image_to_show_user_email_ = false;
ExpandToShowEmail(); ExpandToShowEmail();
...@@ -316,10 +316,11 @@ bool AvatarToolbarButton::ShouldShowGenericIcon() const { ...@@ -316,10 +316,11 @@ bool AvatarToolbarButton::ShouldShowGenericIcon() const {
// This function should only be used for regular profiles. Guest and Incognito // This function should only be used for regular profiles. Guest and Incognito
// sessions should be handled separately and never call this function. // sessions should be handled separately and never call this function.
DCHECK(profile_->IsRegularProfile()); DCHECK(profile_->IsRegularProfile());
#if !defined(OS_CHROMEOS)
if (!signin_ui_util::GetAccountsForDicePromos(profile_).empty()) if (IdentityManagerFactory::GetForProfile(profile_)
->HasUnconsentedPrimaryAccount()) {
return false; return false;
#endif // !defined(OS_CHROMEOS) }
ProfileAttributesEntry* entry = GetProfileAttributesEntry(profile_); ProfileAttributesEntry* entry = GetProfileAttributesEntry(profile_);
if (!entry) { if (!entry) {
...@@ -335,8 +336,7 @@ bool AvatarToolbarButton::ShouldShowGenericIcon() const { ...@@ -335,8 +336,7 @@ bool AvatarToolbarButton::ShouldShowGenericIcon() const {
return entry->GetAvatarIconIndex() == 0 && return entry->GetAvatarIconIndex() == 0 &&
g_browser_process->profile_manager() g_browser_process->profile_manager()
->GetProfileAttributesStorage() ->GetProfileAttributesStorage()
.GetNumberOfProfiles() == 1 && .GetNumberOfProfiles() == 1;
!IdentityManagerFactory::GetForProfile(profile_)->HasPrimaryAccount();
} }
base::string16 AvatarToolbarButton::GetAvatarTooltipText() const { base::string16 AvatarToolbarButton::GetAvatarTooltipText() const {
...@@ -422,26 +422,24 @@ gfx::Image AvatarToolbarButton::GetGaiaImage() const { ...@@ -422,26 +422,24 @@ gfx::Image AvatarToolbarButton::GetGaiaImage() const {
return gfx::Image(); return gfx::Image();
} }
#if !defined(OS_CHROMEOS)
// Try to show the first account icon of the sync promo when the following // Try to show the first account icon of the sync promo when the following
// conditions are satisfied: // conditions are satisfied:
// - the user is migrated to Dice // - the user is migrated to Dice
// - the user isn't signed in // - the user isn't signed in
// - the profile icon wasn't explicitly changed // - the profile icon wasn't explicitly changed
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile_);
if (AccountConsistencyModeManager::IsDiceEnabledForProfile(profile_) && if (AccountConsistencyModeManager::IsDiceEnabledForProfile(profile_) &&
!IdentityManagerFactory::GetForProfile(profile_)->HasPrimaryAccount() && !identity_manager->HasPrimaryAccount() &&
identity_manager->HasUnconsentedPrimaryAccount() &&
entry->IsUsingDefaultAvatar()) { entry->IsUsingDefaultAvatar()) {
// TODO(crbug.com/983182): Update to use GetUnconsentedPrimaryAccountInfo() base::Optional<AccountInfo> account_info =
// and maybe move this whole logic to OnExtendedAccountInfoUpdated() which identity_manager
// is the only callback where the image can change (and cache the resulting ->FindExtendedAccountInfoForAccountWithRefreshTokenByAccountId(
// image as and cache it as |unconsented_primary_account_gaia_image_|). identity_manager->GetUnconsentedPrimaryAccountId());
std::vector<AccountInfo> promo_accounts = if (account_info.has_value())
signin_ui_util::GetAccountsForDicePromos(profile_); return account_info->account_image;
if (!promo_accounts.empty()) {
return promo_accounts.front().account_image;
}
} }
#endif // !defined(OS_CHROMEOS)
return gfx::Image(); return gfx::Image();
} }
......
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