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

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: After refactoring 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
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"
12 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 11 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
13 #include "chrome/browser/profiles/profile_manager.h" 12 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/profiles/profile_metrics.h" 13 #include "chrome/browser/profiles/profile_metrics.h"
15 #include "chrome/browser/profiles/profile_window.h" 14 #include "chrome/browser/profiles/profile_window.h"
16 #include "chrome/browser/profiles/profiles_state.h" 15 #include "chrome/browser/profiles/profiles_state.h"
17 #include "chrome/browser/signin/chrome_signin_helper.h" 16 #include "chrome/browser/signin/chrome_signin_helper.h"
18 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_commands.h" 18 #include "chrome/browser/ui/browser_commands.h"
20 #include "chrome/browser/ui/browser_window.h" 19 #include "chrome/browser/ui/browser_window.h"
21 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" 20 #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
22 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 21 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
23 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h" 22 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h"
24 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" 23 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
25 #include "components/signin/core/browser/signin_error_controller.h"
26 #include "components/signin/core/common/profile_management_switches.h" 24 #include "components/signin/core/common/profile_management_switches.h"
27 #include "ui/base/cocoa/cocoa_base_utils.h" 25 #include "ui/base/cocoa/cocoa_base_utils.h"
28 26
29 // Space between the avatar icon and the avatar menu bubble. 27 // Space between the avatar icon and the avatar menu bubble.
30 const CGFloat kMenuYOffsetAdjust = 1.0; 28 const CGFloat kMenuYOffsetAdjust = 1.0;
31 // Offset needed to align the edge of the avatar bubble with the edge of the 29 // Offset needed to align the edge of the avatar bubble with the edge of the
32 // avatar button. 30 // avatar button.
33 const CGFloat kMenuXOffsetAdjust = 2.0; 31 const CGFloat kMenuXOffsetAdjust = 2.0;
34 32
35 @interface AvatarBaseController (Private) 33 @interface AvatarBaseController (Private)
36 // Shows the avatar bubble. 34 // Shows the avatar bubble.
37 - (IBAction)buttonClicked:(id)sender; 35 - (IBAction)buttonClicked:(id)sender;
38 - (IBAction)buttonRightClicked:(id)sender; 36 - (IBAction)buttonRightClicked:(id)sender;
39 37
40 - (void)bubbleWillClose:(NSNotification*)notif; 38 - (void)bubbleWillClose:(NSNotification*)notif;
41 39
42 // Updates the profile name displayed by the avatar button. If |layoutParent| is 40 // Updates the profile name displayed by the avatar button. If |layoutParent| is
43 // yes, then the BrowserWindowController is notified to relayout the subviews, 41 // yes, then the BrowserWindowController is notified to relayout the subviews,
44 // as the button needs to be repositioned. 42 // as the button needs to be repositioned.
45 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; 43 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent;
46 44
47 // Displays an error icon if any accounts associated with this profile have an 45 // Displays an error icon if any accounts associated with this profile have an
48 // auth error. 46 // auth error or sync error.
49 - (void)updateErrorStatus:(BOOL)hasError; 47 - (void)setErrorStatus:(BOOL)hasError;
50 @end 48 @end
51 49
52 class ProfileAttributesUpdateObserver 50 ProfileUpdateObserver::ProfileUpdateObserver(
53 : public ProfileAttributesStorage::Observer, 51 Profile* profile,
54 public SigninErrorController::Observer { 52 AvatarBaseController* avatarController)
55 public: 53 : errorController_(this, profile),
56 ProfileAttributesUpdateObserver(Profile* profile, 54 profile_(profile),
57 AvatarBaseController* avatarController) 55 avatarController_(avatarController) {
58 : profile_(profile), 56 g_browser_process->profile_manager()
59 avatarController_(avatarController) { 57 ->GetProfileAttributesStorage()
60 g_browser_process->profile_manager()-> 58 .AddObserver(this);
61 GetProfileAttributesStorage().AddObserver(this); 59 }
62 60
63 // Subscribe to authentication error changes so that the avatar button 61 ProfileUpdateObserver::~ProfileUpdateObserver() {
64 // can update itself. 62 g_browser_process->profile_manager()
65 SigninErrorController* errorController = 63 ->GetProfileAttributesStorage()
66 profiles::GetSigninErrorController(profile_); 64 .RemoveObserver(this);
67 if (errorController) 65 }
68 errorController->AddObserver(this);
69 }
70 66
71 ~ProfileAttributesUpdateObserver() override { 67 void ProfileUpdateObserver::OnProfileAdded(const base::FilePath& profile_path) {
72 g_browser_process->profile_manager()-> 68 [avatarController_ updateAvatarButtonAndLayoutParent:YES];
73 GetProfileAttributesStorage().RemoveObserver(this); 69 }
74 SigninErrorController* errorController =
75 profiles::GetSigninErrorController(profile_);
76 if (errorController)
77 errorController->RemoveObserver(this);
78 }
79 70
80 // ProfileAttributesStorage::Observer: 71 void ProfileUpdateObserver::OnProfileWasRemoved(
81 void OnProfileAdded(const base::FilePath& profile_path) override { 72 const base::FilePath& profile_path,
73 const base::string16& profile_name) {
74 // If deleting the active profile, don't bother updating the avatar
75 // button, as the browser window is being closed anyway.
76 if (profile_->GetPath() != profile_path)
82 [avatarController_ updateAvatarButtonAndLayoutParent:YES]; 77 [avatarController_ updateAvatarButtonAndLayoutParent:YES];
83 } 78 }
84 79
85 void OnProfileWasRemoved(const base::FilePath& profile_path, 80 void ProfileUpdateObserver::OnProfileNameChanged(
86 const base::string16& profile_name) override { 81 const base::FilePath& profile_path,
87 // If deleting the active profile, don't bother updating the avatar 82 const base::string16& old_profile_name) {
88 // button, as the browser window is being closed anyway. 83 if (profile_->GetPath() == profile_path)
89 if (profile_->GetPath() != profile_path) 84 [avatarController_ updateAvatarButtonAndLayoutParent:YES];
90 [avatarController_ updateAvatarButtonAndLayoutParent:YES]; 85 }
91 }
92 86
93 void OnProfileNameChanged(const base::FilePath& profile_path, 87 void ProfileUpdateObserver::OnProfileSupervisedUserIdChanged(
94 const base::string16& old_profile_name) override { 88 const base::FilePath& profile_path) {
95 if (profile_->GetPath() == profile_path) 89 if (profile_->GetPath() == profile_path)
96 [avatarController_ updateAvatarButtonAndLayoutParent:YES]; 90 [avatarController_ updateAvatarButtonAndLayoutParent:YES];
97 } 91 }
98 92
99 void OnProfileSupervisedUserIdChanged( 93 void ProfileUpdateObserver::OnAvatarErrorChanged() {
100 const base::FilePath& profile_path) override { 94 [avatarController_ setErrorStatus:errorController_.HasAvatarError()];
101 if (profile_->GetPath() == profile_path) 95 }
102 [avatarController_ updateAvatarButtonAndLayoutParent:YES];
103 }
104 96
105 // SigninErrorController::Observer: 97 bool ProfileUpdateObserver::HasAvatarError() {
106 void OnErrorChanged() override { 98 return errorController_.HasAvatarError();
107 SigninErrorController* errorController = 99 }
108 profiles::GetSigninErrorController(profile_);
109 if (errorController)
110 [avatarController_ updateErrorStatus:errorController->HasError()];
111 }
112
113 private:
114 Profile* profile_;
115 AvatarBaseController* avatarController_; // Weak; owns this.
116
117 DISALLOW_COPY_AND_ASSIGN(ProfileAttributesUpdateObserver);
118 };
119 100
120 @implementation AvatarBaseController 101 @implementation AvatarBaseController
121 102
122 - (id)initWithBrowser:(Browser*)browser { 103 - (id)initWithBrowser:(Browser*)browser {
123 if ((self = [super init])) { 104 if ((self = [super init])) {
124 browser_ = browser; 105 browser_ = browser;
125 profileAttributesObserver_.reset( 106 profileObserver_.reset(
126 new ProfileAttributesUpdateObserver(browser_->profile(), self)); 107 new ProfileUpdateObserver(browser_->profile(), self));
127 } 108 }
128 return self; 109 return self;
129 } 110 }
130 111
131 - (void)dealloc { 112 - (void)dealloc {
132 [self browserWillBeDestroyed]; 113 [self browserWillBeDestroyed];
133 [super dealloc]; 114 [super dealloc];
134 } 115 }
135 116
136 - (void)browserWillBeDestroyed { 117 - (void)browserWillBeDestroyed {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 [static_cast<BrowserWindowController*>(wc) 229 [static_cast<BrowserWindowController*>(wc)
249 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO]; 230 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO];
250 } 231 }
251 menuController_ = nil; 232 menuController_ = nil;
252 } 233 }
253 234
254 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent { 235 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent {
255 NOTREACHED(); 236 NOTREACHED();
256 } 237 }
257 238
258 - (void)updateErrorStatus:(BOOL)hasError { 239 - (void)setErrorStatus:(BOOL)hasError {
259 } 240 }
260 241
261 - (BaseBubbleController*)menuController { 242 - (BaseBubbleController*)menuController {
262 return menuController_; 243 return menuController_;
263 } 244 }
264 245
265 @end 246 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698