Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_PROFILES_AVATAR_MENU_H_ | 5 #ifndef CHROME_BROWSER_PROFILES_AVATAR_MENU_H_ |
| 6 #define CHROME_BROWSER_PROFILES_AVATAR_MENU_H_ | 6 #define CHROME_BROWSER_PROFILES_AVATAR_MENU_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/scoped_observer.h" | 13 #include "base/scoped_observer.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 15 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
| 16 #include "chrome/browser/profiles/profile_metrics.h" | 16 #include "chrome/browser/profiles/profile_metrics.h" |
| 17 #include "chrome/browser/ui/host_desktop.h" | 17 #include "chrome/browser/ui/host_desktop.h" |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/browser/web_contents_observer.h" | 19 #include "content/public/browser/web_contents_observer.h" |
| 20 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
| 21 | 21 |
| 22 #if defined(ENABLE_SUPERVISED_USERS) | 22 #if defined(ENABLE_SUPERVISED_USERS) |
| 23 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" | 23 #include "chrome/browser/supervised_user/supervised_user_service_observer.h" |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 class AvatarMenuActions; | 26 class AvatarMenuActions; |
| 27 class AvatarMenuObserver; | 27 class AvatarMenuObserver; |
| 28 class Browser; | 28 class Browser; |
| 29 class Profile; | 29 class Profile; |
| 30 class ProfileInfoInterface; | 30 class ProfileAttributesStorage; |
| 31 class ProfileList; | 31 class ProfileList; |
| 32 class SupervisedUserService; | 32 class SupervisedUserService; |
| 33 | 33 |
| 34 // This class represents the menu-like interface used to select profiles, | 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 | 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 | 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 | 37 // data changes, and the view for this model should forward actions |
| 38 // back to it in response to user events. | 38 // back to it in response to user events. |
| 39 class AvatarMenu : | 39 class AvatarMenu : |
| 40 #if defined(ENABLE_SUPERVISED_USERS) | 40 #if defined(ENABLE_SUPERVISED_USERS) |
| 41 public SupervisedUserServiceObserver, | 41 public SupervisedUserServiceObserver, |
| 42 #endif | 42 #endif |
| 43 public ProfileInfoCacheObserver { | 43 public ProfileInfoCacheObserver { |
| 44 public: | 44 public: |
| 45 // Represents an item in the menu. | 45 // Represents an item in the menu. |
| 46 struct Item { | 46 struct Item { |
| 47 Item(size_t menu_index, size_t profile_index, const gfx::Image& icon); | 47 Item(size_t menu_index, const gfx::Image& icon); |
| 48 ~Item(); | 48 ~Item(); |
| 49 | 49 |
| 50 // The icon to be displayed next to the item. | 50 // The icon to be displayed next to the item. |
| 51 gfx::Image icon; | 51 gfx::Image icon; |
| 52 | 52 |
| 53 // Whether or not the current browser is using this profile. | 53 // Whether or not the current browser is using this profile. |
| 54 bool active; | 54 bool active; |
| 55 | 55 |
| 56 // The name of this profile. | 56 // The name of this profile. |
| 57 base::string16 name; | 57 base::string16 name; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 72 bool legacy_supervised; | 72 bool legacy_supervised; |
| 73 | 73 |
| 74 // Whether or not the profile is associated with a child account | 74 // Whether or not the profile is associated with a child account |
| 75 // (see SupervisedUserService). | 75 // (see SupervisedUserService). |
| 76 bool child_account; | 76 bool child_account; |
| 77 | 77 |
| 78 // The index in the menu of this profile, used by views to refer to | 78 // The index in the menu of this profile, used by views to refer to |
| 79 // profiles. | 79 // profiles. |
| 80 size_t menu_index; | 80 size_t menu_index; |
| 81 | 81 |
| 82 // The index in the |profile_cache| for this profile. | |
| 83 size_t profile_index; | |
| 84 | |
| 85 // The path of this profile. | 82 // The path of this profile. |
| 86 base::FilePath profile_path; | 83 base::FilePath profile_path; |
| 87 }; | 84 }; |
| 88 | 85 |
| 89 // Constructor. |observer| can be NULL. |browser| can be NULL and a new one | 86 // Constructor. |observer| can be NULL. |browser| can be NULL and a new one |
| 90 // will be created if an action requires it. | 87 // will be created if an action requires it. |
| 91 AvatarMenu(ProfileInfoInterface* profile_cache, | 88 AvatarMenu(ProfileAttributesStorage* profile_storage, |
| 92 AvatarMenuObserver* observer, | 89 AvatarMenuObserver* observer, |
| 93 Browser* browser); | 90 Browser* browser); |
| 94 ~AvatarMenu() override; | 91 ~AvatarMenu() override; |
| 95 | 92 |
| 96 // True if avatar menu should be displayed. | 93 // True if avatar menu should be displayed. |
| 97 static bool ShouldShowAvatarMenu(); | 94 static bool ShouldShowAvatarMenu(); |
| 98 | 95 |
| 99 // Sets |image| to the avatar corresponding to the profile at |profile_path| | 96 // 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 | 97 // 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. | 98 // avatar. For built-in profile avatars, returns the non-high res version. |
| 102 static void GetImageForMenuButton(const base::FilePath& profile_path, | 99 static void GetImageForMenuButton(const base::FilePath& profile_path, |
| 103 gfx::Image* image, | 100 gfx::Image* image, |
| 104 bool* is_rectangle); | 101 bool* is_rectangle); |
| 105 | 102 |
| 106 // Compare items by name. | 103 // Compare items by name. |
| 107 static bool CompareItems(const Item* item1, const Item* item2); | 104 static bool CompareItems(const Item* item1, const Item* item2); |
| 108 | 105 |
| 109 // Opens a Browser with the specified profile in response to the user | 106 // 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 | 107 // selecting an item. If |always_create| is true then a new window is created |
| 111 // even if a window for that profile already exists. | 108 // even if a window for that profile already exists. |
| 112 void SwitchToProfile(size_t index, | 109 void SwitchToProfile(size_t index, |
|
Mike Lerman
2015/08/06 16:06:19
this used to be the index of the profile in the Pr
| |
| 113 bool always_create, | 110 bool always_create, |
| 114 ProfileMetrics::ProfileOpen metric); | 111 ProfileMetrics::ProfileOpen metric); |
| 115 | 112 |
| 116 // Creates a new profile. | 113 // Creates a new profile. |
| 117 void AddNewProfile(ProfileMetrics::ProfileAdd type); | 114 void AddNewProfile(ProfileMetrics::ProfileAdd type); |
| 118 | 115 |
| 119 // Opens the profile settings in response to clicking the edit button next to | 116 // Opens the profile settings in response to clicking the edit button next to |
| 120 // an item. | 117 // an item. |
| 121 void EditProfile(size_t index); | 118 void EditProfile(size_t index); |
| 122 | 119 |
| 123 // Rebuilds the menu from the cache. | 120 // Rebuilds the menu from the cache. |
| 124 void RebuildMenu(); | 121 void RebuildMenu(); |
| 125 | 122 |
| 126 // Gets the number of profiles. | 123 // Gets the number of profiles. |
| 127 size_t GetNumberOfItems() const; | 124 size_t GetNumberOfItems() const; |
| 128 | 125 |
| 129 // Gets the Item at the specified index. | 126 // Gets the Item at the specified index. |
| 130 const Item& GetItemAt(size_t index) const; | 127 const Item& GetItemAt(size_t index) const; |
| 131 | 128 |
| 129 // Gets the index in this menu for which profile_path is equal to |path|. | |
| 130 size_t GetIndexOfItemWithProfilePath(const base::FilePath& path); | |
| 131 | |
| 132 // Returns the index of the active profile. | 132 // Returns the index of the active profile. |
| 133 size_t GetActiveProfileIndex(); | 133 size_t GetActiveProfileIndex(); |
| 134 | 134 |
| 135 // Returns information about a supervised user which will be displayed in the | 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 | 136 // avatar menu. If the profile does not belong to a supervised user, an empty |
| 137 // string will be returned. | 137 // string will be returned. |
| 138 base::string16 GetSupervisedUserInformation() const; | 138 base::string16 GetSupervisedUserInformation() const; |
| 139 | 139 |
| 140 // Returns the icon for the supervised user which will be displayed in the | 140 // Returns the icon for the supervised user which will be displayed in the |
| 141 // avatar menu. | 141 // avatar menu. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 | 179 |
| 180 // The controller for avatar menu actions. | 180 // The controller for avatar menu actions. |
| 181 scoped_ptr<AvatarMenuActions> menu_actions_; | 181 scoped_ptr<AvatarMenuActions> menu_actions_; |
| 182 | 182 |
| 183 #if defined(ENABLE_SUPERVISED_USERS) | 183 #if defined(ENABLE_SUPERVISED_USERS) |
| 184 // Observes changes to a supervised user's custodian info. | 184 // Observes changes to a supervised user's custodian info. |
| 185 ScopedObserver<SupervisedUserService, SupervisedUserServiceObserver> | 185 ScopedObserver<SupervisedUserService, SupervisedUserServiceObserver> |
| 186 supervised_user_observer_; | 186 supervised_user_observer_; |
| 187 #endif | 187 #endif |
| 188 | 188 |
| 189 // The cache that provides the profile information. Weak. | |
| 190 ProfileInfoInterface* profile_info_; | |
| 191 | 189 |
| 192 // The observer of this model, which is notified of changes. Weak. | 190 // The observer of this model, which is notified of changes. Weak. |
| 193 AvatarMenuObserver* observer_; | 191 AvatarMenuObserver* observer_; |
| 194 | 192 |
| 195 // Browser in which this avatar menu resides. Weak. | 193 // Browser in which this avatar menu resides. Weak. |
| 196 Browser* browser_; | 194 Browser* browser_; |
| 197 | 195 |
| 198 DISALLOW_COPY_AND_ASSIGN(AvatarMenu); | 196 DISALLOW_COPY_AND_ASSIGN(AvatarMenu); |
| 199 }; | 197 }; |
| 200 | 198 |
| 201 #endif // CHROME_BROWSER_PROFILES_AVATAR_MENU_H_ | 199 #endif // CHROME_BROWSER_PROFILES_AVATAR_MENU_H_ |
| OLD | NEW |