Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4444)

Unified Diff: chrome/browser/ui/views/profiles/new_avatar_button.cc

Issue 1009403002: Refactor the avatar button/icon class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/profiles/new_avatar_button.cc
diff --git a/chrome/browser/ui/views/profiles/new_avatar_button.cc b/chrome/browser/ui/views/profiles/new_avatar_button.cc
index 0fa981f6ef08fb36f9c2566b4ac52aaac0c5089a..8e05f13bed488b6f57e4eb6e14d725f76e37aff5 100644
--- a/chrome/browser/ui/views/profiles/new_avatar_button.cc
+++ b/chrome/browser/ui/views/profiles/new_avatar_button.cc
@@ -46,8 +46,8 @@ scoped_ptr<views::Border> CreateBorder(const int normal_image_set[],
NewAvatarButton::NewAvatarButton(views::ButtonListener* listener,
AvatarButtonStyle button_style,
Browser* browser)
- : LabelButton(listener, base::string16()),
- browser_(browser),
+ : AvatarBaseController(browser),
+ LabelButton(listener, base::string16()),
has_auth_error_(false),
suppress_mouse_released_action_(false) {
set_triggerable_event_flags(
@@ -95,12 +95,10 @@ NewAvatarButton::NewAvatarButton(views::ButtonListener* listener,
*rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_AVATAR).ToImageSkia();
}
- g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this);
-
// Subscribe to authentication error changes so that the avatar button can
// update itself. Note that guest mode profiles won't have a token service.
SigninErrorController* error =
- profiles::GetSigninErrorController(browser_->profile());
+ profiles::GetSigninErrorController(browser->profile());
if (error) {
error->AddObserver(this);
OnErrorChanged(); // This calls Update().
@@ -111,10 +109,8 @@ NewAvatarButton::NewAvatarButton(views::ButtonListener* listener,
}
NewAvatarButton::~NewAvatarButton() {
- g_browser_process->profile_manager()->
- GetProfileInfoCache().RemoveObserver(this);
SigninErrorController* error =
- profiles::GetSigninErrorController(browser_->profile());
+ profiles::GetSigninErrorController(browser()->profile());
if (error)
error->RemoveObserver(this);
}
@@ -132,41 +128,6 @@ void NewAvatarButton::OnMouseReleased(const ui::MouseEvent& event) {
LabelButton::OnMouseReleased(event);
}
-void NewAvatarButton::OnProfileAdded(const base::FilePath& profile_path) {
- Update();
-}
-
-void NewAvatarButton::OnProfileWasRemoved(
- const base::FilePath& profile_path,
- const base::string16& profile_name) {
- // If deleting the active profile, don't bother updating the avatar
- // button, as the browser window is being closed anyway.
- if (browser_->profile()->GetPath() != profile_path)
- Update();
-}
-
-void NewAvatarButton::OnProfileNameChanged(
- const base::FilePath& profile_path,
- const base::string16& old_profile_name) {
- if (browser_->profile()->GetPath() == profile_path)
- Update();
-}
-
-void NewAvatarButton::OnProfileSupervisedUserIdChanged(
- const base::FilePath& profile_path) {
- if (browser_->profile()->GetPath() == profile_path)
- Update();
-}
-
-void NewAvatarButton::OnErrorChanged() {
- // If there is an error, show an warning icon.
- const SigninErrorController* error =
- profiles::GetSigninErrorController(browser_->profile());
- has_auth_error_ = error && error->HasError();
-
- Update();
-}
-
void NewAvatarButton::Update() {
const ProfileInfoCache& cache =
g_browser_process->profile_manager()->GetProfileInfoCache();
@@ -174,12 +135,12 @@ void NewAvatarButton::Update() {
// If we have a single local profile, then use the generic avatar
// button instead of the profile name. Never use the generic button if
// the active profile is Guest.
- bool use_generic_button = (!browser_->profile()->IsGuestSession() &&
+ bool use_generic_button = (!browser()->profile()->IsGuestSession() &&
cache.GetNumberOfProfiles() == 1 &&
cache.GetUserNameOfProfileAtIndex(0).empty());
SetText(use_generic_button ? base::string16() :
- profiles::GetAvatarButtonTextForProfile(browser_->profile()));
+ profiles::GetAvatarButtonTextForProfile(browser()->profile()));
// If the button has no text, clear the text shadows to make sure the
// image is centered correctly.
@@ -209,3 +170,12 @@ void NewAvatarButton::Update() {
PreferredSizeChanged();
}
+
+void NewAvatarButton::OnErrorChanged() {
+ // If there is an error, show an warning icon.
noms (inactive) 2015/03/26 15:26:56 nit: a warning*
yao 2015/03/26 18:45:01 Done.
+ const SigninErrorController* error =
+ profiles::GetSigninErrorController(browser()->profile());
+ has_auth_error_ = error && error->HasError();
+
+ Update();
+}

Powered by Google App Engine
This is Rietveld 408576698