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_MODEL_H_ | 5 #ifndef CHROME_BROWSER_PROFILES_AVATAR_MENU_MODEL_H_ |
6 #define CHROME_BROWSER_PROFILES_AVATAR_MENU_MODEL_H_ | 6 #define CHROME_BROWSER_PROFILES_AVATAR_MENU_MODEL_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "chrome/browser/profiles/profile_metrics.h" | 13 #include "chrome/browser/profiles/profile_metrics.h" |
14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
18 #include "ui/gfx/image/image.h" | 18 #include "ui/base/profile_selector/avatar_menu_item_model.h" |
19 | 19 |
20 class AvatarMenuModelObserver; | 20 class AvatarMenuModelObserver; |
21 class Browser; | 21 class Browser; |
22 class Profile; | 22 class Profile; |
23 class ProfileInfoInterface; | 23 class ProfileInfoInterface; |
24 | 24 |
| 25 namespace gfx { |
| 26 class Image; |
| 27 } |
| 28 |
25 // This class is the model for the menu-like interface that appears when the | 29 // This class is the model for the menu-like interface that appears when the |
26 // avatar icon is clicked in the browser window frame. This class will notify | 30 // avatar icon is clicked in the browser window frame. This class will notify |
27 // its observer when the backend data changes, and the controller/view for this | 31 // its observer when the backend data changes, and the controller/view for this |
28 // model should forward actions back to it in response to user events. | 32 // model should forward actions back to it in response to user events. |
29 class AvatarMenuModel : public content::NotificationObserver { | 33 class AvatarMenuModel : public content::NotificationObserver { |
30 public: | 34 public: |
31 // Represents an item in the menu. | |
32 struct Item { | |
33 Item(size_t model_index, const gfx::Image& icon); | |
34 ~Item(); | |
35 | |
36 // The icon to be displayed next to the item. | |
37 gfx::Image icon; | |
38 | |
39 // Whether or not the current browser is using this profile. | |
40 bool active; | |
41 | |
42 // The name of this profile. | |
43 string16 name; | |
44 | |
45 // A string representing the sync state of the profile. | |
46 string16 sync_state; | |
47 | |
48 // Whether or not the current profile is signed in. If true, |sync_state| is | |
49 // expected to be the email of the signed in user. | |
50 bool signed_in; | |
51 | |
52 // Whether or not the current profile requires sign-in before use. | |
53 bool signin_required; | |
54 | |
55 // The index in the |profile_cache| that this Item represents. | |
56 size_t model_index; | |
57 }; | |
58 | |
59 // Constructor. |observer| can be NULL. |browser| can be NULL and a new one | 35 // Constructor. |observer| can be NULL. |browser| can be NULL and a new one |
60 // will be created if an action requires it. | 36 // will be created if an action requires it. |
61 AvatarMenuModel(ProfileInfoInterface* profile_cache, | 37 AvatarMenuModel(ProfileInfoInterface* profile_cache, |
62 AvatarMenuModelObserver* observer, | 38 AvatarMenuModelObserver* observer, |
63 Browser* browser); | 39 Browser* browser); |
64 virtual ~AvatarMenuModel(); | 40 virtual ~AvatarMenuModel(); |
65 | 41 |
66 // Actions performed by the view that the controller forwards back to the | 42 // Actions performed by the view that the controller forwards back to the |
67 // model: | 43 // model: |
68 // Opens a Browser with the specified profile in response to the user | 44 // Opens a Browser with the specified profile in response to the user |
(...skipping 11 matching lines...) Expand all Loading... |
80 // Gets the path associated with the profile at |index|. | 56 // Gets the path associated with the profile at |index|. |
81 base::FilePath GetProfilePath(size_t index); | 57 base::FilePath GetProfilePath(size_t index); |
82 | 58 |
83 // Gets the number of profiles. | 59 // Gets the number of profiles. |
84 size_t GetNumberOfItems(); | 60 size_t GetNumberOfItems(); |
85 | 61 |
86 // Returns the index of the active profile. | 62 // Returns the index of the active profile. |
87 size_t GetActiveProfileIndex(); | 63 size_t GetActiveProfileIndex(); |
88 | 64 |
89 // Gets the an Item at a specified index. | 65 // Gets the an Item at a specified index. |
90 const Item& GetItemAt(size_t index); | 66 const ui::AvatarMenuItemModel& GetItemAt(size_t index); |
91 | 67 |
92 // Returns true if the add profile link should be shown. | 68 // Returns true if the add profile link should be shown. |
93 bool ShouldShowAddNewProfileLink() const; | 69 bool ShouldShowAddNewProfileLink() const; |
94 | 70 |
95 // Returns information about a managed user which will be displayed in the | 71 // Returns information about a managed user which will be displayed in the |
96 // avatar menu. If the profile does not belong to a managed user, an empty | 72 // avatar menu. If the profile does not belong to a managed user, an empty |
97 // string will be returned. | 73 // string will be returned. |
98 base::string16 GetManagedUserInformation() const; | 74 base::string16 GetManagedUserInformation() const; |
99 | 75 |
100 // Returns the icon for the managed user which will be displayed in the | 76 // Returns the icon for the managed user which will be displayed in the |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // The cache that provides the profile information. Weak. | 110 // The cache that provides the profile information. Weak. |
135 ProfileInfoInterface* profile_info_; | 111 ProfileInfoInterface* profile_info_; |
136 | 112 |
137 // The observer of this model, which is notified of changes. Weak. | 113 // The observer of this model, which is notified of changes. Weak. |
138 AvatarMenuModelObserver* observer_; | 114 AvatarMenuModelObserver* observer_; |
139 | 115 |
140 // Browser in which this avatar menu resides. Weak. | 116 // Browser in which this avatar menu resides. Weak. |
141 Browser* browser_; | 117 Browser* browser_; |
142 | 118 |
143 // List of built "menu items." | 119 // List of built "menu items." |
144 std::vector<Item*> items_; | 120 std::vector<ui::AvatarMenuItemModel*> items_; |
145 | 121 |
146 // Listens for notifications from the ProfileInfoCache. | 122 // Listens for notifications from the ProfileInfoCache. |
147 content::NotificationRegistrar registrar_; | 123 content::NotificationRegistrar registrar_; |
148 | 124 |
149 // Special "override" logout URL used to let tests work. | 125 // Special "override" logout URL used to let tests work. |
150 std::string logout_override_; | 126 std::string logout_override_; |
151 | 127 |
152 DISALLOW_COPY_AND_ASSIGN(AvatarMenuModel); | 128 DISALLOW_COPY_AND_ASSIGN(AvatarMenuModel); |
153 }; | 129 }; |
154 | 130 |
155 #endif // CHROME_BROWSER_PROFILES_AVATAR_MENU_MODEL_H_ | 131 #endif // CHROME_BROWSER_PROFILES_AVATAR_MENU_MODEL_H_ |
OLD | NEW |