Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / chrome / browser / profiles / avatar_menu.h
blob94ed64ac0c1627d394ca8936374f9defb7b7b6f2
1 // Copyright (c) 2012 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_PROFILES_AVATAR_MENU_H_
6 #define CHROME_BROWSER_PROFILES_AVATAR_MENU_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/scoped_observer.h"
14 #include "base/strings/string16.h"
15 #include "chrome/browser/profiles/profile_info_cache_observer.h"
16 #include "chrome/browser/profiles/profile_metrics.h"
17 #include "chrome/browser/ui/host_desktop.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/browser/web_contents_observer.h"
20 #include "ui/gfx/image/image.h"
22 #if defined(ENABLE_SUPERVISED_USERS)
23 #include "chrome/browser/supervised_user/supervised_user_service_observer.h"
24 #endif
26 class AvatarMenuActions;
27 class AvatarMenuObserver;
28 class Browser;
29 class Profile;
30 class ProfileInfoInterface;
31 class ProfileList;
32 class SupervisedUserService;
34 // This class represents the menu-like interface used to select profiles,
35 // such as the bubble that appears when the avatar icon is clicked in the
36 // browser window frame. This class will notify its observer when the backend
37 // data changes, and the view for this model should forward actions
38 // back to it in response to user events.
39 class AvatarMenu :
40 #if defined(ENABLE_SUPERVISED_USERS)
41 public SupervisedUserServiceObserver,
42 #endif
43 public ProfileInfoCacheObserver {
44 public:
45 // Represents an item in the menu.
46 struct Item {
47 Item(size_t menu_index, size_t profile_index, const gfx::Image& icon);
48 ~Item();
50 // The icon to be displayed next to the item.
51 gfx::Image icon;
53 // Whether or not the current browser is using this profile.
54 bool active;
56 // The name of this profile.
57 base::string16 name;
59 // A string representing the username of the profile, if signed in. Empty
60 // when not signed in.
61 base::string16 username;
63 // Whether or not the current profile is signed in. If true, |sync_state| is
64 // expected to be the email of the signed in user.
65 bool signed_in;
67 // Whether or not the current profile requires sign-in before use.
68 bool signin_required;
70 // Whether or not the current profile is a legacy supervised user profile
71 // (see SupervisedUserService).
72 bool legacy_supervised;
74 // Whether or not the profile is associated with a child account
75 // (see SupervisedUserService).
76 bool child_account;
78 // The index in the menu of this profile, used by views to refer to
79 // profiles.
80 size_t menu_index;
82 // The index in the |profile_cache| for this profile.
83 size_t profile_index;
85 // The path of this profile.
86 base::FilePath profile_path;
89 // Constructor. |observer| can be NULL. |browser| can be NULL and a new one
90 // will be created if an action requires it.
91 AvatarMenu(ProfileInfoInterface* profile_cache,
92 AvatarMenuObserver* observer,
93 Browser* browser);
94 ~AvatarMenu() override;
96 // True if avatar menu should be displayed.
97 static bool ShouldShowAvatarMenu();
99 // Sets |image| to the avatar corresponding to the profile at |profile_path|
100 // and sets |is_rectangle| to true unless |image| is a built-in profile
101 // avatar. For built-in profile avatars, returns the non-high res version.
102 static void GetImageForMenuButton(const base::FilePath& profile_path,
103 gfx::Image* image,
104 bool* is_rectangle);
106 // Compare items by name.
107 static bool CompareItems(const Item* item1, const Item* item2);
109 // Opens a Browser with the specified profile in response to the user
110 // selecting an item. If |always_create| is true then a new window is created
111 // even if a window for that profile already exists.
112 void SwitchToProfile(size_t index,
113 bool always_create,
114 ProfileMetrics::ProfileOpen metric);
116 // Creates a new profile.
117 void AddNewProfile(ProfileMetrics::ProfileAdd type);
119 // Opens the profile settings in response to clicking the edit button next to
120 // an item.
121 void EditProfile(size_t index);
123 // Rebuilds the menu from the cache.
124 void RebuildMenu();
126 // Gets the number of profiles.
127 size_t GetNumberOfItems() const;
129 // Gets the Item at the specified index.
130 const Item& GetItemAt(size_t index) const;
132 // Returns the index of the active profile.
133 size_t GetActiveProfileIndex();
135 // Returns information about a supervised user which will be displayed in the
136 // avatar menu. If the profile does not belong to a supervised user, an empty
137 // string will be returned.
138 base::string16 GetSupervisedUserInformation() const;
140 // This menu is also used for the always-present Mac system menubar. If the
141 // last active browser changes, the menu will need to reference that browser.
142 void ActiveBrowserChanged(Browser* browser);
144 // Returns true if the add profile link should be shown.
145 bool ShouldShowAddNewProfileLink() const;
147 // Returns true if the edit profile link should be shown.
148 bool ShouldShowEditProfileLink() const;
150 private:
151 // ProfileInfoCacheObserver:
152 void OnProfileAdded(const base::FilePath& profile_path) override;
153 void OnProfileWasRemoved(const base::FilePath& profile_path,
154 const base::string16& profile_name) override;
155 void OnProfileNameChanged(const base::FilePath& profile_path,
156 const base::string16& old_profile_name) override;
157 void OnProfileAuthInfoChanged(const base::FilePath& profile_path) override;
158 void OnProfileAvatarChanged(const base::FilePath& profile_path) override;
159 void OnProfileHighResAvatarLoaded(
160 const base::FilePath& profile_path) override;
161 void OnProfileSigninRequiredChanged(
162 const base::FilePath& profile_path) override;
163 void OnProfileIsOmittedChanged(const base::FilePath& profile_path) override;
165 #if defined(ENABLE_SUPERVISED_USERS)
166 // SupervisedUserServiceObserver:
167 void OnCustodianInfoChanged() override;
168 #endif
170 // Rebuilds the menu and notifies any observers that an update occured.
171 void Update();
173 // The model that provides the list of menu items.
174 scoped_ptr<ProfileList> profile_list_;
176 // The controller for avatar menu actions.
177 scoped_ptr<AvatarMenuActions> menu_actions_;
179 #if defined(ENABLE_SUPERVISED_USERS)
180 // Observes changes to a supervised user's custodian info.
181 ScopedObserver<SupervisedUserService, SupervisedUserServiceObserver>
182 supervised_user_observer_;
183 #endif
185 // The cache that provides the profile information. Weak.
186 ProfileInfoInterface* profile_info_;
188 // The observer of this model, which is notified of changes. Weak.
189 AvatarMenuObserver* observer_;
191 // Browser in which this avatar menu resides. Weak.
192 Browser* browser_;
194 DISALLOW_COPY_AND_ASSIGN(AvatarMenu);
197 #endif // CHROME_BROWSER_PROFILES_AVATAR_MENU_H_