Chromium Code Reviews| 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 239255a6cba156328d3ef3030d24ca5ba8292653..5b43eb407c598ab3efeb2eea3ee85da51779e71d 100644 |
| --- a/chrome/browser/ui/views/profiles/new_avatar_button.cc |
| +++ b/chrome/browser/ui/views/profiles/new_avatar_button.cc |
| @@ -8,7 +8,9 @@ |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/browser/profiles/profiles_state.h" |
| +#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| #include "chrome/browser/ui/browser.h" |
| +#include "components/signin/core/browser/profile_oauth2_token_service.h" |
| #include "grit/generated_resources.h" |
| #include "grit/theme_resources.h" |
| #include "ui/base/l10n/l10n_util.h" |
| @@ -99,20 +101,28 @@ NewAvatarButton::NewAvatarButton( |
| } |
| g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); |
| + |
| + // Subscribe to authentication error changes so that the avatar button |
| + // can update itself. |
| + SigninErrorController* error = |
| + ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())-> |
| + signin_error_controller(); |
| + error->AddObserver(this); |
| + OnErrorChanged(); |
| + |
| SchedulePaint(); |
| } |
| NewAvatarButton::~NewAvatarButton() { |
| g_browser_process->profile_manager()-> |
| GetProfileInfoCache().RemoveObserver(this); |
| + SigninErrorController* error = |
| + ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())-> |
| + signin_error_controller(); |
| + error->RemoveObserver(this); |
| } |
| -void NewAvatarButton::OnPaint(gfx::Canvas* canvas) { |
| - // From TextButton::PaintButton, draw everything but the text. |
| - OnPaintBackground(canvas); |
| - OnPaintBorder(canvas); |
| - views::Painter::PaintFocusPainter(this, canvas, focus_painter()); |
| - |
| +void NewAvatarButton::OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode) { |
| gfx::Rect rect; |
| // In RTL languages the marker gets drawn leftmost, so account for its offset. |
| if (base::i18n::IsRTL()) |
| @@ -127,9 +137,6 @@ void NewAvatarButton::OnPaint(gfx::Canvas* canvas) { |
| SK_ColorDKGRAY, |
| rect, |
| gfx::Canvas::NO_SUBPIXEL_RENDERING); |
| - |
| - // From MenuButton::PaintButton, paint the marker |
| - PaintMenuMarker(canvas); |
| } |
| void NewAvatarButton::OnProfileAdded(const base::FilePath& profile_path) { |
| @@ -148,6 +155,21 @@ void NewAvatarButton::OnProfileNameChanged( |
| UpdateAvatarButtonAndRelayoutParent(); |
| } |
| +void NewAvatarButton::OnErrorChanged() { |
| + gfx::ImageSkia icon; |
| + |
| + // If there is an error, use a special background. |
|
noms (inactive)
2014/05/11 19:21:25
nit: I think the comment is wrong. You're only cha
Roger Tawa OOO till Jul 10th
2014/05/13 21:23:54
Done.
|
| + SigninErrorController* error = |
| + ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())-> |
| + signin_error_controller(); |
| + if (error->HasError()) { |
| + ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| + icon = *rb->GetImageNamed(IDR_WARNING).ToImageSkia(); |
| + } |
| + |
| + SetIcon(icon); |
| +} |
| + |
| void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() { |
| // We want the button to resize if the new text is shorter. |
| ClearMaxTextSize(); |