OLD | NEW |
---|---|
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; |
30 - (void)bubbleWillClose:(NSNotification*)notif; | 32 - (void)bubbleWillClose:(NSNotification*)notif; |
31 // Updates the profile name displayed by the avatar button. If |layoutParent| is | 33 // Updates the profile name displayed by the avatar button. If |layoutParent| is |
32 // yes, then the BrowserWindowController is notified to relayout the subviews, | 34 // yes, then the BrowserWindowController is notified to relayout the subviews, |
33 // as the button needs to be repositioned. | 35 // as the button needs to be repositioned. |
34 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; | 36 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; |
groby-ooo-7-16
2014/06/17 17:13:27
nit: Please add a space between declaration and th
noms (inactive)
2014/06/17 18:12:44
Done.
| |
37 // Displays an error icon if any accounts associated with this profile have an | |
38 // auth error. | |
39 - (void)updateErrorStatus:(BOOL)hasError; | |
35 @end | 40 @end |
36 | 41 |
37 class ProfileInfoUpdateObserver : public ProfileInfoCacheObserver { | 42 class ProfileInfoUpdateObserver : public ProfileInfoCacheObserver, |
43 public SigninErrorController::Observer { | |
38 public: | 44 public: |
39 ProfileInfoUpdateObserver(AvatarBaseController* avatarButton) | 45 ProfileInfoUpdateObserver(Profile* profile, |
40 : avatarButton_(avatarButton) { | 46 AvatarBaseController* avatarButton) |
groby-ooo-7-16
2014/06/17 17:13:27
nit: avatarController
noms (inactive)
2014/06/17 18:12:44
Done.
| |
47 : profile_(profile), | |
48 avatarButton_(avatarButton) { | |
41 g_browser_process->profile_manager()-> | 49 g_browser_process->profile_manager()-> |
42 GetProfileInfoCache().AddObserver(this); | 50 GetProfileInfoCache().AddObserver(this); |
51 | |
52 // Subscribe to authentication error changes so that the avatar button | |
53 // can update itself. | |
54 SigninErrorController* error = profiles::GetSigninErrorController(profile_); | |
groby-ooo-7-16
2014/06/17 17:13:26
nit:errorController
noms (inactive)
2014/06/17 18:12:44
Done.
| |
55 if (error) | |
56 error->AddObserver(this); | |
43 } | 57 } |
44 | 58 |
45 virtual ~ProfileInfoUpdateObserver() { | 59 virtual ~ProfileInfoUpdateObserver() { |
46 g_browser_process->profile_manager()-> | 60 g_browser_process->profile_manager()-> |
47 GetProfileInfoCache().RemoveObserver(this); | 61 GetProfileInfoCache().RemoveObserver(this); |
62 SigninErrorController* error = profiles::GetSigninErrorController(profile_); | |
63 if (error) | |
64 error->RemoveObserver(this); | |
48 } | 65 } |
49 | 66 |
50 // ProfileInfoCacheObserver: | 67 // ProfileInfoCacheObserver: |
51 virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE { | 68 virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE { |
52 [avatarButton_ updateAvatarButtonAndLayoutParent:YES]; | 69 [avatarButton_ updateAvatarButtonAndLayoutParent:YES]; |
53 } | 70 } |
54 | 71 |
55 virtual void OnProfileWasRemoved( | 72 virtual void OnProfileWasRemoved( |
56 const base::FilePath& profile_path, | 73 const base::FilePath& profile_path, |
57 const base::string16& profile_name) OVERRIDE { | 74 const base::string16& profile_name) OVERRIDE { |
58 [avatarButton_ updateAvatarButtonAndLayoutParent:YES]; | 75 [avatarButton_ updateAvatarButtonAndLayoutParent:YES]; |
59 } | 76 } |
60 | 77 |
61 virtual void OnProfileNameChanged( | 78 virtual void OnProfileNameChanged( |
62 const base::FilePath& profile_path, | 79 const base::FilePath& profile_path, |
63 const base::string16& old_profile_name) OVERRIDE { | 80 const base::string16& old_profile_name) OVERRIDE { |
64 [avatarButton_ updateAvatarButtonAndLayoutParent:YES]; | 81 [avatarButton_ updateAvatarButtonAndLayoutParent:YES]; |
65 } | 82 } |
66 | 83 |
67 virtual void OnProfileAvatarChanged( | 84 virtual void OnProfileAvatarChanged( |
68 const base::FilePath& profile_path) OVERRIDE { | 85 const base::FilePath& profile_path) OVERRIDE { |
69 [avatarButton_ updateAvatarButtonAndLayoutParent:YES]; | 86 [avatarButton_ updateAvatarButtonAndLayoutParent:YES]; |
70 } | 87 } |
71 | 88 |
89 // SigninErrorController::Observer: | |
90 virtual void OnErrorChanged() OVERRIDE { | |
91 SigninErrorController* error = profiles::GetSigninErrorController(profile_); | |
92 if (error) | |
93 [avatarButton_ updateErrorStatus:error->HasError()]; | |
94 } | |
95 | |
72 private: | 96 private: |
97 Profile* profile_; | |
73 AvatarBaseController* avatarButton_; // Weak; owns this. | 98 AvatarBaseController* avatarButton_; // Weak; owns this. |
74 | 99 |
75 DISALLOW_COPY_AND_ASSIGN(ProfileInfoUpdateObserver); | 100 DISALLOW_COPY_AND_ASSIGN(ProfileInfoUpdateObserver); |
76 }; | 101 }; |
77 | 102 |
78 @implementation AvatarBaseController | 103 @implementation AvatarBaseController |
79 | 104 |
80 - (id)initWithBrowser:(Browser*)browser { | 105 - (id)initWithBrowser:(Browser*)browser { |
81 if ((self = [super init])) { | 106 if ((self = [super init])) { |
82 browser_ = browser; | 107 browser_ = browser; |
83 profileInfoObserver_.reset(new ProfileInfoUpdateObserver(self)); | 108 profileInfoObserver_.reset( |
109 new ProfileInfoUpdateObserver(browser_->profile(), self)); | |
84 } | 110 } |
85 return self; | 111 return self; |
86 } | 112 } |
87 | 113 |
88 - (void)dealloc { | 114 - (void)dealloc { |
89 [[NSNotificationCenter defaultCenter] | 115 [[NSNotificationCenter defaultCenter] |
90 removeObserver:self | 116 removeObserver:self |
91 name:NSWindowWillCloseNotification | 117 name:NSWindowWillCloseNotification |
92 object:[menuController_ window]]; | 118 object:[menuController_ window]]; |
93 [super dealloc]; | 119 [super dealloc]; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 [static_cast<BrowserWindowController*>(wc) | 189 [static_cast<BrowserWindowController*>(wc) |
164 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO]; | 190 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO]; |
165 } | 191 } |
166 menuController_ = nil; | 192 menuController_ = nil; |
167 } | 193 } |
168 | 194 |
169 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent { | 195 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent { |
170 NOTREACHED(); | 196 NOTREACHED(); |
171 } | 197 } |
172 | 198 |
199 - (void)updateErrorStatus:(BOOL)hasError { | |
200 } | |
201 | |
173 - (BaseBubbleController*)menuController { | 202 - (BaseBubbleController*)menuController { |
174 return menuController_; | 203 return menuController_; |
175 } | 204 } |
176 | 205 |
177 @end | 206 @end |
OLD | NEW |