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

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: rachel nits 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
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/signin/signin_header_helper.h" 13 #include "chrome/browser/signin/signin_header_helper.h"
14 #include "chrome/browser/profiles/profiles_state.h"
14 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_commands.h" 16 #include "chrome/browser/ui/browser_commands.h"
16 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
17 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" 18 #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
18 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 19 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
19 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h" 20 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h"
20 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" 21 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
22 #include "components/signin/core/browser/signin_error_controller.h"
21 #include "components/signin/core/common/profile_management_switches.h" 23 #include "components/signin/core/common/profile_management_switches.h"
22 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
23 25
24 // Space between the avatar icon and the avatar menu bubble. 26 // Space between the avatar icon and the avatar menu bubble.
25 const CGFloat kMenuYOffsetAdjust = 1.0; 27 const CGFloat kMenuYOffsetAdjust = 1.0;
26 28
27 @interface AvatarBaseController (Private) 29 @interface AvatarBaseController (Private)
28 // Shows the avatar bubble. 30 // Shows the avatar bubble.
29 - (IBAction)buttonClicked:(id)sender; 31 - (IBAction)buttonClicked:(id)sender;
32
30 - (void)bubbleWillClose:(NSNotification*)notif; 33 - (void)bubbleWillClose:(NSNotification*)notif;
34
31 // Updates the profile name displayed by the avatar button. If |layoutParent| is 35 // Updates the profile name displayed by the avatar button. If |layoutParent| is
32 // yes, then the BrowserWindowController is notified to relayout the subviews, 36 // yes, then the BrowserWindowController is notified to relayout the subviews,
33 // as the button needs to be repositioned. 37 // as the button needs to be repositioned.
34 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; 38 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent;
39
40 // Displays an error icon if any accounts associated with this profile have an
41 // auth error.
42 - (void)updateErrorStatus:(BOOL)hasError;
35 @end 43 @end
36 44
37 class ProfileInfoUpdateObserver : public ProfileInfoCacheObserver { 45 class ProfileInfoUpdateObserver : public ProfileInfoCacheObserver,
46 public SigninErrorController::Observer {
38 public: 47 public:
39 ProfileInfoUpdateObserver(AvatarBaseController* avatarButton) 48 ProfileInfoUpdateObserver(Profile* profile,
40 : avatarButton_(avatarButton) { 49 AvatarBaseController* avatarController)
50 : profile_(profile),
51 avatarController_(avatarController) {
41 g_browser_process->profile_manager()-> 52 g_browser_process->profile_manager()->
42 GetProfileInfoCache().AddObserver(this); 53 GetProfileInfoCache().AddObserver(this);
54
55 // Subscribe to authentication error changes so that the avatar button
56 // can update itself.
57 SigninErrorController* errorController =
58 profiles::GetSigninErrorController(profile_);
59 if (errorController)
60 errorController->AddObserver(this);
43 } 61 }
44 62
45 virtual ~ProfileInfoUpdateObserver() { 63 virtual ~ProfileInfoUpdateObserver() {
46 g_browser_process->profile_manager()-> 64 g_browser_process->profile_manager()->
47 GetProfileInfoCache().RemoveObserver(this); 65 GetProfileInfoCache().RemoveObserver(this);
66 SigninErrorController* errorController =
67 profiles::GetSigninErrorController(profile_);
68 if (errorController)
69 errorController->RemoveObserver(this);
48 } 70 }
49 71
50 // ProfileInfoCacheObserver: 72 // ProfileInfoCacheObserver:
51 virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE { 73 virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE {
52 [avatarButton_ updateAvatarButtonAndLayoutParent:YES]; 74 [avatarController_ updateAvatarButtonAndLayoutParent:YES];
53 } 75 }
54 76
55 virtual void OnProfileWasRemoved( 77 virtual void OnProfileWasRemoved(
56 const base::FilePath& profile_path, 78 const base::FilePath& profile_path,
57 const base::string16& profile_name) OVERRIDE { 79 const base::string16& profile_name) OVERRIDE {
58 [avatarButton_ updateAvatarButtonAndLayoutParent:YES]; 80 [avatarController_ updateAvatarButtonAndLayoutParent:YES];
59 } 81 }
60 82
61 virtual void OnProfileNameChanged( 83 virtual void OnProfileNameChanged(
62 const base::FilePath& profile_path, 84 const base::FilePath& profile_path,
63 const base::string16& old_profile_name) OVERRIDE { 85 const base::string16& old_profile_name) OVERRIDE {
64 [avatarButton_ updateAvatarButtonAndLayoutParent:YES]; 86 [avatarController_ updateAvatarButtonAndLayoutParent:YES];
65 } 87 }
66 88
67 virtual void OnProfileAvatarChanged( 89 virtual void OnProfileAvatarChanged(
68 const base::FilePath& profile_path) OVERRIDE { 90 const base::FilePath& profile_path) OVERRIDE {
69 [avatarButton_ updateAvatarButtonAndLayoutParent:YES]; 91 [avatarController_ updateAvatarButtonAndLayoutParent:YES];
92 }
93
94 // SigninErrorController::Observer:
95 virtual void OnErrorChanged() OVERRIDE {
96 SigninErrorController* errorController =
97 profiles::GetSigninErrorController(profile_);
98 if (errorController)
99 [avatarController_ updateErrorStatus:errorController->HasError()];
70 } 100 }
71 101
72 private: 102 private:
73 AvatarBaseController* avatarButton_; // Weak; owns this. 103 Profile* profile_;
104 AvatarBaseController* avatarController_; // Weak; owns this.
74 105
75 DISALLOW_COPY_AND_ASSIGN(ProfileInfoUpdateObserver); 106 DISALLOW_COPY_AND_ASSIGN(ProfileInfoUpdateObserver);
76 }; 107 };
77 108
78 @implementation AvatarBaseController 109 @implementation AvatarBaseController
79 110
80 - (id)initWithBrowser:(Browser*)browser { 111 - (id)initWithBrowser:(Browser*)browser {
81 if ((self = [super init])) { 112 if ((self = [super init])) {
82 browser_ = browser; 113 browser_ = browser;
83 profileInfoObserver_.reset(new ProfileInfoUpdateObserver(self)); 114 profileInfoObserver_.reset(
115 new ProfileInfoUpdateObserver(browser_->profile(), self));
84 } 116 }
85 return self; 117 return self;
86 } 118 }
87 119
88 - (void)dealloc { 120 - (void)dealloc {
89 [[NSNotificationCenter defaultCenter] 121 [[NSNotificationCenter defaultCenter]
90 removeObserver:self 122 removeObserver:self
91 name:NSWindowWillCloseNotification 123 name:NSWindowWillCloseNotification
92 object:[menuController_ window]]; 124 object:[menuController_ window]];
93 [super dealloc]; 125 [super dealloc];
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 [static_cast<BrowserWindowController*>(wc) 195 [static_cast<BrowserWindowController*>(wc)
164 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO]; 196 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO];
165 } 197 }
166 menuController_ = nil; 198 menuController_ = nil;
167 } 199 }
168 200
169 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent { 201 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent {
170 NOTREACHED(); 202 NOTREACHED();
171 } 203 }
172 204
205 - (void)updateErrorStatus:(BOOL)hasError {
206 }
207
173 - (BaseBubbleController*)menuController { 208 - (BaseBubbleController*)menuController {
174 return menuController_; 209 return menuController_;
175 } 210 }
176 211
177 @end 212 @end
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698