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

Side by Side Diff: chrome/browser/ui/avatar_button_error_controller.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: Pure virtual interface 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/avatar_button_error_controller.h"
6
7 #include "chrome/browser/profiles/profiles_state.h"
8 #include "chrome/browser/sync/profile_sync_service_factory.h"
9 #include "components/browser_sync/browser/profile_sync_service.h"
10 #include "components/signin/core/browser/signin_error_controller.h"
11 #include "components/signin/core/common/profile_management_switches.h"
12
13 AvatarButtonErrorController::AvatarButtonErrorController(
14 AvatarButtonErrorControllerDelegate* delegate,
15 Profile* profile)
16 : delegate_(delegate),
17 avatar_signin_error_controller_(profile, this),
18 avatar_sync_error_controller_(profile, this),
19 has_signin_error_(false),
20 has_sync_error_(false) {}
21
22 void AvatarButtonErrorController::GetAvatarErrorUpdate() {
sky 2016/08/01 22:59:40 Can you elaborate on why you need this function? A
Jane 2016/08/02 14:23:18 Done. Makes sense! I refactored the actual error d
23 avatar_signin_error_controller_.OnErrorChanged();
24 avatar_sync_error_controller_.OnErrorChanged();
25 }
26
27 void AvatarButtonErrorController::UpdateSigninError(bool has_signin_error) {
28 has_signin_error_ = has_signin_error;
29 delegate_->OnAvatarErrorChanged();
sky 2016/08/01 22:59:40 The public api for this class is effectively HasAv
Jane 2016/08/02 14:23:18 Done. I added a check for HasAvatarError().
30 }
31
32 void AvatarButtonErrorController::UpdateSyncError(bool has_sync_error) {
33 has_sync_error_ = has_sync_error;
34 delegate_->OnAvatarErrorChanged();
35 }
36
37 AvatarButtonErrorController::SigninErrorObserver::SigninErrorObserver(
38 Profile* profile,
39 AvatarButtonErrorController* avatar_button_error_controller)
40 : profile_(profile),
41 avatar_button_error_controller_(avatar_button_error_controller) {
42 SigninErrorController* signin_error_controller =
43 profiles::GetSigninErrorController(profile_);
44 if (signin_error_controller)
45 signin_error_controller->AddObserver(this);
46 }
47
48 AvatarButtonErrorController::SigninErrorObserver::~SigninErrorObserver() {
49 SigninErrorController* signin_error_controller =
50 profiles::GetSigninErrorController(profile_);
51 if (signin_error_controller)
52 signin_error_controller->RemoveObserver(this);
53 }
54
55 void AvatarButtonErrorController::SigninErrorObserver::OnErrorChanged() {
56 const SigninErrorController* signin_error_controller =
57 profiles::GetSigninErrorController(profile_);
58 avatar_button_error_controller_->UpdateSigninError(
59 signin_error_controller && signin_error_controller->HasError());
60 }
61
62 AvatarButtonErrorController::SyncErrorObserver::SyncErrorObserver(
63 Profile* profile,
64 AvatarButtonErrorController* avatar_button_error_controller)
65 : profile_(profile),
66 avatar_button_error_controller_(avatar_button_error_controller) {
67 SyncErrorController* sync_error_controller = GetSyncErrorControllerIfNeeded();
68 if (sync_error_controller)
69 sync_error_controller->AddObserver(this);
70 }
71
72 AvatarButtonErrorController::SyncErrorObserver::~SyncErrorObserver() {
73 SyncErrorController* sync_error_controller = GetSyncErrorControllerIfNeeded();
74 if (sync_error_controller)
75 sync_error_controller->RemoveObserver(this);
76 }
77
78 void AvatarButtonErrorController::SyncErrorObserver::OnErrorChanged() {
79 ProfileSyncService* sync_service =
80 ProfileSyncServiceFactory::GetForProfile(profile_);
81 if (switches::IsMaterialDesignUserMenu() && sync_service) {
82 SyncErrorController* sync_error_controller =
83 sync_service->sync_error_controller();
84 ProfileSyncService::Status status;
85 sync_service->QueryDetailedSyncStatus(&status);
86 avatar_button_error_controller_->UpdateSyncError(
87 sync_service->HasUnrecoverableError() ||
88 status.sync_protocol_error.action == syncer::UPGRADE_CLIENT ||
89 (sync_error_controller && sync_error_controller->HasError()));
90 } else {
91 avatar_button_error_controller_->UpdateSyncError(false);
92 }
93 }
94
95 SyncErrorController* AvatarButtonErrorController::SyncErrorObserver::
96 GetSyncErrorControllerIfNeeded() {
97 if (!switches::IsMaterialDesignUserMenu())
98 return nullptr;
99 ProfileSyncService* sync_service =
100 ProfileSyncServiceFactory::GetForProfile(profile_);
101 return sync_service ? sync_service->sync_error_controller() : nullptr;
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698