OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_PROFILES_AVATAR_MENU_MODEL_H_ |
| 6 #define CHROME_BROWSER_PROFILES_AVATAR_MENU_MODEL_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" |
| 12 #include "base/string16.h" |
| 13 #include "content/common/notification_observer.h" |
| 14 #include "content/common/notification_registrar.h" |
| 15 |
| 16 class AvatarMenuModelObserver; |
| 17 class Browser; |
| 18 class ProfileInfoInterface; |
| 19 |
| 20 namespace gfx { |
| 21 class Image; |
| 22 } |
| 23 |
| 24 // This class is the model for the menu-like interface that appears when the |
| 25 // avatar icon is clicked in the browser window frame. This class will notify |
| 26 // its observer when the backend data changes, and the controller/view for this |
| 27 // model should forward actions back to it in response to user events. |
| 28 class AvatarMenuModel : public NotificationObserver { |
| 29 public: |
| 30 // Represents an item in the menu. |
| 31 struct Item { |
| 32 Item(size_t model_index, const gfx::Image& icon); |
| 33 ~Item(); |
| 34 |
| 35 // The icon to be displayed next to the item. |
| 36 const gfx::Image& icon; |
| 37 |
| 38 // Whether or not the current browser is using this profile. |
| 39 bool active; |
| 40 |
| 41 // The name of this profile. |
| 42 string16 name; |
| 43 |
| 44 // A string representing the sync state of the profile. |
| 45 string16 sync_state; |
| 46 |
| 47 // The index in the |profile_cache| that this Item represents. |
| 48 size_t model_index; |
| 49 }; |
| 50 |
| 51 // Constructor. No parameters can be NULL in practice. |browser| can be NULL |
| 52 // for unit tests, but no actions should be executed. |
| 53 AvatarMenuModel(ProfileInfoInterface* profile_cache, |
| 54 AvatarMenuModelObserver* observer, |
| 55 Browser* browser); |
| 56 virtual ~AvatarMenuModel(); |
| 57 |
| 58 // Actions performed by the view that the controller forwards back to the |
| 59 // model: |
| 60 // Opens a Browser with the specified profile in response to the user |
| 61 // selecting an item. |
| 62 void SwichToProfile(size_t index); |
| 63 // Opens the profile settings in response to clicking the edit button next to |
| 64 // an item. |
| 65 void EditProfile(size_t index); |
| 66 // Creates a new profile. |
| 67 void AddNewProfile(); |
| 68 |
| 69 // Gets the number of profiles. |
| 70 size_t GetNumberOfItems(); |
| 71 |
| 72 // Gets the an Item at a specified index. |
| 73 const Item& GetItemAt(size_t index); |
| 74 |
| 75 // NotificationObserver: |
| 76 virtual void Observe(int type, |
| 77 const NotificationSource& source, |
| 78 const NotificationDetails& details) OVERRIDE; |
| 79 |
| 80 private: |
| 81 // Rebuilds the menu from the cache and notifies the |observer_|. |
| 82 void RebuildMenu(); |
| 83 |
| 84 // Clears the list of items, deleting each. |
| 85 void ClearMenu(); |
| 86 |
| 87 // The cache that provides the profile information. Weak. |
| 88 ProfileInfoInterface* profile_info_; |
| 89 |
| 90 // The observer of this model, which is notified of changes. Weak. |
| 91 AvatarMenuModelObserver* observer_; |
| 92 |
| 93 // Browser in which this avatar menu resides. Weak. |
| 94 Browser* browser_; |
| 95 |
| 96 // List of built "menu items." |
| 97 std::vector<Item*> items_; |
| 98 |
| 99 // Listens for notifications from the ProfileInfoCache. |
| 100 NotificationRegistrar registrar_; |
| 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(AvatarMenuModel); |
| 103 }; |
| 104 |
| 105 #endif // CHROME_BROWSER_PROFILES_AVATAR_MENU_MODEL_H_ |
OLD | NEW |