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 44f2863a2e3afc0489aab0de057b078e25c597aa..a35a18e1a069ed71ebd034bb1da57c45bef27e75 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,69 @@ 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_(new SigninErrorObserver(this, profile)), |
| + sync_error_observer_(switches::IsMaterialDesignUserMenu() |
| + ? new SyncErrorObserver(this, profile) |
| + : nullptr), |
| 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,12 +162,12 @@ 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(). |
| + SigninErrorController* signin_error_controller = |
| + profiles::GetSigninErrorController(profile_); |
| + SyncErrorController* sync_error_controller = |
| + GetSyncErrorControllerIfNeeded(profile_); |
| + if (signin_error_controller || sync_error_controller) { |
| + OnErrorChanged(); // This calls Update() |
|
msw
2016/07/14 17:47:52
nit: Just always call OnErrorChanged here and remo
Jane
2016/07/14 17:59:44
Done.
|
| } else { |
| Update(); |
| } |
| @@ -119,10 +177,6 @@ NewAvatarButton::NewAvatarButton(AvatarButtonDelegate* delegate, |
| 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 +203,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 +252,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 +281,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, |