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