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_
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"
26 class AvatarMenuActions
;
27 class AvatarMenuObserver
;
30 class ProfileInfoInterface
;
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.
40 #if defined(ENABLE_SUPERVISED_USERS)
41 public SupervisedUserServiceObserver
,
43 public ProfileInfoCacheObserver
{
45 // Represents an item in the menu.
47 Item(size_t menu_index
, size_t profile_index
, const gfx::Image
& icon
);
50 // The icon to be displayed next to the item.
53 // Whether or not the current browser is using this profile.
56 // The name of this profile.
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.
67 // Whether or not the current profile requires sign-in before use.
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).
78 // The index in the menu of this profile, used by views to refer to
82 // The index in the |profile_cache| for this profile.
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
,
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
,
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
,
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
121 void EditProfile(size_t index
);
123 // Rebuilds the menu from the cache.
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
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;
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
;
174 // Rebuilds the menu and notifies any observers that an update occured.
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_
;
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.
198 DISALLOW_COPY_AND_ASSIGN(AvatarMenu
);
201 #endif // CHROME_BROWSER_PROFILES_AVATAR_MENU_H_