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/strings/string16.h"
14 #include "chrome/browser/profiles/profile_metrics.h"
15 #include "chrome/browser/ui/host_desktop.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.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 class AvatarMenuObserver
;
25 class ProfileInfoInterface
;
27 class AvatarMenuActions
;
29 // This class represents the menu-like interface used to select profiles,
30 // such as the bubble that appears when the avatar icon is clicked in the
31 // browser window frame. This class will notify its observer when the backend
32 // data changes, and the view for this model should forward actions
33 // back to it in response to user events.
34 class AvatarMenu
: public content::NotificationObserver
{
36 // Represents an item in the menu.
38 Item(size_t menu_index
, size_t profile_index
, const gfx::Image
& icon
);
41 // The icon to be displayed next to the item.
44 // Whether or not the current browser is using this profile.
47 // The name of this profile.
50 // A string representing the sync state of the profile.
51 base::string16 sync_state
;
53 // Whether or not the current profile is signed in. If true, |sync_state| is
54 // expected to be the email of the signed in user.
57 // Whether or not the current profile requires sign-in before use.
60 // Whether or not the current profile is a managed user
61 // (see ManagedUserService).
64 // The index in the menu of this profile, used by views to refer to
68 // The index in the |profile_cache| for this profile.
71 // The path of this profile.
72 base::FilePath profile_path
;
75 // Constructor. |observer| can be NULL. |browser| can be NULL and a new one
76 // will be created if an action requires it.
77 AvatarMenu(ProfileInfoInterface
* profile_cache
,
78 AvatarMenuObserver
* observer
,
80 virtual ~AvatarMenu();
82 // True if avatar menu should be displayed.
83 static bool ShouldShowAvatarMenu();
85 // Sets |image| to the image corresponding to the given profile, and
86 // sets |is_rectangle| to true unless |image| is a built-in profile avatar.
87 static void GetImageForMenuButton(Profile
* profile
,
91 // Compare items by name.
92 static bool CompareItems(const Item
* item1
, const Item
* item2
);
94 // Opens a Browser with the specified profile in response to the user
95 // selecting an item. If |always_create| is true then a new window is created
96 // even if a window for that profile already exists.
97 void SwitchToProfile(size_t index
,
99 ProfileMetrics::ProfileOpen metric
);
101 // Creates a new profile.
102 void AddNewProfile(ProfileMetrics::ProfileAdd type
);
104 // Opens the profile settings in response to clicking the edit button next to
106 void EditProfile(size_t index
);
108 // Rebuilds the menu from the cache.
111 // Gets the number of profiles.
112 size_t GetNumberOfItems() const;
114 // Gets the Item at the specified index.
115 const Item
& GetItemAt(size_t index
) const;
117 // Returns the index of the active profile.
118 size_t GetActiveProfileIndex();
120 // Returns information about a managed user which will be displayed in the
121 // avatar menu. If the profile does not belong to a managed user, an empty
122 // string will be returned.
123 base::string16
GetManagedUserInformation() const;
125 // Returns the icon for the managed user which will be displayed in the
127 const gfx::Image
& GetManagedUserIcon() const;
129 // This menu is also used for the always-present Mac system menubar. If the
130 // last active browser changes, the menu will need to reference that browser.
131 void ActiveBrowserChanged(Browser
* browser
);
133 // Returns true if the add profile link should be shown.
134 bool ShouldShowAddNewProfileLink() const;
136 // Returns true if the edit profile link should be shown.
137 bool ShouldShowEditProfileLink() const;
139 // content::NotificationObserver:
140 virtual void Observe(int type
,
141 const content::NotificationSource
& source
,
142 const content::NotificationDetails
& details
) OVERRIDE
;
145 // The model that provides the list of menu items.
146 scoped_ptr
<ProfileList
> profile_list_
;
148 // The controller for avatar menu actions.
149 scoped_ptr
<AvatarMenuActions
> menu_actions_
;
151 // The cache that provides the profile information. Weak.
152 ProfileInfoInterface
* profile_info_
;
154 // The observer of this model, which is notified of changes. Weak.
155 AvatarMenuObserver
* observer_
;
157 // Browser in which this avatar menu resides. Weak.
160 // Listens for notifications from the ProfileInfoCache.
161 content::NotificationRegistrar registrar_
;
163 DISALLOW_COPY_AND_ASSIGN(AvatarMenu
);
166 #endif // CHROME_BROWSER_PROFILES_AVATAR_MENU_H_