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_metrics.h"
16 #include "chrome/browser/ui/host_desktop.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
19 #include "content/public/browser/web_contents.h"
20 #include "content/public/browser/web_contents_observer.h"
21 #include "ui/gfx/image/image.h"
23 #if defined(ENABLE_MANAGED_USERS)
24 #include "chrome/browser/supervised_user/supervised_user_service_observer.h"
27 class AvatarMenuActions;
28 class AvatarMenuObserver;
31 class ProfileInfoInterface;
33 class SupervisedUserService;
35 // This class represents the menu-like interface used to select profiles,
36 // such as the bubble that appears when the avatar icon is clicked in the
37 // browser window frame. This class will notify its observer when the backend
38 // data changes, and the view for this model should forward actions
39 // back to it in response to user events.
41 #if defined(ENABLE_MANAGED_USERS)
42 public SupervisedUserServiceObserver,
44 public content::NotificationObserver {
46 // Represents an item in the menu.
48 Item(size_t menu_index, size_t profile_index, const gfx::Image& icon);
51 // The icon to be displayed next to the item.
54 // Whether or not the current browser is using this profile.
57 // The name of this profile.
60 // A string representing the sync state of the profile.
61 base::string16 sync_state;
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 supervised user
71 // (see SupervisedUserService).
74 // The index in the menu of this profile, used by views to refer to
78 // The index in the |profile_cache| for this profile.
81 // The path of this profile.
82 base::FilePath profile_path;
85 // Constructor. |observer| can be NULL. |browser| can be NULL and a new one
86 // will be created if an action requires it.
87 AvatarMenu(ProfileInfoInterface* profile_cache,
88 AvatarMenuObserver* observer,
90 virtual ~AvatarMenu();
92 // True if avatar menu should be displayed.
93 static bool ShouldShowAvatarMenu();
95 // Sets |image| to the image corresponding to the given profile, and
96 // sets |is_rectangle| to true unless |image| is a built-in profile avatar.
97 static void GetImageForMenuButton(Profile* profile,
101 // Compare items by name.
102 static bool CompareItems(const Item* item1, const Item* item2);
104 // Opens a Browser with the specified profile in response to the user
105 // selecting an item. If |always_create| is true then a new window is created
106 // even if a window for that profile already exists.
107 void SwitchToProfile(size_t index,
109 ProfileMetrics::ProfileOpen metric);
111 // Creates a new profile.
112 void AddNewProfile(ProfileMetrics::ProfileAdd type);
114 // Opens the profile settings in response to clicking the edit button next to
116 void EditProfile(size_t index);
118 // Rebuilds the menu from the cache.
121 // Gets the number of profiles.
122 size_t GetNumberOfItems() const;
124 // Gets the Item at the specified index.
125 const Item& GetItemAt(size_t index) const;
127 // Returns the index of the active profile.
128 size_t GetActiveProfileIndex();
130 // Returns information about a supervised user which will be displayed in the
131 // avatar menu. If the profile does not belong to a supervised user, an empty
132 // string will be returned.
133 base::string16 GetSupervisedUserInformation() const;
135 // Returns the icon for the supervised user which will be displayed in the
137 const gfx::Image& GetSupervisedUserIcon() const;
139 // This menu is also used for the always-present Mac system menubar. If the
140 // last active browser changes, the menu will need to reference that browser.
141 void ActiveBrowserChanged(Browser* browser);
143 // Returns true if the add profile link should be shown.
144 bool ShouldShowAddNewProfileLink() const;
146 // Returns true if the edit profile link should be shown.
147 bool ShouldShowEditProfileLink() const;
149 // content::NotificationObserver:
150 virtual void Observe(int type,
151 const content::NotificationSource& source,
152 const content::NotificationDetails& details) OVERRIDE;
155 #if defined(ENABLE_MANAGED_USERS)
156 // SupervisedUserServiceObserver:
157 virtual void OnCustodianInfoChanged() OVERRIDE;
160 // The model that provides the list of menu items.
161 scoped_ptr<ProfileList> profile_list_;
163 // The controller for avatar menu actions.
164 scoped_ptr<AvatarMenuActions> menu_actions_;
166 #if defined(ENABLE_MANAGED_USERS)
167 // Observes changes to a supervised user's custodian info.
168 ScopedObserver<SupervisedUserService, SupervisedUserServiceObserver>
169 supervised_user_observer_;
172 // The cache that provides the profile information. Weak.
173 ProfileInfoInterface* profile_info_;
175 // The observer of this model, which is notified of changes. Weak.
176 AvatarMenuObserver* observer_;
178 // Browser in which this avatar menu resides. Weak.
181 // Listens for notifications from the ProfileInfoCache.
182 content::NotificationRegistrar registrar_;
184 DISALLOW_COPY_AND_ASSIGN(AvatarMenu);
187 #endif // CHROME_BROWSER_PROFILES_AVATAR_MENU_H_