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

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

Issue 303463010: [Mac] Show a warning in the new avatar button/menu if there's an auth error (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
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 "chrome/app/chrome_command_ids.h" 7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/profile_info_cache_observer.h" 9 #include "chrome/browser/profiles/profile_info_cache_observer.h"
10 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 10 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
11 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/profiles/profile_metrics.h" 12 #include "chrome/browser/profiles/profile_metrics.h"
13 #include "chrome/browser/profiles/profiles_state.h"
13 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_commands.h" 15 #include "chrome/browser/ui/browser_commands.h"
15 #include "chrome/browser/ui/browser_window.h" 16 #include "chrome/browser/ui/browser_window.h"
16 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" 17 #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 18 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
18 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h" 19 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h"
19 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" 20 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
21 #include "components/signin/core/browser/signin_error_controller.h"
20 #include "components/signin/core/common/profile_management_switches.h" 22 #include "components/signin/core/common/profile_management_switches.h"
21 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
22 24
23 // Space between the avatar icon and the avatar menu bubble. 25 // Space between the avatar icon and the avatar menu bubble.
24 const CGFloat kMenuYOffsetAdjust = 1.0; 26 const CGFloat kMenuYOffsetAdjust = 1.0;
25 27
26 @interface AvatarBaseController (Private) 28 @interface AvatarBaseController (Private)
27 // Shows the avatar bubble. 29 // Shows the avatar bubble.
28 - (IBAction)buttonClicked:(id)sender; 30 - (IBAction)buttonClicked:(id)sender;
29 - (void)bubbleWillClose:(NSNotification*)notif; 31 - (void)bubbleWillClose:(NSNotification*)notif;
30 // Updates the profile name displayed by the avatar button. If |layoutParent| is 32 // Updates the profile name displayed by the avatar button. If |layoutParent| is
31 // yes, then the BrowserWindowController is notified to relayout the subviews, 33 // yes, then the BrowserWindowController is notified to relayout the subviews,
32 // as the button needs to be repositioned. 34 // as the button needs to be repositioned.
33 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; 35 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent;
36 - (void)updateErrorStatus:(BOOL)hasError;
msw 2014/06/03 04:15:31 nit: consider a more descriptive name or add a com
noms (inactive) 2014/06/06 20:33:43 Done.
34 @end 37 @end
35 38
36 class ProfileInfoUpdateObserver : public ProfileInfoCacheObserver { 39 class ProfileInfoUpdateObserver : public ProfileInfoCacheObserver,
40 public SigninErrorController::Observer {
37 public: 41 public:
38 ProfileInfoUpdateObserver(AvatarBaseController* avatarButton) 42 ProfileInfoUpdateObserver(Profile* profile,
39 : avatarButton_(avatarButton) { 43 AvatarBaseController* avatarButton)
44 : profile_(profile),
45 avatarButton_(avatarButton) {
40 g_browser_process->profile_manager()-> 46 g_browser_process->profile_manager()->
41 GetProfileInfoCache().AddObserver(this); 47 GetProfileInfoCache().AddObserver(this);
48
49 // Subscribe to authentication error changes so that the avatar button
50 // can update itself.
51 SigninErrorController* error = profiles::GetSigninErrorController(profile_);
52 if (error)
msw 2014/06/03 04:15:31 nit: Can this generally ever be NIL? (remove if st
noms (inactive) 2014/06/06 20:33:43 Yes. The SigninErrorController can be null for Gue
53 error->AddObserver(this);
42 } 54 }
43 55
44 virtual ~ProfileInfoUpdateObserver() { 56 virtual ~ProfileInfoUpdateObserver() {
45 g_browser_process->profile_manager()-> 57 g_browser_process->profile_manager()->
46 GetProfileInfoCache().RemoveObserver(this); 58 GetProfileInfoCache().RemoveObserver(this);
59 SigninErrorController* error = profiles::GetSigninErrorController(profile_);
60 if(error)
msw 2014/06/03 04:15:31 nit: space after if
noms (inactive) 2014/06/06 20:33:43 Done.
61 error->RemoveObserver(this);
47 } 62 }
48 63
49 // ProfileInfoCacheObserver: 64 // ProfileInfoCacheObserver:
50 virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE { 65 virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE {
51 [avatarButton_ updateAvatarButtonAndLayoutParent:YES]; 66 [avatarButton_ updateAvatarButtonAndLayoutParent:YES];
52 } 67 }
53 68
54 virtual void OnProfileWasRemoved( 69 virtual void OnProfileWasRemoved(
55 const base::FilePath& profile_path, 70 const base::FilePath& profile_path,
56 const base::string16& profile_name) OVERRIDE { 71 const base::string16& profile_name) OVERRIDE {
57 [avatarButton_ updateAvatarButtonAndLayoutParent:YES]; 72 [avatarButton_ updateAvatarButtonAndLayoutParent:YES];
58 } 73 }
59 74
60 virtual void OnProfileNameChanged( 75 virtual void OnProfileNameChanged(
61 const base::FilePath& profile_path, 76 const base::FilePath& profile_path,
62 const base::string16& old_profile_name) OVERRIDE { 77 const base::string16& old_profile_name) OVERRIDE {
63 [avatarButton_ updateAvatarButtonAndLayoutParent:YES]; 78 [avatarButton_ updateAvatarButtonAndLayoutParent:YES];
64 } 79 }
65 80
66 virtual void OnProfileAvatarChanged( 81 virtual void OnProfileAvatarChanged(
67 const base::FilePath& profile_path) OVERRIDE { 82 const base::FilePath& profile_path) OVERRIDE {
68 [avatarButton_ updateAvatarButtonAndLayoutParent:YES]; 83 [avatarButton_ updateAvatarButtonAndLayoutParent:YES];
69 } 84 }
70 85
86 // SigninErrorController::Observer:
87 virtual void OnErrorChanged() OVERRIDE {
88 SigninErrorController* error = profiles::GetSigninErrorController(profile_);
89 if (error)
90 [avatarButton_ updateErrorStatus:error->HasError()];
msw 2014/06/03 04:15:31 When won't error exist? Should the button be updat
noms (inactive) 2014/06/06 20:33:43 |error| can be null for guest or incognito profile
91 }
92
71 private: 93 private:
94 Profile* profile_;
72 AvatarBaseController* avatarButton_; // Weak; owns this. 95 AvatarBaseController* avatarButton_; // Weak; owns this.
73 96
74 DISALLOW_COPY_AND_ASSIGN(ProfileInfoUpdateObserver); 97 DISALLOW_COPY_AND_ASSIGN(ProfileInfoUpdateObserver);
75 }; 98 };
76 99
77 @implementation AvatarBaseController 100 @implementation AvatarBaseController
78 101
79 - (id)initWithBrowser:(Browser*)browser { 102 - (id)initWithBrowser:(Browser*)browser {
80 if ((self = [super init])) { 103 if ((self = [super init])) {
81 browser_ = browser; 104 browser_ = browser;
82 profileInfoObserver_.reset(new ProfileInfoUpdateObserver(self)); 105 profileInfoObserver_.reset(
106 new ProfileInfoUpdateObserver(browser_->profile(), self));
83 } 107 }
84 return self; 108 return self;
85 } 109 }
86 110
87 - (void)dealloc { 111 - (void)dealloc {
88 [[NSNotificationCenter defaultCenter] 112 [[NSNotificationCenter defaultCenter]
89 removeObserver:self 113 removeObserver:self
90 name:NSWindowWillCloseNotification 114 name:NSWindowWillCloseNotification
91 object:[menuController_ window]]; 115 object:[menuController_ window]];
92 [super dealloc]; 116 [super dealloc];
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 [static_cast<BrowserWindowController*>(wc) 183 [static_cast<BrowserWindowController*>(wc)
160 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO]; 184 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO];
161 } 185 }
162 menuController_ = nil; 186 menuController_ = nil;
163 } 187 }
164 188
165 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent { 189 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent {
166 NOTREACHED(); 190 NOTREACHED();
167 } 191 }
168 192
193 - (void)updateErrorStatus:(BOOL)hasError {
194 }
195
169 - (BaseBubbleController*)menuController { 196 - (BaseBubbleController*)menuController {
170 return menuController_; 197 return menuController_;
171 } 198 }
172 199
173 @end 200 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698