Commit b5378632 authored by Thomas Tangl's avatar Thomas Tangl Committed by Commit Bot

[profile-menu] Resolve BubbleViewMode in ProfileMenuView

This CL removes code paths of unused bubble view modes in
ProfileMenuView and refactors related code.

Bug: 966388
Change-Id: Icece4828989c61d8be9ac85de27874d934fa92ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1751788Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Thomas Tangl <tangltom@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686449}
parent c09cf562
...@@ -64,10 +64,6 @@ namespace { ...@@ -64,10 +64,6 @@ namespace {
// Number of times the Dice sign-in promo illustration should be shown. // Number of times the Dice sign-in promo illustration should be shown.
constexpr int kDiceSigninPromoIllustrationShowCountMax = 10; constexpr int kDiceSigninPromoIllustrationShowCountMax = 10;
bool IsProfileChooser(profiles::BubbleViewMode mode) {
return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER;
}
BadgedProfilePhoto::BadgeType GetProfileBadgeType(Profile* profile) { BadgedProfilePhoto::BadgeType GetProfileBadgeType(Profile* profile) {
if (profile->IsSupervised()) { if (profile->IsSupervised()) {
return profile->IsChild() ? BadgedProfilePhoto::BADGE_TYPE_CHILD return profile->IsChild() ? BadgedProfilePhoto::BADGE_TYPE_CHILD
...@@ -135,11 +131,9 @@ bool ProfileMenuView::close_on_deactivate_for_testing_ = true; ...@@ -135,11 +131,9 @@ bool ProfileMenuView::close_on_deactivate_for_testing_ = true;
ProfileMenuView::ProfileMenuView(views::Button* anchor_button, ProfileMenuView::ProfileMenuView(views::Button* anchor_button,
Browser* browser, Browser* browser,
profiles::BubbleViewMode view_mode,
signin::GAIAServiceType service_type, signin::GAIAServiceType service_type,
signin_metrics::AccessPoint access_point) signin_metrics::AccessPoint access_point)
: ProfileMenuViewBase(anchor_button, browser), : ProfileMenuViewBase(anchor_button, browser),
view_mode_(view_mode),
gaia_service_type_(service_type), gaia_service_type_(service_type),
access_point_(access_point), access_point_(access_point),
dice_enabled_(AccountConsistencyModeManager::IsDiceEnabledForProfile( dice_enabled_(AccountConsistencyModeManager::IsDiceEnabledForProfile(
...@@ -181,13 +175,6 @@ void ProfileMenuView::Init() { ...@@ -181,13 +175,6 @@ void ProfileMenuView::Init() {
this, browser())); this, browser()));
avatar_menu_->RebuildMenu(); avatar_menu_->RebuildMenu();
Profile* profile = browser()->profile();
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile);
if (identity_manager)
identity_manager->AddObserver(this);
if (dice_enabled_) { if (dice_enabled_) {
// Fetch DICE accounts. Note: This always includes the primary account if it // Fetch DICE accounts. Note: This always includes the primary account if it
// is set. // is set.
...@@ -195,68 +182,22 @@ void ProfileMenuView::Init() { ...@@ -195,68 +182,22 @@ void ProfileMenuView::Init() {
signin_ui_util::GetAccountsForDicePromos(browser()->profile()); signin_ui_util::GetAccountsForDicePromos(browser()->profile());
} }
ShowViewOrOpenTab(view_mode_); ShowView(avatar_menu_.get());
} }
void ProfileMenuView::OnAvatarMenuChanged( void ProfileMenuView::OnAvatarMenuChanged(
AvatarMenu* avatar_menu) { AvatarMenu* avatar_menu) {
if (IsProfileChooser(view_mode_)) { // Refresh the view with the new menu. We can't just update the local copy
// Refresh the view with the new menu. We can't just update the local copy // as this may have been triggered by a sign out action, in which case
// as this may have been triggered by a sign out action, in which case // the view is being destroyed.
// the view is being destroyed. ShowView(avatar_menu);
ShowView(view_mode_, avatar_menu);
}
} }
void ProfileMenuView::OnRefreshTokenUpdatedForAccount( void ProfileMenuView::ShowView(AvatarMenu* avatar_menu) {
const CoreAccountInfo& account_info) { AddProfileMenuView(avatar_menu);
if (view_mode_ == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT ||
view_mode_ == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH) {
ShowViewOrOpenTab(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER);
}
}
void ProfileMenuView::ShowView(profiles::BubbleViewMode view_to_display,
AvatarMenu* avatar_menu) {
if (browser()->profile()->IsSupervised() &&
view_to_display == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT) {
LOG(WARNING) << "Supervised user attempted to add account";
return;
}
view_mode_ = view_to_display;
switch (view_mode_) {
case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN:
case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT:
case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH:
// The modal sign-in view is shown in for bubble view modes.
// See |SigninViewController::ShouldShowSigninForMode|.
NOTREACHED();
break;
case profiles::BUBBLE_VIEW_MODE_INCOGNITO:
// Covered in IncognitoView.
NOTREACHED();
break;
case profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER:
AddProfileMenuView(avatar_menu);
break;
}
RepopulateViewFromMenuItems(); RepopulateViewFromMenuItems();
} }
void ProfileMenuView::ShowViewOrOpenTab(profiles::BubbleViewMode mode) {
if (SigninViewController::ShouldShowSigninForMode(mode)) {
// Hides the user menu if it is currently shown. The user menu automatically
// closes when it loses focus; however, on Windows, the signin modals do not
// take away focus, thus we need to manually close the bubble.
Hide();
browser()->signin_view_controller()->ShowSignin(mode, browser(),
access_point_);
} else {
ShowView(mode, avatar_menu_.get());
}
}
void ProfileMenuView::FocusButtonOnKeyboardOpen() { void ProfileMenuView::FocusButtonOnKeyboardOpen() {
if (first_profile_button_) if (first_profile_button_)
first_profile_button_->RequestFocus(); first_profile_button_->RequestFocus();
...@@ -266,10 +207,6 @@ void ProfileMenuView::OnWidgetClosing(views::Widget* /*widget*/) { ...@@ -266,10 +207,6 @@ void ProfileMenuView::OnWidgetClosing(views::Widget* /*widget*/) {
// Unsubscribe from everything early so that the updates do not reach the // Unsubscribe from everything early so that the updates do not reach the
// bubble and change its state. // bubble and change its state.
avatar_menu_.reset(); avatar_menu_.reset();
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(browser()->profile());
if (identity_manager)
identity_manager->RemoveObserver(this);
} }
views::View* ProfileMenuView::GetInitiallyFocusedView() { views::View* ProfileMenuView::GetInitiallyFocusedView() {
...@@ -346,11 +283,15 @@ void ProfileMenuView::ButtonPressed(views::Button* sender, ...@@ -346,11 +283,15 @@ void ProfileMenuView::ButtonPressed(views::Button* sender,
signin::PrimaryAccountMutator::ClearAccountsAction::kDefault, signin::PrimaryAccountMutator::ClearAccountsAction::kDefault,
signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS, signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS,
signin_metrics::SignoutDelete::IGNORE_METRIC); signin_metrics::SignoutDelete::IGNORE_METRIC);
ShowViewOrOpenTab(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN); Hide();
browser()->signin_view_controller()->ShowSignin(
profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN, browser(), access_point_);
} }
break; break;
case sync_ui_util::AUTH_ERROR: case sync_ui_util::AUTH_ERROR:
ShowViewOrOpenTab(profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH); Hide();
browser()->signin_view_controller()->ShowSignin(
profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH, browser(), access_point_);
break; break;
case sync_ui_util::UPGRADE_CLIENT_ERROR: case sync_ui_util::UPGRADE_CLIENT_ERROR:
chrome::OpenUpdateChromeDialog(browser()); chrome::OpenUpdateChromeDialog(browser());
...@@ -378,7 +319,9 @@ void ProfileMenuView::ButtonPressed(views::Button* sender, ...@@ -378,7 +319,9 @@ void ProfileMenuView::ButtonPressed(views::Button* sender,
PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME); PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME);
} }
} else if (sender == signin_current_profile_button_) { } else if (sender == signin_current_profile_button_) {
ShowViewOrOpenTab(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN); Hide();
browser()->signin_view_controller()->ShowSignin(
profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN, browser(), access_point_);
} else if (sender == signin_with_gaia_account_button_) { } else if (sender == signin_with_gaia_account_button_) {
DCHECK(dice_signin_button_view_->account()); DCHECK(dice_signin_button_view_->account());
Hide(); Hide();
......
...@@ -16,10 +16,8 @@ ...@@ -16,10 +16,8 @@
#include "chrome/browser/profiles/avatar_menu_observer.h" #include "chrome/browser/profiles/avatar_menu_observer.h"
#include "chrome/browser/sync/sync_ui_util.h" #include "chrome/browser/sync/sync_ui_util.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/profile_chooser_constants.h"
#include "chrome/browser/ui/views/profiles/profile_menu_view_base.h" #include "chrome/browser/ui/views/profiles/profile_menu_view_base.h"
#include "components/signin/core/browser/signin_header_helper.h" #include "components/signin/core/browser/signin_header_helper.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "ui/views/controls/styled_label.h" #include "ui/views/controls/styled_label.h"
namespace views { namespace views {
...@@ -33,13 +31,10 @@ class HoverButton; ...@@ -33,13 +31,10 @@ class HoverButton;
// This bubble view is displayed when the user clicks on the avatar button. // This bubble view is displayed when the user clicks on the avatar button.
// It displays a list of profiles and allows users to switch between profiles. // It displays a list of profiles and allows users to switch between profiles.
class ProfileMenuView : public ProfileMenuViewBase, class ProfileMenuView : public ProfileMenuViewBase, public AvatarMenuObserver {
public AvatarMenuObserver,
public signin::IdentityManager::Observer {
public: public:
ProfileMenuView(views::Button* anchor_button, ProfileMenuView(views::Button* anchor_button,
Browser* browser, Browser* browser,
profiles::BubbleViewMode view_mode,
signin::GAIAServiceType service_type, signin::GAIAServiceType service_type,
signin_metrics::AccessPoint access_point); signin_metrics::AccessPoint access_point);
~ProfileMenuView() override; ~ProfileMenuView() override;
...@@ -70,10 +65,6 @@ class ProfileMenuView : public ProfileMenuViewBase, ...@@ -70,10 +65,6 @@ class ProfileMenuView : public ProfileMenuViewBase,
// AvatarMenuObserver: // AvatarMenuObserver:
void OnAvatarMenuChanged(AvatarMenu* avatar_menu) override; void OnAvatarMenuChanged(AvatarMenu* avatar_menu) override;
// signin::IdentityManager::Observer overrides.
void OnRefreshTokenUpdatedForAccount(
const CoreAccountInfo& account_info) override;
// We normally close the bubble any time it becomes inactive but this can lead // We normally close the bubble any time it becomes inactive but this can lead
// to flaky tests where unexpected UI events are triggering this behavior. // to flaky tests where unexpected UI events are triggering this behavior.
// Tests set this to "false" for more consistent operation. // Tests set this to "false" for more consistent operation.
...@@ -81,11 +72,8 @@ class ProfileMenuView : public ProfileMenuViewBase, ...@@ -81,11 +72,8 @@ class ProfileMenuView : public ProfileMenuViewBase,
void Reset(); void Reset();
// Shows the bubble with the |view_to_display|. // Shows the bubble view.
void ShowView(profiles::BubbleViewMode view_to_display, void ShowView(AvatarMenu* avatar_menu);
AvatarMenu* avatar_menu);
// Shows the bubble view or opens a tab based on given |mode|.
void ShowViewOrOpenTab(profiles::BubbleViewMode mode);
// Adds the profile chooser view. // Adds the profile chooser view.
void AddProfileMenuView(AvatarMenu* avatar_menu); void AddProfileMenuView(AvatarMenu* avatar_menu);
...@@ -178,9 +166,6 @@ class ProfileMenuView : public ProfileMenuViewBase, ...@@ -178,9 +166,6 @@ class ProfileMenuView : public ProfileMenuViewBase,
// View for the signin/turn-on-sync button in the dice promo. // View for the signin/turn-on-sync button in the dice promo.
DiceSigninButtonView* dice_signin_button_view_; DiceSigninButtonView* dice_signin_button_view_;
// Active view mode.
profiles::BubbleViewMode view_mode_;
// The GAIA service type provided in the response header. // The GAIA service type provided in the response header.
signin::GAIAServiceType gaia_service_type_; signin::GAIAServiceType gaia_service_type_;
......
...@@ -72,17 +72,16 @@ void ProfileMenuViewBase::ShowBubble( ...@@ -72,17 +72,16 @@ void ProfileMenuViewBase::ShowBubble(
if (IsShowing()) if (IsShowing())
return; return;
DCHECK_EQ(browser->profile()->IsIncognitoProfile(),
view_mode == profiles::BUBBLE_VIEW_MODE_INCOGNITO);
ProfileMenuViewBase* bubble; ProfileMenuViewBase* bubble;
if (view_mode == profiles::BUBBLE_VIEW_MODE_INCOGNITO) { if (view_mode == profiles::BUBBLE_VIEW_MODE_INCOGNITO) {
DCHECK(browser->profile()->IsIncognitoProfile());
bubble = new IncognitoMenuView(anchor_button, browser); bubble = new IncognitoMenuView(anchor_button, browser);
} else { } else {
DCHECK_EQ(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, view_mode);
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
bubble = new ProfileMenuView(anchor_button, browser, view_mode, bubble =
manage_accounts_params.service_type, new ProfileMenuView(anchor_button, browser,
access_point); manage_accounts_params.service_type, access_point);
#else #else
NOTREACHED(); NOTREACHED();
return; return;
......
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