Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / profiles / avatar_menu.h
blobb6bb0478a91bc30b8fc441154d6cfd7520bae71d
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 sync state of the profile.
60 base::string16 sync_state;
62 // Whether or not the current profile is signed in. If true, |sync_state| is
63 // expected to be the email of the signed in user.
64 bool signed_in;
66 // Whether or not the current profile requires sign-in before use.
67 bool signin_required;
69 // Whether or not the current profile is a legacy supervised user profile
70 // (see SupervisedUserService).
71 bool legacy_supervised;
73 // Whether or not the profile is associated with a child account
74 // (see SupervisedUserService).
75 bool child_account;
77 // The index in the menu of this profile, used by views to refer to
78 // profiles.
79 size_t menu_index;
81 // The index in the |profile_cache| for this profile.
82 size_t profile_index;
84 // The path of this profile.
85 base::FilePath profile_path;
88 // Constructor. |observer| can be NULL. |browser| can be NULL and a new one
89 // will be created if an action requires it.
90 AvatarMenu(ProfileInfoInterface* profile_cache,
91 AvatarMenuObserver* observer,
92 Browser* browser);
93 ~AvatarMenu() override;
95 // True if avatar menu should be displayed.
96 static bool ShouldShowAvatarMenu();
98 // Sets |image| to the avatar corresponding to the profile at |profile_path|
99 // and sets |is_rectangle| to true unless |image| is a built-in profile
100 // avatar. For built-in profile avatars, returns the non-high res version.
101 static void GetImageForMenuButton(const base::FilePath& profile_path,
102 gfx::Image* image,
103 bool* is_rectangle);
105 // Compare items by name.
106 static bool CompareItems(const Item* item1, const Item* item2);
108 // Opens a Browser with the specified profile in response to the user
109 // selecting an item. If |always_create| is true then a new window is created
110 // even if a window for that profile already exists.
111 void SwitchToProfile(size_t index,
112 bool always_create,
113 ProfileMetrics::ProfileOpen metric);
115 // Creates a new profile.
116 void AddNewProfile(ProfileMetrics::ProfileAdd type);
118 // Opens the profile settings in response to clicking the edit button next to
119 // an item.
120 void EditProfile(size_t index);
122 // Rebuilds the menu from the cache.
123 void RebuildMenu();
125 // Gets the number of profiles.
126 size_t GetNumberOfItems() const;
128 // Gets the Item at the specified index.
129 const Item& GetItemAt(size_t index) const;
131 // Returns the index of the active profile.
132 size_t GetActiveProfileIndex();
134 // Returns information about a supervised user which will be displayed in the
135 // avatar menu. If the profile does not belong to a supervised user, an empty
136 // string will be returned.
137 base::string16 GetSupervisedUserInformation() const;
139 // Returns the icon for the supervised user which will be displayed in the
140 // avatar menu.
141 const gfx::Image& GetSupervisedUserIcon() const;
143 // This menu is also used for the always-present Mac system menubar. If the
144 // last active browser changes, the menu will need to reference that browser.
145 void ActiveBrowserChanged(Browser* browser);
147 // Returns true if the add profile link should be shown.
148 bool ShouldShowAddNewProfileLink() const;
150 // Returns true if the edit profile link should be shown.
151 bool ShouldShowEditProfileLink() const;
153 private:
154 // ProfileInfoCacheObserver:
155 void OnProfileAdded(const base::FilePath& profile_path) override;
156 void OnProfileWasRemoved(const base::FilePath& profile_path,
157 const base::string16& profile_name) override;
158 void OnProfileNameChanged(const base::FilePath& profile_path,
159 const base::string16& old_profile_name) override;
160 void OnProfileUserNameChanged(const base::FilePath& profile_path) override;
161 void OnProfileAvatarChanged(const base::FilePath& profile_path) override;
162 void OnProfileHighResAvatarLoaded(
163 const base::FilePath& profile_path) override;
164 void OnProfileSigninRequiredChanged(
165 const base::FilePath& profile_path) override;
167 #if defined(ENABLE_SUPERVISED_USERS)
168 // SupervisedUserServiceObserver:
169 void OnCustodianInfoChanged() override;
170 #endif
172 // Rebuilds the menu and notifies any observers that an update occured.
173 void Update();
175 // The model that provides the list of menu items.
176 scoped_ptr<ProfileList> profile_list_;
178 // The controller for avatar menu actions.
179 scoped_ptr<AvatarMenuActions> menu_actions_;
181 #if defined(ENABLE_SUPERVISED_USERS)
182 // Observes changes to a supervised user's custodian info.
183 ScopedObserver<SupervisedUserService, SupervisedUserServiceObserver>
184 supervised_user_observer_;
185 #endif
187 // The cache that provides the profile information. Weak.
188 ProfileInfoInterface* profile_info_;
190 // The observer of this model, which is notified of changes. Weak.
191 AvatarMenuObserver* observer_;
193 // Browser in which this avatar menu resides. Weak.
194 Browser* browser_;
196 DISALLOW_COPY_AND_ASSIGN(AvatarMenu);
199 #endif // CHROME_BROWSER_PROFILES_AVATAR_MENU_H_