| 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_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "chrome/browser/profiles/profile_attributes_storage.h" | 9 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 10 #include "chrome/browser/ui/avatar_button_error_controller.h" |
| 11 #include "chrome/browser/ui/avatar_button_error_controller_delegate.h" |
| 10 #include "chrome/browser/ui/views/profiles/avatar_button_style.h" | 12 #include "chrome/browser/ui/views/profiles/avatar_button_style.h" |
| 11 #include "components/signin/core/browser/signin_error_controller.h" | |
| 12 #include "components/sync_driver/sync_error_controller.h" | |
| 13 #include "ui/views/controls/button/label_button.h" | 13 #include "ui/views/controls/button/label_button.h" |
| 14 | 14 |
| 15 class AvatarButtonDelegate; | 15 class AvatarButtonDelegate; |
| 16 class Profile; | 16 class Profile; |
| 17 | 17 |
| 18 // Avatar button that displays the active profile's name in the caption area. | 18 // Avatar button that displays the active profile's name in the caption area. |
| 19 class NewAvatarButton : public views::LabelButton, | 19 class NewAvatarButton : public views::LabelButton, |
| 20 public AvatarButtonErrorControllerDelegate, |
| 20 public ProfileAttributesStorage::Observer { | 21 public ProfileAttributesStorage::Observer { |
| 21 public: | 22 public: |
| 22 class SigninErrorObserver : public SigninErrorController::Observer { | |
| 23 public: | |
| 24 SigninErrorObserver(NewAvatarButton* parent_button, Profile* profile); | |
| 25 ~SigninErrorObserver() override; | |
| 26 | |
| 27 private: | |
| 28 // SigninErrorController::Observer: | |
| 29 void OnErrorChanged() override; | |
| 30 | |
| 31 NewAvatarButton* parent_button_; | |
| 32 Profile* profile_; | |
| 33 | |
| 34 DISALLOW_COPY_AND_ASSIGN(SigninErrorObserver); | |
| 35 }; | |
| 36 | |
| 37 class SyncErrorObserver : public SyncErrorController::Observer { | |
| 38 public: | |
| 39 SyncErrorObserver(NewAvatarButton* parent_button, Profile* profile); | |
| 40 ~SyncErrorObserver() override; | |
| 41 | |
| 42 private: | |
| 43 // SyncErrorController::Observer: | |
| 44 void OnErrorChanged() override; | |
| 45 | |
| 46 NewAvatarButton* parent_button_; | |
| 47 Profile* profile_; | |
| 48 | |
| 49 DISALLOW_COPY_AND_ASSIGN(SyncErrorObserver); | |
| 50 }; | |
| 51 | |
| 52 NewAvatarButton(AvatarButtonDelegate* delegate, | 23 NewAvatarButton(AvatarButtonDelegate* delegate, |
| 53 AvatarButtonStyle button_style, | 24 AvatarButtonStyle button_style, |
| 54 Profile* profile); | 25 Profile* profile); |
| 55 ~NewAvatarButton() override; | 26 ~NewAvatarButton() override; |
| 56 | 27 |
| 57 // Views::LabelButton | 28 // Views::LabelButton |
| 58 bool OnMousePressed(const ui::MouseEvent& event) override; | 29 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 59 void OnMouseReleased(const ui::MouseEvent& event) override; | 30 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 60 | 31 |
| 61 // Views | 32 // Views |
| 62 void OnGestureEvent(ui::GestureEvent* event) override; | 33 void OnGestureEvent(ui::GestureEvent* event) override; |
| 63 | 34 |
| 64 void OnErrorChanged(); | |
| 65 | |
| 66 private: | 35 private: |
| 67 friend class ProfileChooserViewExtensionsTest; | 36 friend class ProfileChooserViewExtensionsTest; |
| 68 | 37 |
| 38 // AvatarButtonErrorControllerDelegate: |
| 39 void OnAvatarErrorChanged() override; |
| 40 |
| 69 // ProfileAttributesStorage::Observer: | 41 // ProfileAttributesStorage::Observer: |
| 70 void OnProfileAdded(const base::FilePath& profile_path) override; | 42 void OnProfileAdded(const base::FilePath& profile_path) override; |
| 71 void OnProfileWasRemoved(const base::FilePath& profile_path, | 43 void OnProfileWasRemoved(const base::FilePath& profile_path, |
| 72 const base::string16& profile_name) override; | 44 const base::string16& profile_name) override; |
| 73 void OnProfileNameChanged(const base::FilePath& profile_path, | 45 void OnProfileNameChanged(const base::FilePath& profile_path, |
| 74 const base::string16& old_profile_name) override; | 46 const base::string16& old_profile_name) override; |
| 75 void OnProfileSupervisedUserIdChanged( | 47 void OnProfileSupervisedUserIdChanged( |
| 76 const base::FilePath& profile_path) override; | 48 const base::FilePath& profile_path) override; |
| 77 | 49 |
| 78 // Called when the profile info cache has changed, which means we might | 50 // Called when the profile info cache or signin/sync error has changed, which |
| 79 // have to update the icon/text of the button. | 51 // means we might have to update the icon/text of the button. |
| 80 void Update(); | 52 void Update(); |
| 81 | 53 |
| 82 SigninErrorObserver signin_error_observer_; | |
| 83 SyncErrorObserver sync_error_observer_; | |
| 84 | |
| 85 AvatarButtonDelegate* delegate_; | 54 AvatarButtonDelegate* delegate_; |
| 55 AvatarButtonErrorController error_controller_; |
| 86 Profile* profile_; | 56 Profile* profile_; |
| 87 | 57 |
| 88 // Whether the signed in profile has any authentication error or sync error. | |
| 89 // Used to display an error icon next to the button text. | |
| 90 bool has_error_; | |
| 91 | |
| 92 // The icon displayed instead of the profile name in the local profile case. | 58 // The icon displayed instead of the profile name in the local profile case. |
| 93 // Different assets are used depending on the OS version. | 59 // Different assets are used depending on the OS version. |
| 94 gfx::ImageSkia generic_avatar_; | 60 gfx::ImageSkia generic_avatar_; |
| 95 | 61 |
| 96 // This is used to check if the bubble was showing during the mouse pressed | 62 // This is used to check if the bubble was showing during the mouse pressed |
| 97 // event. If this is true then the mouse released event is ignored to prevent | 63 // event. If this is true then the mouse released event is ignored to prevent |
| 98 // the bubble from reshowing. | 64 // the bubble from reshowing. |
| 99 bool suppress_mouse_released_action_; | 65 bool suppress_mouse_released_action_; |
| 100 | 66 |
| 101 DISALLOW_COPY_AND_ASSIGN(NewAvatarButton); | 67 DISALLOW_COPY_AND_ASSIGN(NewAvatarButton); |
| 102 }; | 68 }; |
| 103 | 69 |
| 104 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_ | 70 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_ |
| OLD | NEW |