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 44f2863a2e3afc0489aab0de057b078e25c597aa..14aee2c8e9c667a6a9cb8a26be2e3ac7b222e995 100644 |
--- a/chrome/browser/ui/views/profiles/new_avatar_button.cc |
+++ b/chrome/browser/ui/views/profiles/new_avatar_button.cc |
@@ -12,8 +12,10 @@ |
#include "chrome/browser/profiles/profile_attributes_entry.h" |
#include "chrome/browser/profiles/profile_manager.h" |
#include "chrome/browser/profiles/profiles_state.h" |
+#include "chrome/browser/sync/profile_sync_service_factory.h" |
#include "chrome/browser/ui/views/profiles/avatar_button_delegate.h" |
#include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
+#include "components/browser_sync/browser/profile_sync_service.h" |
#include "components/signin/core/common/profile_management_switches.h" |
#include "grit/theme_resources.h" |
#include "ui/base/resource/resource_bundle.h" |
@@ -51,13 +53,67 @@ std::unique_ptr<views::Border> CreateBorder(const int normal_image_set[], |
} // namespace |
+SyncErrorController* GetSyncErrorControllerIfNeeded(Profile* profile) { |
+ if (!switches::IsMaterialDesignUserMenu()) |
+ return nullptr; |
+ ProfileSyncService* sync_service = |
+ ProfileSyncServiceFactory::GetForProfile(profile); |
+ return sync_service ? sync_service->sync_error_controller() : nullptr; |
+} |
+ |
+NewAvatarButton::SigninErrorObserver::SigninErrorObserver( |
+ NewAvatarButton* parent_button, |
+ Profile* profile) |
+ : parent_button_(parent_button), profile_(profile) { |
+ // 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* signin_error_controller = |
+ profiles::GetSigninErrorController(profile_); |
+ if (signin_error_controller) |
+ signin_error_controller->AddObserver(this); |
+} |
+ |
+NewAvatarButton::SigninErrorObserver::~SigninErrorObserver() { |
+ SigninErrorController* signin_error_controller = |
+ profiles::GetSigninErrorController(profile_); |
+ if (signin_error_controller) |
+ signin_error_controller->RemoveObserver(this); |
+} |
+ |
+void NewAvatarButton::SigninErrorObserver::OnErrorChanged() { |
+ parent_button_->OnErrorChanged(); |
+} |
+ |
+NewAvatarButton::SyncErrorObserver::SyncErrorObserver( |
+ NewAvatarButton* parent_button, |
+ Profile* profile) |
+ : parent_button_(parent_button), profile_(profile) { |
+ SyncErrorController* sync_error_controller = |
+ GetSyncErrorControllerIfNeeded(profile_); |
+ if (sync_error_controller) |
+ sync_error_controller->AddObserver(this); |
+} |
+ |
+NewAvatarButton::SyncErrorObserver::~SyncErrorObserver() { |
+ SyncErrorController* sync_error_controller = |
+ GetSyncErrorControllerIfNeeded(profile_); |
+ if (sync_error_controller) |
+ sync_error_controller->RemoveObserver(this); |
+} |
+ |
+void NewAvatarButton::SyncErrorObserver::OnErrorChanged() { |
+ parent_button_->OnErrorChanged(); |
+} |
+ |
NewAvatarButton::NewAvatarButton(AvatarButtonDelegate* delegate, |
AvatarButtonStyle button_style, |
Profile* profile) |
: LabelButton(delegate, base::string16()), |
+ signin_error_observer_(this, profile), |
+ sync_error_observer_(this, profile), |
delegate_(delegate), |
profile_(profile), |
- has_auth_error_(false), |
+ has_error_(false), |
suppress_mouse_released_action_(false) { |
set_triggerable_event_flags( |
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); |
@@ -104,25 +160,13 @@ NewAvatarButton::NewAvatarButton(AvatarButtonDelegate* delegate, |
g_browser_process->profile_manager()-> |
GetProfileAttributesStorage().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(profile_); |
- if (error) { |
- error->AddObserver(this); |
- OnErrorChanged(); // This calls Update(). |
- } else { |
- Update(); |
- } |
+ OnErrorChanged(); |
SchedulePaint(); |
} |
NewAvatarButton::~NewAvatarButton() { |
g_browser_process->profile_manager()-> |
GetProfileAttributesStorage().RemoveObserver(this); |
- SigninErrorController* error = |
- profiles::GetSigninErrorController(profile_); |
- if (error) |
- error->RemoveObserver(this); |
} |
bool NewAvatarButton::OnMousePressed(const ui::MouseEvent& event) { |
@@ -149,6 +193,29 @@ void NewAvatarButton::OnGestureEvent(ui::GestureEvent* event) { |
LabelButton::OnGestureEvent(event); |
} |
+void NewAvatarButton::OnErrorChanged() { |
+ // If there is a signin error, show a warning icon. |
+ const SigninErrorController* signin_error_controller = |
+ profiles::GetSigninErrorController(profile_); |
+ has_error_ = signin_error_controller && signin_error_controller->HasError(); |
+ |
+ // Also show a warning icon for sync errors for the material design user menu. |
+ ProfileSyncService* sync_service = |
+ ProfileSyncServiceFactory::GetForProfile(profile_); |
+ if (switches::IsMaterialDesignUserMenu() && sync_service) { |
+ SyncErrorController* sync_error_controller = |
+ sync_service->sync_error_controller(); |
+ ProfileSyncService::Status status; |
+ sync_service->QueryDetailedSyncStatus(&status); |
+ has_error_ |= |
+ (sync_service->HasUnrecoverableError() || |
+ status.sync_protocol_error.action == syncer::UPGRADE_CLIENT || |
+ (sync_error_controller && sync_error_controller->HasError())); |
+ } |
+ |
+ Update(); |
+} |
+ |
void NewAvatarButton::OnProfileAdded(const base::FilePath& profile_path) { |
Update(); |
} |
@@ -175,15 +242,6 @@ void NewAvatarButton::OnProfileSupervisedUserIdChanged( |
Update(); |
} |
-void NewAvatarButton::OnErrorChanged() { |
- // If there is an error, show an warning icon. |
- const SigninErrorController* error = |
- profiles::GetSigninErrorController(profile_); |
- has_auth_error_ = error && error->HasError(); |
- |
- Update(); |
-} |
- |
void NewAvatarButton::Update() { |
ProfileAttributesStorage& storage = |
g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
@@ -213,7 +271,7 @@ void NewAvatarButton::Update() { |
if (use_generic_button) { |
SetImage(views::Button::STATE_NORMAL, generic_avatar_); |
- } else if (has_auth_error_) { |
+ } else if (has_error_) { |
if (switches::IsMaterialDesignUserMenu()) { |
SetImage(views::Button::STATE_NORMAL, |
gfx::CreateVectorIcon(gfx::VectorIconId::SYNC_PROBLEM, 13, |