Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / profiles / avatar_menu.h
blob974965ac0a7413cc41af25098dc0d219279c52b1
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 // Returns the icon for the supervised user which will be displayed in the
141 // avatar menu.
142 const gfx::Image& GetSupervisedUserIcon() const;
144 // This menu is also used for the always-present Mac system menubar. If the
145 // last active browser changes, the menu will need to reference that browser.
146 void ActiveBrowserChanged(Browser* browser);
148 // Returns true if the add profile link should be shown.
149 bool ShouldShowAddNewProfileLink() const;
151 // Returns true if the edit profile link should be shown.
152 bool ShouldShowEditProfileLink() const;
154 private:
155 // ProfileInfoCacheObserver:
156 void OnProfileAdded(const base::FilePath& profile_path) override;
157 void OnProfileWasRemoved(const base::FilePath& profile_path,
158 const base::string16& profile_name) override;
159 void OnProfileNameChanged(const base::FilePath& profile_path,
160 const base::string16& old_profile_name) override;
161 void OnProfileAuthInfoChanged(const base::FilePath& profile_path) override;
162 void OnProfileAvatarChanged(const base::FilePath& profile_path) override;
163 void OnProfileHighResAvatarLoaded(
164 const base::FilePath& profile_path) override;
165 void OnProfileSigninRequiredChanged(
166 const base::FilePath& profile_path) override;
167 void OnProfileIsOmittedChanged(const base::FilePath& profile_path) override;
169 #if defined(ENABLE_SUPERVISED_USERS)
170 // SupervisedUserServiceObserver:
171 void OnCustodianInfoChanged() override;
172 #endif
174 // Rebuilds the menu and notifies any observers that an update occured.
175 void Update();
177 // The model that provides the list of menu items.
178 scoped_ptr<ProfileList> profile_list_;
180 // The controller for avatar menu actions.
181 scoped_ptr<AvatarMenuActions> menu_actions_;
183 #if defined(ENABLE_SUPERVISED_USERS)
184 // Observes changes to a supervised user's custodian info.
185 ScopedObserver<SupervisedUserService, SupervisedUserServiceObserver>
186 supervised_user_observer_;
187 #endif
189 // The cache that provides the profile information. Weak.
190 ProfileInfoInterface* profile_info_;
192 // The observer of this model, which is notified of changes. Weak.
193 AvatarMenuObserver* observer_;
195 // Browser in which this avatar menu resides. Weak.
196 Browser* browser_;
198 DISALLOW_COPY_AND_ASSIGN(AvatarMenu);
201 #endif // CHROME_BROWSER_PROFILES_AVATAR_MENU_H_