Fix experimental app list start page tiles not updating correctly.
[chromium-blink-merge.git] / ui / message_center / notifier_settings.h
blob8bed9c663e6636f154d0186c5e51cf33483bdf94
1 // Copyright (c) 2013 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 UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_
6 #define UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_
8 #include <string>
10 #include "base/gtest_prod_util.h"
11 #include "base/strings/string16.h"
12 #include "ui/gfx/image/image.h"
13 #include "ui/message_center/message_center_export.h"
14 #include "url/gurl.h"
16 class MessageCenterNotificationsTest;
17 class MessageCenterTrayBridgeTest;
19 namespace ash {
20 class WebNotificationTrayTest;
23 namespace message_center {
24 namespace test {
25 class MessagePopupCollectionTest;
28 class MessageCenterNotificationManagerTest;
29 class NotifierSettingsDelegate;
30 class NotifierSettingsProvider;
32 // Brings up the settings dialog and returns a weak reference to the delegate,
33 // which is typically the view. If the dialog already exists, it is brought to
34 // the front, otherwise it is created.
35 MESSAGE_CENTER_EXPORT NotifierSettingsDelegate* ShowSettings(
36 NotifierSettingsProvider* provider,
37 gfx::NativeView context);
39 // The struct to distinguish the notifiers.
40 struct MESSAGE_CENTER_EXPORT NotifierId {
41 enum NotifierType {
42 APPLICATION,
43 WEB_PAGE,
44 SYSTEM_COMPONENT,
47 // Constructor for non WEB_PAGE type.
48 NotifierId(NotifierType type, const std::string& id);
50 // Constructor for WEB_PAGE type.
51 explicit NotifierId(const GURL& url);
53 bool operator==(const NotifierId& other) const;
54 // Allows NotifierId to be used as a key in std::map.
55 bool operator<(const NotifierId& other) const;
57 NotifierType type;
59 // The identifier of the app notifier. Empty if it's WEB_PAGE.
60 std::string id;
62 // The URL pattern of the notifer.
63 GURL url;
65 // The identifier of the profile where the notification is created. This is
66 // used for ChromeOS multi-profile support and can be empty.
67 std::string profile_id;
69 private:
70 friend class MessageCenterNotificationManagerTest;
71 friend class MessageCenterTrayTest;
72 friend class NotificationControllerTest;
73 friend class PopupCollectionTest;
74 friend class TrayViewControllerTest;
75 friend class ::MessageCenterNotificationsTest;
76 friend class ::MessageCenterTrayBridgeTest;
77 friend class ash::WebNotificationTrayTest;
78 friend class test::MessagePopupCollectionTest;
79 FRIEND_TEST_ALL_PREFIXES(PopupControllerTest, Creation);
80 FRIEND_TEST_ALL_PREFIXES(NotificationListTest, UnreadCountNoNegative);
81 FRIEND_TEST_ALL_PREFIXES(NotificationListTest, TestHasNotificationOfType);
83 // The default constructor which doesn't specify the notifier. Used for tests.
84 NotifierId();
87 // The struct to hold the information of notifiers. The information will be
88 // used by NotifierSettingsView.
89 struct MESSAGE_CENTER_EXPORT Notifier {
90 Notifier(const NotifierId& notifier_id,
91 const base::string16& name,
92 bool enabled);
93 ~Notifier();
95 NotifierId notifier_id;
97 // The human-readable name of the notifier such like the extension name.
98 // It can be empty.
99 base::string16 name;
101 // True if the source is allowed to send notifications. True is default.
102 bool enabled;
104 // The icon image of the notifier. The extension icon or favicon.
105 gfx::Image icon;
107 private:
108 DISALLOW_COPY_AND_ASSIGN(Notifier);
111 struct MESSAGE_CENTER_EXPORT NotifierGroup {
112 NotifierGroup(const gfx::Image& icon,
113 const base::string16& name,
114 const base::string16& login_info,
115 size_t index);
116 ~NotifierGroup();
118 // Icon of a notifier group.
119 const gfx::Image icon;
121 // Display name of a notifier group.
122 const base::string16 name;
124 // More display information about the notifier group.
125 base::string16 login_info;
127 // Unique identifier for the notifier group so that they can be selected in
128 // the UI.
129 const size_t index;
131 private:
132 DISALLOW_COPY_AND_ASSIGN(NotifierGroup);
135 // An observer class implemented by the view of the NotifierSettings to get
136 // notified when the controller has changed data.
137 class MESSAGE_CENTER_EXPORT NotifierSettingsObserver {
138 public:
139 // Called when an icon in the controller has been updated.
140 virtual void UpdateIconImage(const NotifierId& notifier_id,
141 const gfx::Image& icon) = 0;
143 // Called when any change happens to the set of notifier groups.
144 virtual void NotifierGroupChanged() = 0;
146 // Called when a notifier is enabled or disabled.
147 virtual void NotifierEnabledChanged(const NotifierId& notifier_id,
148 bool enabled) = 0;
151 // A class used by NotifierSettingsView to integrate with a setting system
152 // for the clients of this module.
153 class MESSAGE_CENTER_EXPORT NotifierSettingsProvider {
154 public:
155 virtual ~NotifierSettingsProvider() {};
157 // Sets the delegate.
158 virtual void AddObserver(NotifierSettingsObserver* observer) = 0;
159 virtual void RemoveObserver(NotifierSettingsObserver* observer) = 0;
161 // Returns the number of notifier groups available.
162 virtual size_t GetNotifierGroupCount() const = 0;
164 // Requests the model for a particular notifier group.
165 virtual const message_center::NotifierGroup& GetNotifierGroupAt(
166 size_t index) const = 0;
168 // Returns true if the notifier group at |index| is active.
169 virtual bool IsNotifierGroupActiveAt(size_t index) const = 0;
171 // Informs the settings provider that further requests to GetNotifierList
172 // should return notifiers for the specified notifier group.
173 virtual void SwitchToNotifierGroup(size_t index) = 0;
175 // Requests the currently active notifier group.
176 virtual const message_center::NotifierGroup& GetActiveNotifierGroup()
177 const = 0;
179 // Collects the current notifier list and fills to |notifiers|. Caller takes
180 // the ownership of the elements of |notifiers|.
181 virtual void GetNotifierList(std::vector<Notifier*>* notifiers) = 0;
183 // Called when the |enabled| for the |notifier| has been changed by user
184 // operation.
185 virtual void SetNotifierEnabled(const Notifier& notifier, bool enabled) = 0;
187 // Called when the settings window is closed.
188 virtual void OnNotifierSettingsClosing() = 0;
190 // Called to determine if a particular notifier can respond to a request for
191 // more information.
192 virtual bool NotifierHasAdvancedSettings(const NotifierId& notifier_id)
193 const = 0;
195 // Called upon request for more information about a particular notifier.
196 virtual void OnNotifierAdvancedSettingsRequested(
197 const NotifierId& notifier_id,
198 const std::string* notification_id) = 0;
201 } // namespace message_center
203 #endif // UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_