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

Side by Side Diff: chrome/browser/ui/views/profiles/new_avatar_button.h

Issue 2179283002: Refactored signin/sync error controllers for the avatar button (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: New refactoring Created 4 years, 4 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
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 #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"
10 #include "chrome/browser/ui/views/profiles/avatar_button_style.h" 11 #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" 12 #include "ui/views/controls/button/label_button.h"
14 13
15 class AvatarButtonDelegate; 14 class AvatarButtonDelegate;
16 class Profile; 15 class Profile;
17 16
18 // Avatar button that displays the active profile's name in the caption area. 17 // Avatar button that displays the active profile's name in the caption area.
19 class NewAvatarButton : public views::LabelButton, 18 class NewAvatarButton : public views::LabelButton,
19 public AvatarButtonErrorController,
20 public ProfileAttributesStorage::Observer { 20 public ProfileAttributesStorage::Observer {
21 public: 21 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, 22 NewAvatarButton(AvatarButtonDelegate* delegate,
53 AvatarButtonStyle button_style, 23 AvatarButtonStyle button_style,
54 Profile* profile); 24 Profile* profile);
55 ~NewAvatarButton() override; 25 ~NewAvatarButton() override;
56 26
57 // Views::LabelButton 27 // Views::LabelButton
58 bool OnMousePressed(const ui::MouseEvent& event) override; 28 bool OnMousePressed(const ui::MouseEvent& event) override;
59 void OnMouseReleased(const ui::MouseEvent& event) override; 29 void OnMouseReleased(const ui::MouseEvent& event) override;
60 30
61 // Views 31 // Views
62 void OnGestureEvent(ui::GestureEvent* event) override; 32 void OnGestureEvent(ui::GestureEvent* event) override;
63 33
64 void OnErrorChanged();
65
66 private: 34 private:
67 friend class ProfileChooserViewExtensionsTest; 35 friend class ProfileChooserViewExtensionsTest;
68 36
37 // AvatarButtonErrorController:
38 void OnAvatarErrorChanged() override;
39
69 // ProfileAttributesStorage::Observer: 40 // ProfileAttributesStorage::Observer:
70 void OnProfileAdded(const base::FilePath& profile_path) override; 41 void OnProfileAdded(const base::FilePath& profile_path) override;
71 void OnProfileWasRemoved(const base::FilePath& profile_path, 42 void OnProfileWasRemoved(const base::FilePath& profile_path,
72 const base::string16& profile_name) override; 43 const base::string16& profile_name) override;
73 void OnProfileNameChanged(const base::FilePath& profile_path, 44 void OnProfileNameChanged(const base::FilePath& profile_path,
74 const base::string16& old_profile_name) override; 45 const base::string16& old_profile_name) override;
75 void OnProfileSupervisedUserIdChanged( 46 void OnProfileSupervisedUserIdChanged(
76 const base::FilePath& profile_path) override; 47 const base::FilePath& profile_path) override;
77 48
78 // Called when the profile info cache has changed, which means we might 49 // Called when the profile info cache or signin/sync error has changed, which
79 // have to update the icon/text of the button. 50 // means we might have to update the icon/text of the button.
80 void Update(); 51 void Update();
81 52
82 SigninErrorObserver signin_error_observer_;
83 SyncErrorObserver sync_error_observer_;
84
85 AvatarButtonDelegate* delegate_; 53 AvatarButtonDelegate* delegate_;
86 Profile* profile_; 54 Profile* profile_;
87 55
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. 56 // The icon displayed instead of the profile name in the local profile case.
93 // Different assets are used depending on the OS version. 57 // Different assets are used depending on the OS version.
94 gfx::ImageSkia generic_avatar_; 58 gfx::ImageSkia generic_avatar_;
95 59
96 // This is used to check if the bubble was showing during the mouse pressed 60 // 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 61 // event. If this is true then the mouse released event is ignored to prevent
98 // the bubble from reshowing. 62 // the bubble from reshowing.
99 bool suppress_mouse_released_action_; 63 bool suppress_mouse_released_action_;
100 64
101 DISALLOW_COPY_AND_ASSIGN(NewAvatarButton); 65 DISALLOW_COPY_AND_ASSIGN(NewAvatarButton);
102 }; 66 };
103 67
104 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_ 68 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698