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

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: Enum name change 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 { 22 class AvatarSigninErrorObserver : public AvatarSigninErrorController {
sky 2016/07/27 18:17:30 Does this and the next really need to be in the pu
Jane 2016/07/27 20:17:49 You're right, no need to be in the public section.
23 public: 23 public:
24 SigninErrorObserver(NewAvatarButton* parent_button, Profile* profile); 24 AvatarSigninErrorObserver(Profile* profile, NewAvatarButton* parent_button);
25 ~SigninErrorObserver() override; 25 void OnErrorChanged() override;
26 26
27 private: 27 private:
28 // SigninErrorController::Observer: 28 NewAvatarButton* parent_button_;
29
30 DISALLOW_COPY_AND_ASSIGN(AvatarSigninErrorObserver);
31 };
32
33 class AvatarSyncErrorObserver : public AvatarSyncErrorController {
34 public:
35 AvatarSyncErrorObserver(Profile* profile, NewAvatarButton* parent_button);
29 void OnErrorChanged() override; 36 void OnErrorChanged() override;
30 37
38 private:
31 NewAvatarButton* parent_button_; 39 NewAvatarButton* parent_button_;
32 Profile* profile_;
33 40
34 DISALLOW_COPY_AND_ASSIGN(SigninErrorObserver); 41 DISALLOW_COPY_AND_ASSIGN(AvatarSyncErrorObserver);
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 }; 42 };
51 43
52 NewAvatarButton(AvatarButtonDelegate* delegate, 44 NewAvatarButton(AvatarButtonDelegate* delegate,
53 AvatarButtonStyle button_style, 45 AvatarButtonStyle button_style,
54 Profile* profile); 46 Profile* profile);
55 ~NewAvatarButton() override; 47 ~NewAvatarButton() override;
56 48
57 // Views::LabelButton 49 // Views::LabelButton
58 bool OnMousePressed(const ui::MouseEvent& event) override; 50 bool OnMousePressed(const ui::MouseEvent& event) override;
59 void OnMouseReleased(const ui::MouseEvent& event) override; 51 void OnMouseReleased(const ui::MouseEvent& event) override;
60 52
61 // Views 53 // Views
62 void OnGestureEvent(ui::GestureEvent* event) override; 54 void OnGestureEvent(ui::GestureEvent* event) override;
63 55
64 void OnErrorChanged(); 56 // Called when the profile info cache or signin/sync error has changed, which
57 // means we might have to update the icon/text of the button.
58 void Update();
65 59
66 private: 60 private:
67 friend class ProfileChooserViewExtensionsTest; 61 friend class ProfileChooserViewExtensionsTest;
68 62
69 // ProfileAttributesStorage::Observer: 63 // ProfileAttributesStorage::Observer:
70 void OnProfileAdded(const base::FilePath& profile_path) override; 64 void OnProfileAdded(const base::FilePath& profile_path) override;
71 void OnProfileWasRemoved(const base::FilePath& profile_path, 65 void OnProfileWasRemoved(const base::FilePath& profile_path,
72 const base::string16& profile_name) override; 66 const base::string16& profile_name) override;
73 void OnProfileNameChanged(const base::FilePath& profile_path, 67 void OnProfileNameChanged(const base::FilePath& profile_path,
74 const base::string16& old_profile_name) override; 68 const base::string16& old_profile_name) override;
75 void OnProfileSupervisedUserIdChanged( 69 void OnProfileSupervisedUserIdChanged(
76 const base::FilePath& profile_path) override; 70 const base::FilePath& profile_path) override;
77 71
78 // Called when the profile info cache has changed, which means we might 72 AvatarSigninErrorObserver signin_error_observer_;
79 // have to update the icon/text of the button. 73 AvatarSyncErrorObserver sync_error_observer_;
80 void Update();
81
82 SigninErrorObserver signin_error_observer_;
83 SyncErrorObserver sync_error_observer_;
84 74
85 AvatarButtonDelegate* delegate_; 75 AvatarButtonDelegate* delegate_;
86 Profile* profile_; 76 Profile* profile_;
87 77
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. 78 // The icon displayed instead of the profile name in the local profile case.
93 // Different assets are used depending on the OS version. 79 // Different assets are used depending on the OS version.
94 gfx::ImageSkia generic_avatar_; 80 gfx::ImageSkia generic_avatar_;
95 81
96 // This is used to check if the bubble was showing during the mouse pressed 82 // 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 83 // event. If this is true then the mouse released event is ignored to prevent
98 // the bubble from reshowing. 84 // the bubble from reshowing.
99 bool suppress_mouse_released_action_; 85 bool suppress_mouse_released_action_;
100 86
101 DISALLOW_COPY_AND_ASSIGN(NewAvatarButton); 87 DISALLOW_COPY_AND_ASSIGN(NewAvatarButton);
102 }; 88 };
103 89
104 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_ 90 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698