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

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: Made nested classes private 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/signin/avatar_signin_error_controller.h"
11 #include "chrome/browser/sync/avatar_sync_error_controller.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 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(); 34 // Called when the profile info cache or signin/sync error has changed, which
35 // means we might have to update the icon/text of the button.
36 void Update();
65 37
66 private: 38 private:
67 friend class ProfileChooserViewExtensionsTest; 39 friend class ProfileChooserViewExtensionsTest;
68 40
41 class AvatarSigninErrorObserver : public AvatarSigninErrorController {
42 public:
43 AvatarSigninErrorObserver(Profile* profile, NewAvatarButton* parent_button);
44 // AvatarSigninErrorController:
45 void OnErrorChanged() override;
46
47 private:
48 NewAvatarButton* parent_button_;
49
50 DISALLOW_COPY_AND_ASSIGN(AvatarSigninErrorObserver);
51 };
52
53 class AvatarSyncErrorObserver : public AvatarSyncErrorController {
54 public:
55 AvatarSyncErrorObserver(Profile* profile, NewAvatarButton* parent_button);
56 // AvatarSyncErrorController:
57 void OnErrorChanged() override;
58
59 private:
60 NewAvatarButton* parent_button_;
61
62 DISALLOW_COPY_AND_ASSIGN(AvatarSyncErrorObserver);
63 };
64
69 // ProfileAttributesStorage::Observer: 65 // ProfileAttributesStorage::Observer:
70 void OnProfileAdded(const base::FilePath& profile_path) override; 66 void OnProfileAdded(const base::FilePath& profile_path) override;
71 void OnProfileWasRemoved(const base::FilePath& profile_path, 67 void OnProfileWasRemoved(const base::FilePath& profile_path,
72 const base::string16& profile_name) override; 68 const base::string16& profile_name) override;
73 void OnProfileNameChanged(const base::FilePath& profile_path, 69 void OnProfileNameChanged(const base::FilePath& profile_path,
74 const base::string16& old_profile_name) override; 70 const base::string16& old_profile_name) override;
75 void OnProfileSupervisedUserIdChanged( 71 void OnProfileSupervisedUserIdChanged(
76 const base::FilePath& profile_path) override; 72 const base::FilePath& profile_path) override;
77 73
78 // Called when the profile info cache has changed, which means we might 74 AvatarSigninErrorObserver signin_error_observer_;
79 // have to update the icon/text of the button. 75 AvatarSyncErrorObserver sync_error_observer_;
80 void Update();
81
82 SigninErrorObserver signin_error_observer_;
83 SyncErrorObserver sync_error_observer_;
84 76
85 AvatarButtonDelegate* delegate_; 77 AvatarButtonDelegate* delegate_;
86 Profile* profile_; 78 Profile* profile_;
87 79
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. 80 // The icon displayed instead of the profile name in the local profile case.
93 // Different assets are used depending on the OS version. 81 // Different assets are used depending on the OS version.
94 gfx::ImageSkia generic_avatar_; 82 gfx::ImageSkia generic_avatar_;
95 83
96 // This is used to check if the bubble was showing during the mouse pressed 84 // 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 85 // event. If this is true then the mouse released event is ignored to prevent
98 // the bubble from reshowing. 86 // the bubble from reshowing.
99 bool suppress_mouse_released_action_; 87 bool suppress_mouse_released_action_;
100 88
101 DISALLOW_COPY_AND_ASSIGN(NewAvatarButton); 89 DISALLOW_COPY_AND_ASSIGN(NewAvatarButton);
102 }; 90 };
103 91
104 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_ 92 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698