| 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 #ifndef CHROME_BROWSER_UI_COCOA_PROFILES_AVATAR_BASE_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_PROFILES_AVATAR_BASE_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_COCOA_PROFILES_AVATAR_BASE_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_COCOA_PROFILES_AVATAR_BASE_CONTROLLER_H_ |
| 7 | 7 |
| 8 #import <AppKit/AppKit.h> | 8 #import <AppKit/AppKit.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #import "base/mac/scoped_nsobject.h" | 12 #import "base/mac/scoped_nsobject.h" |
| 13 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 14 #include "chrome/browser/ui/avatar_button_error_controller.h" |
| 15 #include "chrome/browser/ui/avatar_button_error_controller_delegate.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 14 #import "chrome/browser/ui/cocoa/has_weak_browser_pointer.h" | 17 #import "chrome/browser/ui/cocoa/has_weak_browser_pointer.h" |
| 15 #include "components/signin/core/browser/signin_header_helper.h" | 18 #include "components/signin/core/browser/signin_header_helper.h" |
| 16 | 19 |
| 17 @class BaseBubbleController; | 20 @class BaseBubbleController; |
| 18 class Browser; | 21 class Browser; |
| 19 class ProfileAttributesUpdateObserver; | 22 class ProfileUpdateObserver; |
| 20 | 23 |
| 21 // This view controller manages the button that sits in the top of the | 24 // This view controller manages the button that sits in the top of the |
| 22 // window frame when using multi-profiles, and shows information about the | 25 // window frame when using multi-profiles, and shows information about the |
| 23 // current profile. Clicking the button will open the profile menu. | 26 // current profile. Clicking the button will open the profile menu. |
| 24 @interface AvatarBaseController : NSViewController<HasWeakBrowserPointer> { | 27 @interface AvatarBaseController : NSViewController<HasWeakBrowserPointer> { |
| 25 @protected | 28 @protected |
| 26 Browser* browser_; | 29 Browser* browser_; |
| 27 | 30 |
| 28 // The avatar button. Child classes are responsible for implementing it. | 31 // The avatar button. Child classes are responsible for implementing it. |
| 29 base::scoped_nsobject<NSButton> button_; | 32 base::scoped_nsobject<NSButton> button_; |
| 30 | 33 |
| 34 // Observer that listens for updates to the ProfileAttributesStorage as well |
| 35 // as AvatarButtonErrorController. |
| 36 std::unique_ptr<ProfileUpdateObserver> profileObserver_; |
| 37 |
| 31 @private | 38 @private |
| 32 // The menu controller, if the menu is open. | 39 // The menu controller, if the menu is open. |
| 33 BaseBubbleController* menuController_; | 40 BaseBubbleController* menuController_; |
| 34 | |
| 35 // Observer that listens for updates to the ProfileAttributesStorage. | |
| 36 std::unique_ptr<ProfileAttributesUpdateObserver> profileAttributesObserver_; | |
| 37 } | 41 } |
| 38 | 42 |
| 39 // The avatar button view. | 43 // The avatar button view. |
| 40 @property(readonly, nonatomic) NSButton* buttonView; | 44 @property(readonly, nonatomic) NSButton* buttonView; |
| 41 | 45 |
| 42 // Designated initializer. | 46 // Designated initializer. |
| 43 - (id)initWithBrowser:(Browser*)browser; | 47 - (id)initWithBrowser:(Browser*)browser; |
| 44 | 48 |
| 45 // Shows the avatar bubble in the given mode. | 49 // Shows the avatar bubble in the given mode. |
| 46 - (void)showAvatarBubbleAnchoredAt:(NSView*)anchor | 50 - (void)showAvatarBubbleAnchoredAt:(NSView*)anchor |
| 47 withMode:(BrowserWindow::AvatarBubbleMode)mode | 51 withMode:(BrowserWindow::AvatarBubbleMode)mode |
| 48 withServiceType:(signin::GAIAServiceType)serviceType | 52 withServiceType:(signin::GAIAServiceType)serviceType |
| 49 fromAccessPoint:(signin_metrics::AccessPoint)accessPoint; | 53 fromAccessPoint:(signin_metrics::AccessPoint)accessPoint; |
| 50 | 54 |
| 51 @end | 55 @end |
| 52 | 56 |
| 53 @interface AvatarBaseController (ExposedForTesting) | 57 @interface AvatarBaseController (ExposedForTesting) |
| 54 - (BaseBubbleController*)menuController; | 58 - (BaseBubbleController*)menuController; |
| 55 | 59 |
| 56 - (BOOL)isCtrlPressed; | 60 - (BOOL)isCtrlPressed; |
| 57 @end | 61 @end |
| 58 | 62 |
| 63 class ProfileUpdateObserver : public ProfileAttributesStorage::Observer, |
| 64 public AvatarButtonErrorControllerDelegate { |
| 65 public: |
| 66 ProfileUpdateObserver(Profile* profile, |
| 67 AvatarBaseController* avatarController); |
| 68 ~ProfileUpdateObserver() override; |
| 69 |
| 70 // ProfileAttributesStorage::Observer: |
| 71 void OnProfileAdded(const base::FilePath& profile_path) override; |
| 72 void OnProfileWasRemoved(const base::FilePath& profile_path, |
| 73 const base::string16& profile_name) override; |
| 74 void OnProfileNameChanged(const base::FilePath& profile_path, |
| 75 const base::string16& old_profile_name) override; |
| 76 void OnProfileSupervisedUserIdChanged( |
| 77 const base::FilePath& profile_path) override; |
| 78 |
| 79 // AvatarButtonErrorControllerDelegate: |
| 80 void OnAvatarErrorChanged() override; |
| 81 |
| 82 bool HasAvatarError(); |
| 83 |
| 84 private: |
| 85 AvatarButtonErrorController errorController_; |
| 86 Profile* profile_; |
| 87 AvatarBaseController* avatarController_; // Weak; owns this. |
| 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(ProfileUpdateObserver); |
| 90 }; |
| 91 |
| 59 #endif // CHROME_BROWSER_UI_COCOA_PROFILES_AVATAR_BASE_CONTROLLER_H_ | 92 #endif // CHROME_BROWSER_UI_COCOA_PROFILES_AVATAR_BASE_CONTROLLER_H_ |
| OLD | NEW |