Commit 9d2cfc0d authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Update views/profiles for ephemeral Guest profiles.

Updates a few chrome/browser/ui/views/profiles/* classes for
compatibility with ephemeral Guest profiles.

Please see go/ephemeral-guest-profiles for more context.

Bug: 1125474
Change-Id: Ie11779eebf17c6a8dc93eb5ad88279112faa9836
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2461315
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816466}
parent 4c28846b
...@@ -89,6 +89,12 @@ gfx::Image GetAvatarImage(Profile* profile, ...@@ -89,6 +89,12 @@ gfx::Image GetAvatarImage(Profile* profile,
return entry->GetAvatarIcon(preferred_size); return entry->GetAvatarIcon(preferred_size);
} }
// TODO(crbug.com/1125474): Replace IsGuest(profile) calls with
// Profile::IsGuestProfile() after IsEphemeralGuestProfile is fully migrated.
bool IsGuest(Profile* profile) {
return profile->IsGuestSession() || profile->IsEphemeralGuestProfile();
}
} // namespace } // namespace
AvatarToolbarButtonDelegate::AvatarToolbarButtonDelegate() = default; AvatarToolbarButtonDelegate::AvatarToolbarButtonDelegate() = default;
...@@ -161,14 +167,14 @@ gfx::Image AvatarToolbarButtonDelegate::GetProfileAvatarImage( ...@@ -161,14 +167,14 @@ gfx::Image AvatarToolbarButtonDelegate::GetProfileAvatarImage(
} }
int AvatarToolbarButtonDelegate::GetWindowCount() const { int AvatarToolbarButtonDelegate::GetWindowCount() const {
if (profile_->IsGuestSession()) if (IsGuest(profile_))
return BrowserList::GetGuestBrowserCount(); return BrowserList::GetGuestBrowserCount();
DCHECK(profile_->IsOffTheRecord()); DCHECK(profile_->IsOffTheRecord());
return BrowserList::GetOffTheRecordBrowsersActiveForProfile(profile_); return BrowserList::GetOffTheRecordBrowsersActiveForProfile(profile_);
} }
AvatarToolbarButton::State AvatarToolbarButtonDelegate::GetState() const { AvatarToolbarButton::State AvatarToolbarButtonDelegate::GetState() const {
if (profile_->IsGuestSession()) if (IsGuest(profile_))
return AvatarToolbarButton::State::kGuestSession; return AvatarToolbarButton::State::kGuestSession;
// Return |kIncognitoProfile| state for all OffTheRecord profile types except // Return |kIncognitoProfile| state for all OffTheRecord profile types except
......
...@@ -153,6 +153,12 @@ bool IsSyncPaused(Profile* profile) { ...@@ -153,6 +153,12 @@ bool IsSyncPaused(Profile* profile) {
sync_ui_util::AUTH_ERROR; sync_ui_util::AUTH_ERROR;
} }
// TODO(crbug.com/1125474): Replace IsGuest(profile) calls with
// Profile::IsGuestProfile() after IsEphemeralGuestProfile is fully migrated.
bool IsGuest(Profile* profile) {
return profile->IsGuestSession() || profile->IsEphemeralGuestProfile();
}
} // namespace } // namespace
// ProfileMenuView --------------------------------------------------------- // ProfileMenuView ---------------------------------------------------------
...@@ -171,13 +177,12 @@ ProfileMenuView::~ProfileMenuView() = default; ...@@ -171,13 +177,12 @@ ProfileMenuView::~ProfileMenuView() = default;
void ProfileMenuView::BuildMenu() { void ProfileMenuView::BuildMenu() {
Profile* profile = browser()->profile(); Profile* profile = browser()->profile();
const bool is_guest = profile->IsGuestSession(); if (IsGuest(profile)) {
if (profile->IsRegularProfile()) { BuildGuestIdentity();
} else if (profile->IsRegularProfile()) {
BuildIdentity(); BuildIdentity();
BuildSyncInfo(); BuildSyncInfo();
BuildAutofillButtons(); BuildAutofillButtons();
} else if (is_guest) {
BuildGuestIdentity();
} else { } else {
NOTREACHED(); NOTREACHED();
} }
...@@ -186,7 +191,7 @@ void ProfileMenuView::BuildMenu() { ...@@ -186,7 +191,7 @@ void ProfileMenuView::BuildMenu() {
// ChromeOS doesn't support multi-profile. // ChromeOS doesn't support multi-profile.
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
if (!(is_guest && if (!(IsGuest(profile) &&
base::FeatureList::IsEnabled(features::kNewProfilePicker))) { base::FeatureList::IsEnabled(features::kNewProfilePicker))) {
BuildProfileManagementHeading(); BuildProfileManagementHeading();
BuildSelectableProfiles(); BuildSelectableProfiles();
...@@ -580,9 +585,8 @@ void ProfileMenuView::BuildFeatureButtons() { ...@@ -580,9 +585,8 @@ void ProfileMenuView::BuildFeatureButtons() {
Profile* profile = browser()->profile(); Profile* profile = browser()->profile();
signin::IdentityManager* identity_manager = signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile); IdentityManagerFactory::GetForProfile(profile);
const bool is_guest = profile->IsGuestSession();
const bool has_unconsented_account = const bool has_unconsented_account =
!is_guest && !IsGuest(profile) &&
identity_manager->HasPrimaryAccount(signin::ConsentLevel::kNotRequired); identity_manager->HasPrimaryAccount(signin::ConsentLevel::kNotRequired);
if (has_unconsented_account && !IsSyncPaused(profile)) { if (has_unconsented_account && !IsSyncPaused(profile)) {
...@@ -606,7 +610,8 @@ void ProfileMenuView::BuildFeatureButtons() { ...@@ -606,7 +610,8 @@ void ProfileMenuView::BuildFeatureButtons() {
} }
int window_count = CountBrowsersFor(profile); int window_count = CountBrowsersFor(profile);
if (base::FeatureList::IsEnabled(features::kNewProfilePicker) && is_guest) { if (base::FeatureList::IsEnabled(features::kNewProfilePicker) &&
IsGuest(profile)) {
AddFeatureButton( AddFeatureButton(
l10n_util::GetPluralStringFUTF16(IDS_GUEST_PROFILE_MENU_CLOSE_BUTTON, l10n_util::GetPluralStringFUTF16(IDS_GUEST_PROFILE_MENU_CLOSE_BUTTON,
window_count), window_count),
...@@ -626,7 +631,7 @@ void ProfileMenuView::BuildFeatureButtons() { ...@@ -626,7 +631,7 @@ void ProfileMenuView::BuildFeatureButtons() {
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
const bool has_primary_account = const bool has_primary_account =
!is_guest && identity_manager->HasPrimaryAccount(); !IsGuest(profile) && identity_manager->HasPrimaryAccount();
// The sign-out button is always at the bottom. // The sign-out button is always at the bottom.
if (has_unconsented_account && !has_primary_account) { if (has_unconsented_account && !has_primary_account) {
AddFeatureButton( AddFeatureButton(
...@@ -666,7 +671,7 @@ void ProfileMenuView::BuildSelectableProfiles() { ...@@ -666,7 +671,7 @@ void ProfileMenuView::BuildSelectableProfiles() {
PrefService* service = g_browser_process->local_state(); PrefService* service = g_browser_process->local_state();
DCHECK(service); DCHECK(service);
if (!browser()->profile()->IsGuestSession() && if (!IsGuest(browser()->profile()) &&
service->GetBoolean(prefs::kBrowserGuestModeEnabled)) { service->GetBoolean(prefs::kBrowserGuestModeEnabled)) {
AddSelectableProfile( AddSelectableProfile(
profiles::GetGuestAvatar(), profiles::GetGuestAvatar(),
......
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