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

Side by Side Diff: chrome/browser/ui/cocoa/profiles/avatar_base_controller.mm

Issue 2174973002: [Mac][MD User Menu] Revamped signin/sync error surfacing UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" 5 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/profiles/profile_attributes_storage.h" 11 #include "chrome/browser/profiles/profile_attributes_storage.h"
12 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 12 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
13 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/profiles/profile_metrics.h" 14 #include "chrome/browser/profiles/profile_metrics.h"
15 #include "chrome/browser/profiles/profile_window.h" 15 #include "chrome/browser/profiles/profile_window.h"
16 #include "chrome/browser/profiles/profiles_state.h" 16 #include "chrome/browser/profiles/profiles_state.h"
17 #include "chrome/browser/signin/chrome_signin_helper.h" 17 #include "chrome/browser/signin/chrome_signin_helper.h"
18 #include "chrome/browser/sync/profile_sync_service_factory.h"
18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_commands.h" 20 #include "chrome/browser/ui/browser_commands.h"
20 #include "chrome/browser/ui/browser_window.h" 21 #include "chrome/browser/ui/browser_window.h"
21 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" 22 #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
22 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 23 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
23 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h" 24 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h"
24 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" 25 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
26 #include "components/browser_sync/browser/profile_sync_service.h"
25 #include "components/signin/core/browser/signin_error_controller.h" 27 #include "components/signin/core/browser/signin_error_controller.h"
26 #include "components/signin/core/common/profile_management_switches.h" 28 #include "components/signin/core/common/profile_management_switches.h"
29 #include "components/sync_driver/sync_error_controller.h"
27 #include "ui/base/cocoa/cocoa_base_utils.h" 30 #include "ui/base/cocoa/cocoa_base_utils.h"
28 31
29 // Space between the avatar icon and the avatar menu bubble. 32 // Space between the avatar icon and the avatar menu bubble.
30 const CGFloat kMenuYOffsetAdjust = 1.0; 33 const CGFloat kMenuYOffsetAdjust = 1.0;
31 // Offset needed to align the edge of the avatar bubble with the edge of the 34 // Offset needed to align the edge of the avatar bubble with the edge of the
32 // avatar button. 35 // avatar button.
33 const CGFloat kMenuXOffsetAdjust = 2.0; 36 const CGFloat kMenuXOffsetAdjust = 2.0;
34 37
35 @interface AvatarBaseController (Private) 38 @interface AvatarBaseController (Private)
36 // Shows the avatar bubble. 39 // Shows the avatar bubble.
37 - (IBAction)buttonClicked:(id)sender; 40 - (IBAction)buttonClicked:(id)sender;
38 - (IBAction)buttonRightClicked:(id)sender; 41 - (IBAction)buttonRightClicked:(id)sender;
39 42
40 - (void)bubbleWillClose:(NSNotification*)notif; 43 - (void)bubbleWillClose:(NSNotification*)notif;
41 44
42 // Updates the profile name displayed by the avatar button. If |layoutParent| is 45 // Updates the profile name displayed by the avatar button. If |layoutParent| is
43 // yes, then the BrowserWindowController is notified to relayout the subviews, 46 // yes, then the BrowserWindowController is notified to relayout the subviews,
44 // as the button needs to be repositioned. 47 // as the button needs to be repositioned.
45 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; 48 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent;
46 49
47 // Displays an error icon if any accounts associated with this profile have an 50 // Displays an error icon if any accounts associated with this profile have an
48 // auth error. 51 // auth error or sync error.
52 - (void)updateAuthErrorStatus:(BOOL)hasAuthError;
groby-ooo-7-16 2016/07/22 23:53:15 setXYZ instead of updateXYZ, please?
Jane 2016/08/03 19:57:57 Done.
53 - (void)updateSyncErrorStatus:(BOOL)hasSyncError;
49 - (void)updateErrorStatus:(BOOL)hasError; 54 - (void)updateErrorStatus:(BOOL)hasError;
50 @end 55 @end
51 56
52 class ProfileAttributesUpdateObserver 57 class ProfileAttributesUpdateObserver
53 : public ProfileAttributesStorage::Observer, 58 : public ProfileAttributesStorage::Observer,
54 public SigninErrorController::Observer { 59 public SigninErrorController::Observer {
55 public: 60 public:
56 ProfileAttributesUpdateObserver(Profile* profile, 61 ProfileAttributesUpdateObserver(Profile* profile,
57 AvatarBaseController* avatarController) 62 AvatarBaseController* avatarController)
58 : profile_(profile), 63 : profile_(profile),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 const base::FilePath& profile_path) override { 105 const base::FilePath& profile_path) override {
101 if (profile_->GetPath() == profile_path) 106 if (profile_->GetPath() == profile_path)
102 [avatarController_ updateAvatarButtonAndLayoutParent:YES]; 107 [avatarController_ updateAvatarButtonAndLayoutParent:YES];
103 } 108 }
104 109
105 // SigninErrorController::Observer: 110 // SigninErrorController::Observer:
106 void OnErrorChanged() override { 111 void OnErrorChanged() override {
107 SigninErrorController* errorController = 112 SigninErrorController* errorController =
108 profiles::GetSigninErrorController(profile_); 113 profiles::GetSigninErrorController(profile_);
109 if (errorController) 114 if (errorController)
110 [avatarController_ updateErrorStatus:errorController->HasError()]; 115 [avatarController_ updateAuthErrorStatus:errorController->HasError()];
111 } 116 }
112 117
113 private: 118 private:
114 Profile* profile_; 119 Profile* profile_;
115 AvatarBaseController* avatarController_; // Weak; owns this. 120 AvatarBaseController* avatarController_; // Weak; owns this.
116 121
117 DISALLOW_COPY_AND_ASSIGN(ProfileAttributesUpdateObserver); 122 DISALLOW_COPY_AND_ASSIGN(ProfileAttributesUpdateObserver);
118 }; 123 };
119 124
125 class SyncErrorObserver : public SyncErrorController::Observer {
groby-ooo-7-16 2016/07/22 23:53:16 Please don't inline code in the class declaration.
Jane 2016/08/03 19:57:57 Done. I put the declaration separately in avatar_b
126 public:
127 SyncErrorObserver(Profile* profile, AvatarBaseController* avatarController)
128 : profile_(profile), avatarController_(avatarController) {
129 // Subscribe to sync error changes so that the avatar button can update
groby-ooo-7-16 2016/07/22 23:53:15 If you change "so that the avatar" to "so the avat
Jane 2016/08/03 19:57:57 Done.
130 // itself.
131 SyncErrorController* sync_error_controller =
132 GetSyncErrorControllerIfNeeded(profile_);
133 if (sync_error_controller)
134 sync_error_controller->AddObserver(this);
135 }
136
137 ~SyncErrorObserver() override {
138 SyncErrorController* sync_error_controller =
139 GetSyncErrorControllerIfNeeded(profile_);
140 if (sync_error_controller)
141 sync_error_controller->RemoveObserver(this);
142 }
143
144 private:
145 // SyncErrorController::Observer:
146 void OnErrorChanged() override {
147 ProfileSyncService* sync_service =
148 ProfileSyncServiceFactory::GetForProfile(profile_);
149 bool has_sync_error = false;
150 if (switches::IsMaterialDesignUserMenu() && sync_service) {
151 SyncErrorController* sync_error_controller =
152 sync_service->sync_error_controller();
153 ProfileSyncService::Status status;
154 sync_service->QueryDetailedSyncStatus(&status);
155 has_sync_error =
groby-ooo-7-16 2016/07/22 23:53:15 This code has me a bit confused - it seemed like a
156 (sync_service->HasUnrecoverableError() ||
157 status.sync_protocol_error.action == syncer::UPGRADE_CLIENT ||
158 (sync_error_controller && sync_error_controller->HasError()));
159 }
160 [avatarController_ updateSyncErrorStatus:has_sync_error];
161 }
162
163 SyncErrorController* GetSyncErrorControllerIfNeeded(Profile* profile) {
164 if (!switches::IsMaterialDesignUserMenu())
groby-ooo-7-16 2016/07/22 23:53:15 Same goes for this, which is completely shared wit
165 return nullptr;
166 ProfileSyncService* sync_service =
167 ProfileSyncServiceFactory::GetForProfile(profile);
168 return sync_service ? sync_service->sync_error_controller() : nullptr;
169 }
170
171 Profile* profile_;
172 AvatarBaseController* avatarController_;
173
174 DISALLOW_COPY_AND_ASSIGN(SyncErrorObserver);
175 };
176
120 @implementation AvatarBaseController 177 @implementation AvatarBaseController
121 178
122 - (id)initWithBrowser:(Browser*)browser { 179 - (id)initWithBrowser:(Browser*)browser {
123 if ((self = [super init])) { 180 if ((self = [super init])) {
124 browser_ = browser; 181 browser_ = browser;
125 profileAttributesObserver_.reset( 182 profileAttributesObserver_.reset(
126 new ProfileAttributesUpdateObserver(browser_->profile(), self)); 183 new ProfileAttributesUpdateObserver(browser_->profile(), self));
184 syncErrorObserver_.reset(new SyncErrorObserver(browser_->profile(), self));
127 } 185 }
128 return self; 186 return self;
129 } 187 }
130 188
131 - (void)dealloc { 189 - (void)dealloc {
132 [self browserWillBeDestroyed]; 190 [self browserWillBeDestroyed];
133 [super dealloc]; 191 [super dealloc];
134 } 192 }
135 193
136 - (void)browserWillBeDestroyed { 194 - (void)browserWillBeDestroyed {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 [static_cast<BrowserWindowController*>(wc) 306 [static_cast<BrowserWindowController*>(wc)
249 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO]; 307 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO];
250 } 308 }
251 menuController_ = nil; 309 menuController_ = nil;
252 } 310 }
253 311
254 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent { 312 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent {
255 NOTREACHED(); 313 NOTREACHED();
256 } 314 }
257 315
316 - (void)updateAuthErrorStatus:(BOOL)hasAuthError {
317 hasAuthError_ = hasAuthError;
318 [self updateErrorStatus:(hasAuthError_ || hasSyncError_)];
319 }
320
321 - (void)updateSyncErrorStatus:(BOOL)hasSyncError {
322 hasSyncError_ = hasSyncError;
323 [self updateErrorStatus:(hasAuthError_ || hasSyncError_)];
324 }
325
258 - (void)updateErrorStatus:(BOOL)hasError { 326 - (void)updateErrorStatus:(BOOL)hasError {
259 } 327 }
260 328
261 - (BaseBubbleController*)menuController { 329 - (BaseBubbleController*)menuController {
262 return menuController_; 330 return menuController_;
263 } 331 }
264 332
265 @end 333 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698