[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / profiles / profile_chooser_view.h
blobb68f3b231bc9015de10960d5ea5a63854bbf5465
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_
8 #include <map>
9 #include <vector>
11 #include "chrome/browser/profiles/avatar_menu.h"
12 #include "chrome/browser/profiles/avatar_menu_observer.h"
13 #include "chrome/browser/ui/browser_window.h"
14 #include "google_apis/gaia/oauth2_token_service.h"
15 #include "ui/views/bubble/bubble_delegate.h"
16 #include "ui/views/controls/button/button.h"
17 #include "ui/views/controls/link_listener.h"
18 #include "ui/views/controls/styled_label_listener.h"
19 #include "ui/views/controls/textfield/textfield_controller.h"
21 class EditableProfilePhoto;
22 class EditableProfileName;
24 namespace gfx {
25 class Image;
28 namespace views {
29 class GridLayout;
30 class ImageButton;
31 class Link;
32 class LabelButton;
35 class Browser;
37 // This bubble view is displayed when the user clicks on the avatar button.
38 // It displays a list of profiles and allows users to switch between profiles.
39 class ProfileChooserView : public views::BubbleDelegateView,
40 public views::ButtonListener,
41 public views::LinkListener,
42 public views::StyledLabelListener,
43 public views::TextfieldController,
44 public AvatarMenuObserver,
45 public OAuth2TokenService::Observer {
46 public:
47 // Different views that can be displayed in the bubble.
48 enum BubbleViewMode {
49 // Shows a "fast profile switcher" view.
50 BUBBLE_VIEW_MODE_PROFILE_CHOOSER,
51 // Shows a list of accounts for the active user.
52 BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT,
53 // Shows a web view for primary sign in.
54 BUBBLE_VIEW_MODE_GAIA_SIGNIN,
55 // Shows a web view for adding secondary accounts.
56 BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT,
57 // Shows a view for confirming account removal.
58 BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL,
59 // Shows a view for ending new profile management preview.
60 BUBBLE_VIEW_MODE_END_PREVIEW
63 enum TutorialMode {
64 TUTORIAL_MODE_NONE, // No tutorial card shown.
65 TUTORIAL_MODE_ENABLE_PREVIEW, // The enable-mirror-preview tutorial shown.
66 TUTORIAL_MODE_PREVIEW_ENABLED, // The welcome-to-mirror tutorial shown.
67 TUTORIAL_MODE_SEND_FEEDBACK // The send-feedback tutorial shown.
70 // Shows the bubble if one is not already showing. This allows us to easily
71 // make a button toggle the bubble on and off when clicked: we unconditionally
72 // call this function when the button is clicked and if the bubble isn't
73 // showing it will appear while if it is showing, nothing will happen here and
74 // the existing bubble will auto-close due to focus loss.
75 static void ShowBubble(BubbleViewMode view_mode,
76 views::View* anchor_view,
77 views::BubbleBorder::Arrow arrow,
78 views::BubbleBorder::BubbleAlignment border_alignment,
79 const gfx::Rect& anchor_rect,
80 Browser* browser);
81 static bool IsShowing();
82 static void Hide();
84 // We normally close the bubble any time it becomes inactive but this can lead
85 // to flaky tests where unexpected UI events are triggering this behavior.
86 // Tests should call this with "false" for more consistent operation.
87 static void clear_close_on_deactivate_for_testing() {
88 close_on_deactivate_for_testing_ = false;
91 private:
92 friend class NewAvatarMenuButtonTest;
93 FRIEND_TEST_ALL_PREFIXES(NewAvatarMenuButtonTest, SignOut);
95 typedef std::vector<size_t> Indexes;
96 typedef std::map<views::Button*, int> ButtonIndexes;
97 typedef std::map<views::Button*, std::string> AccountButtonIndexes;
99 ProfileChooserView(views::View* anchor_view,
100 views::BubbleBorder::Arrow arrow,
101 const gfx::Rect& anchor_rect,
102 Browser* browser,
103 BubbleViewMode view_mode);
104 virtual ~ProfileChooserView();
106 // views::BubbleDelegateView:
107 virtual void Init() OVERRIDE;
108 virtual void WindowClosing() OVERRIDE;
110 // views::ButtonListener:
111 virtual void ButtonPressed(views::Button* sender,
112 const ui::Event& event) OVERRIDE;
114 // views::LinkListener:
115 virtual void LinkClicked(views::Link* sender, int event_flags) OVERRIDE;
117 // views::StyledLabelListener implementation.
118 virtual void StyledLabelLinkClicked(
119 const gfx::Range& range, int event_flags) OVERRIDE;
121 // views::TextfieldController:
122 virtual bool HandleKeyEvent(views::Textfield* sender,
123 const ui::KeyEvent& key_event) OVERRIDE;
125 // AvatarMenuObserver:
126 virtual void OnAvatarMenuChanged(AvatarMenu* avatar_menu) OVERRIDE;
128 // OAuth2TokenService::Observer overrides.
129 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE;
130 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE;
132 static ProfileChooserView* profile_bubble_;
133 static bool close_on_deactivate_for_testing_;
135 void ResetView();
137 // Shows the bubble with the |view_to_display|.
138 void ShowView(BubbleViewMode view_to_display,
139 AvatarMenu* avatar_menu);
141 // Creates the profile chooser view. |tutorial_shown| indicates if the "mirror
142 // enabled" tutorial was shown or not in the last active view.
143 views::View* CreateProfileChooserView(AvatarMenu* avatar_menu,
144 TutorialMode last_tutorial_mode);
146 // Creates the main profile card for the profile |avatar_item|. |is_guest|
147 // is used to determine whether to show any Sign in/Sign out/Manage accounts
148 // links.
149 views::View* CreateCurrentProfileView(
150 const AvatarMenu::Item& avatar_item,
151 bool is_guest);
152 views::View* CreateGuestProfileView();
153 views::View* CreateOtherProfilesView(const Indexes& avatars_to_show);
154 views::View* CreateOptionsView(bool enable_lock);
156 // Account Management view for the profile |avatar_item|.
157 views::View* CreateCurrentProfileAccountsView(
158 const AvatarMenu::Item& avatar_item);
159 void CreateAccountButton(views::GridLayout* layout,
160 const std::string& account,
161 bool is_primary_account,
162 int width);
164 // Creates a webview showing the gaia signin page.
165 views::View* CreateGaiaSigninView(bool add_secondary_account);
167 // Creates a view to confirm account removal for |account_id_to_remove_|.
168 views::View* CreateAccountRemovalView();
170 // Removes the currently selected account and attempts to restart Chrome.
171 void RemoveAccount();
173 // Creates a a tutorial card at the top prompting the user to try out the new
174 // profile management UI.
175 views::View* CreateNewProfileManagementPreviewView();
177 // Creates a tutorial card shown when new profile management preview is
178 // enabled. |current_avatar_item| indicates the current profile.
179 // |tutorial_shown| indicates if the tutorial card is already shown in the
180 // last active view.
181 views::View* CreatePreviewEnabledTutorialView(
182 const AvatarMenu::Item& current_avatar_item, bool tutorial_shown);
184 // Creates a a tutorial card at the top prompting the user to send feedback
185 // about the new profile management preview and/or to end preview.
186 views::View* CreateSendPreviewFeedbackView();
188 // Creates a tutorial card with the specified |title_text|, |context_text|,
189 // and a bottom row with a right-aligned link using the specified |link_text|,
190 // and a left aligned button using the specified |button_text|. The method
191 // sets |link| to point to the newly created link, |button| to the newly
192 // created button, and |tutorial_mode_| to the given |tutorial_mode|.
193 views::View* CreateTutorialView(
194 TutorialMode tutorial_mode,
195 const base::string16& title_text,
196 const base::string16& content_text,
197 const base::string16& link_text,
198 const base::string16& button_text,
199 views::Link** link,
200 views::LabelButton** button);
202 views::View* CreateEndPreviewView();
204 scoped_ptr<AvatarMenu> avatar_menu_;
205 Browser* browser_;
207 // Other profiles used in the "fast profile switcher" view.
208 ButtonIndexes open_other_profile_indexes_map_;
210 // Accounts associated with the current profile.
211 AccountButtonIndexes current_profile_accounts_map_;
213 // Links and buttons displayed in the tutorial card.
214 views::Link* tutorial_learn_more_link_;
215 views::LabelButton* tutorial_ok_button_;
216 views::LabelButton* tutorial_enable_new_profile_management_button_;
217 views::Link* tutorial_end_preview_link_;
218 views::LabelButton* tutorial_send_feedback_button_;
220 // Links and buttons displayed in the active profile card.
221 views::Link* manage_accounts_link_;
222 views::LabelButton* signin_current_profile_link_;
223 views::ImageButton* question_mark_button_;
225 // The profile name and photo in the active profile card. Owned by the
226 // views hierarchy.
227 EditableProfilePhoto* current_profile_photo_;
228 EditableProfileName* current_profile_name_;
230 // Action buttons.
231 views::LabelButton* users_button_;
232 views::LabelButton* lock_button_;
233 views::Link* add_account_link_;
235 // Buttons displayed in the gaia signin view.
236 views::ImageButton* gaia_signin_cancel_button_;
238 // Links and buttons displayed in the account removal view.
239 views::LabelButton* remove_account_button_;
240 views::ImageButton* account_removal_cancel_button_;
242 // Links and buttons displayed in the end-preview view.
243 views::LabelButton* end_preview_and_relaunch_button_;
244 views::ImageButton* end_preview_cancel_button_;
246 // Records the account id to remove.
247 std::string account_id_to_remove_;
249 // Active view mode.
250 BubbleViewMode view_mode_;
252 // The current tutorial mode.
253 TutorialMode tutorial_mode_;
255 DISALLOW_COPY_AND_ASSIGN(ProfileChooserView);
258 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_PROFILE_CHOOSER_VIEW_H_