1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_PROFILES_AVATAR_MENU_H_
#define CHROME_BROWSER_PROFILES_AVATAR_MENU_H_
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/scoped_observer.h"
#include "base/strings/string16.h"
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/ui/host_desktop.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/gfx/image/image.h"
#if defined(ENABLE_SUPERVISED_USERS)
#include "chrome/browser/supervised_user/supervised_user_service_observer.h"
#endif
class AvatarMenuActions;
class AvatarMenuObserver;
class Browser;
class Profile;
class ProfileInfoInterface;
class ProfileList;
class SupervisedUserService;
// This class represents the menu-like interface used to select profiles,
// such as the bubble that appears when the avatar icon is clicked in the
// browser window frame. This class will notify its observer when the backend
// data changes, and the view for this model should forward actions
// back to it in response to user events.
class AvatarMenu :
#if defined(ENABLE_SUPERVISED_USERS)
public SupervisedUserServiceObserver,
#endif
public content::NotificationObserver {
public:
// Represents an item in the menu.
struct Item {
Item(size_t menu_index, size_t profile_index, const gfx::Image& icon);
~Item();
// The icon to be displayed next to the item.
gfx::Image icon;
// Whether or not the current browser is using this profile.
bool active;
// The name of this profile.
base::string16 name;
// A string representing the sync state of the profile.
base::string16 sync_state;
// Whether or not the current profile is signed in. If true, |sync_state| is
// expected to be the email of the signed in user.
bool signed_in;
// Whether or not the current profile requires sign-in before use.
bool signin_required;
// Whether or not the current profile is a supervised user
// (see SupervisedUserService).
bool supervised;
// The index in the menu of this profile, used by views to refer to
// profiles.
size_t menu_index;
// The index in the |profile_cache| for this profile.
size_t profile_index;
// The path of this profile.
base::FilePath profile_path;
};
// Constructor. |observer| can be NULL. |browser| can be NULL and a new one
// will be created if an action requires it.
AvatarMenu(ProfileInfoInterface* profile_cache,
AvatarMenuObserver* observer,
Browser* browser);
~AvatarMenu() override;
// True if avatar menu should be displayed.
static bool ShouldShowAvatarMenu();
// Sets |image| to the avatar corresponding to the profile at |profile_path|
// and sets |is_rectangle| to true unless |image| is a built-in profile
// avatar. For built-in profile avatars, returns the non-high res version.
static void GetImageForMenuButton(const base::FilePath& profile_path,
gfx::Image* image,
bool* is_rectangle);
// Compare items by name.
static bool CompareItems(const Item* item1, const Item* item2);
// Opens a Browser with the specified profile in response to the user
// selecting an item. If |always_create| is true then a new window is created
// even if a window for that profile already exists.
void SwitchToProfile(size_t index,
bool always_create,
ProfileMetrics::ProfileOpen metric);
// Creates a new profile.
void AddNewProfile(ProfileMetrics::ProfileAdd type);
// Opens the profile settings in response to clicking the edit button next to
// an item.
void EditProfile(size_t index);
// Rebuilds the menu from the cache.
void RebuildMenu();
// Gets the number of profiles.
size_t GetNumberOfItems() const;
// Gets the Item at the specified index.
const Item& GetItemAt(size_t index) const;
// Returns the index of the active profile.
size_t GetActiveProfileIndex();
// Returns information about a supervised user which will be displayed in the
// avatar menu. If the profile does not belong to a supervised user, an empty
// string will be returned.
base::string16 GetSupervisedUserInformation() const;
// Returns the icon for the supervised user which will be displayed in the
// avatar menu.
const gfx::Image& GetSupervisedUserIcon() const;
// This menu is also used for the always-present Mac system menubar. If the
// last active browser changes, the menu will need to reference that browser.
void ActiveBrowserChanged(Browser* browser);
// Returns true if the add profile link should be shown.
bool ShouldShowAddNewProfileLink() const;
// Returns true if the edit profile link should be shown.
bool ShouldShowEditProfileLink() const;
// content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
private:
#if defined(ENABLE_SUPERVISED_USERS)
// SupervisedUserServiceObserver:
void OnCustodianInfoChanged() override;
#endif
// The model that provides the list of menu items.
scoped_ptr<ProfileList> profile_list_;
// The controller for avatar menu actions.
scoped_ptr<AvatarMenuActions> menu_actions_;
#if defined(ENABLE_SUPERVISED_USERS)
// Observes changes to a supervised user's custodian info.
ScopedObserver<SupervisedUserService, SupervisedUserServiceObserver>
supervised_user_observer_;
#endif
// The cache that provides the profile information. Weak.
ProfileInfoInterface* profile_info_;
// The observer of this model, which is notified of changes. Weak.
AvatarMenuObserver* observer_;
// Browser in which this avatar menu resides. Weak.
Browser* browser_;
// Listens for notifications from the ProfileInfoCache.
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(AvatarMenu);
};
#endif // CHROME_BROWSER_PROFILES_AVATAR_MENU_H_
|