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

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

Issue 2179283002: Refactored signin/sync error controllers for the avatar button (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Uninitialized ptr Created 4 years, 4 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 14aee2c8e9c667a6a9cb8a26be2e3ac7b222e995..e4d4b8a84f01e3fe8d02a01a8fd433865eb7fc57 100644
--- a/chrome/browser/ui/views/profiles/new_avatar_button.cc
+++ b/chrome/browser/ui/views/profiles/new_avatar_button.cc
@@ -12,10 +12,8 @@
#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"
@@ -53,67 +51,13 @@ 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),
+ error_controller_(this, profile),
profile_(profile),
- has_error_(false),
suppress_mouse_released_action_(false) {
set_triggerable_event_flags(
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON);
@@ -159,8 +103,7 @@ NewAvatarButton::NewAvatarButton(AvatarButtonDelegate* delegate,
g_browser_process->profile_manager()->
GetProfileAttributesStorage().AddObserver(this);
-
- OnErrorChanged();
+ Update();
SchedulePaint();
}
@@ -193,26 +136,7 @@ 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()));
- }
-
+void NewAvatarButton::OnAvatarErrorChanged() {
Update();
}
@@ -271,7 +195,7 @@ void NewAvatarButton::Update() {
if (use_generic_button) {
SetImage(views::Button::STATE_NORMAL, generic_avatar_);
- } else if (has_error_) {
+ } else if (error_controller_.HasAvatarError()) {
if (switches::IsMaterialDesignUserMenu()) {
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(gfx::VectorIconId::SYNC_PROBLEM, 13,
« no previous file with comments | « chrome/browser/ui/views/profiles/new_avatar_button.h ('k') | chrome/browser/ui/views/profiles/profile_chooser_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698