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 UI_MESSAGE_CENTER_MESSAGE_CENTER_H_
6 #define UI_MESSAGE_CENTER_MESSAGE_CENTER_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "ui/message_center/message_center_export.h"
12 #include "ui/message_center/message_center_types.h"
13 #include "ui/message_center/notification_list.h"
16 class DictionaryValue;
19 // Interface to manage the NotificationList. The client (e.g. Chrome) calls
20 // [Add|Remove|Update]Notification to create and update notifications in the
21 // list. It also sends those changes to its observers when a notification
22 // is shown, closed, or clicked on.
24 namespace message_center {
27 class MessagePopupCollectionTest;
30 class MessageCenterObserver;
31 class NotificationBlocker;
32 class NotifierSettingsProvider;
34 class MESSAGE_CENTER_EXPORT MessageCenter {
36 // Creates the global message center object.
37 static void Initialize();
39 // Returns the global message center object. Returns NULL if Initialize is not
41 static MessageCenter* Get();
43 // Destroys the global message_center object.
44 static void Shutdown();
46 // Management of the observer list.
47 virtual void AddObserver(MessageCenterObserver* observer) = 0;
48 virtual void RemoveObserver(MessageCenterObserver* observer) = 0;
50 // Queries of current notification list status.
51 virtual size_t NotificationCount() const = 0;
52 virtual size_t UnreadNotificationCount() const = 0;
53 virtual bool HasPopupNotifications() const = 0;
54 virtual bool HasNotification(const std::string& id) = 0;
55 virtual bool IsQuietMode() const = 0;
56 virtual bool HasClickedListener(const std::string& id) = 0;
58 // Gets all notifications to be shown to the user in the message center. Note
59 // that queued changes due to the message center being open are not reflected
61 virtual const NotificationList::Notifications& GetVisibleNotifications() = 0;
63 // Gets all notifications being shown as popups. This should not be affected
64 // by the change queue since notifications are not held up while the state is
65 // VISIBILITY_TRANSIENT or VISIBILITY_SETTINGS.
66 virtual NotificationList::PopupNotifications GetPopupNotifications() = 0;
68 // Management of NotificationBlockers.
69 virtual void AddNotificationBlocker(NotificationBlocker* blocker) = 0;
70 virtual void RemoveNotificationBlocker(NotificationBlocker* blocker) = 0;
72 // Basic operations of notification: add/remove/update.
74 // Adds a new notification.
75 virtual void AddNotification(scoped_ptr<Notification> notification) = 0;
77 // Updates an existing notification with id = old_id and set its id to new_id.
78 virtual void UpdateNotification(
79 const std::string& old_id,
80 scoped_ptr<Notification> new_notification) = 0;
82 // Removes an existing notification.
83 virtual void RemoveNotification(const std::string& id, bool by_user) = 0;
84 virtual void RemoveAllNotifications(bool by_user) = 0;
85 virtual void RemoveAllVisibleNotifications(bool by_user) = 0;
87 // Sets the icon image. Icon appears at the top-left of the notification.
88 virtual void SetNotificationIcon(const std::string& notification_id,
89 const gfx::Image& image) = 0;
91 // Sets the large image for the notifications of type == TYPE_IMAGE. Specified
92 // image will appear below of the notification.
93 virtual void SetNotificationImage(const std::string& notification_id,
94 const gfx::Image& image) = 0;
96 // Sets the image for the icon of the specific action button.
97 virtual void SetNotificationButtonIcon(const std::string& notification_id,
99 const gfx::Image& image) = 0;
101 // Operations happening especially from GUIs: click, disable, and settings.
102 // Searches through the notifications and disables any that match the
103 // extension id given.
104 virtual void DisableNotificationsByNotifier(
105 const NotifierId& notifier_id) = 0;
107 // This should be called by UI classes when a notification is clicked to
108 // trigger the notification's delegate callback and also update the message
110 virtual void ClickOnNotification(const std::string& id) = 0;
112 // This should be called by UI classes when a notification button is clicked
113 // to trigger the notification's delegate callback and also update the message
115 virtual void ClickOnNotificationButton(const std::string& id,
116 int button_index) = 0;
118 // This should be called by UI classes after a visible notification popup
119 // closes, indicating that the notification has been shown to the user.
120 // |mark_notification_as_read|, if false, will unset the read bit on a
121 // notification, increasing the unread count of the center.
122 virtual void MarkSinglePopupAsShown(const std::string& id,
123 bool mark_notification_as_read) = 0;
125 // This should be called by UI classes when a notification is first displayed
126 // to the user, in order to decrement the unread_count for the tray, and to
127 // notify observers that the notification is visible.
128 virtual void DisplayedNotification(
129 const std::string& id,
130 const DisplaySource source) = 0;
132 // Setter/getter of notifier settings provider. This will be a weak reference.
133 // This should be set at the initialization process. The getter may return
135 virtual void SetNotifierSettingsProvider(
136 NotifierSettingsProvider* provider) = 0;
137 virtual NotifierSettingsProvider* GetNotifierSettingsProvider() = 0;
139 // This can be called to change the quiet mode state (without a timeout).
140 virtual void SetQuietMode(bool in_quiet_mode) = 0;
142 // Temporarily enables quiet mode for |expires_in| time.
143 virtual void EnterQuietModeWithExpire(const base::TimeDelta& expires_in) = 0;
145 // Informs the notification list whether the message center is visible.
146 // This affects whether or not a message has been "read".
147 virtual void SetVisibility(Visibility visible) = 0;
149 // Allows querying the visibility of the center.
150 virtual bool IsMessageCenterVisible() const = 0;
152 // UI classes should call this when there is cause to leave popups visible for
153 // longer than the default (for example, when the mouse hovers over a popup).
154 virtual void PausePopupTimers() = 0;
156 // UI classes should call this when the popup timers should restart (for
157 // example, after the mouse leaves the popup.)
158 virtual void RestartPopupTimers() = 0;
161 friend class TrayViewControllerTest;
162 friend class test::MessagePopupCollectionTest;
163 virtual void DisableTimersForTest() = 0;
166 virtual ~MessageCenter();
169 DISALLOW_COPY_AND_ASSIGN(MessageCenter);
172 } // namespace message_center
174 #endif // UI_MESSAGE_CENTER_MESSAGE_CENTER_H_