message_center.h revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
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. 4 5#ifndef UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 6#define UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 7 8#include <string> 9 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" 14 15namespace base { 16class DictionaryValue; 17} 18 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. 23 24namespace message_center { 25 26namespace test { 27class MessagePopupCollectionTest; 28} 29 30class MessageCenterObserver; 31class NotificationBlocker; 32class NotifierSettingsProvider; 33 34class MESSAGE_CENTER_EXPORT MessageCenter { 35 public: 36 // Creates the global message center object. 37 static void Initialize(); 38 39 // Returns the global message center object. Returns NULL if Initialize is not 40 // called. 41 static MessageCenter* Get(); 42 43 // Destroys the global message_center object. 44 static void Shutdown(); 45 46 // Management of the observer list. 47 virtual void AddObserver(MessageCenterObserver* observer) = 0; 48 virtual void RemoveObserver(MessageCenterObserver* observer) = 0; 49 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; 57 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 60 // in this list. 61 virtual const NotificationList::Notifications& GetVisibleNotifications() = 0; 62 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; 67 68 // Management of NotificaitonBlockers. 69 virtual void AddNotificationBlocker(NotificationBlocker* blocker) = 0; 70 virtual void RemoveNotificationBlocker(NotificationBlocker* blocker) = 0; 71 72 // Basic operations of notification: add/remove/update. 73 74 // Adds a new notification. 75 virtual void AddNotification(scoped_ptr<Notification> notification) = 0; 76 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; 81 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; 86 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; 90 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; 95 96 // Sets the image for the icon of the specific action button. 97 virtual void SetNotificationButtonIcon(const std::string& notification_id, 98 int button_index, 99 const gfx::Image& image) = 0; 100 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; 106 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 109 // center observers. 110 virtual void ClickOnNotification(const std::string& id) = 0; 111 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 114 // center observers. 115 virtual void ClickOnNotificationButton(const std::string& id, 116 int button_index) = 0; 117 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; 124 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(const std::string& id) = 0; 129 130 // Setter/getter of notifier settings provider. This will be a weak reference. 131 // This should be set at the initialization process. The getter may return 132 // NULL for tests. 133 virtual void SetNotifierSettingsProvider( 134 NotifierSettingsProvider* provider) = 0; 135 virtual NotifierSettingsProvider* GetNotifierSettingsProvider() = 0; 136 137 // This can be called to change the quiet mode state (without a timeout). 138 virtual void SetQuietMode(bool in_quiet_mode) = 0; 139 140 // Temporarily enables quiet mode for |expires_in| time. 141 virtual void EnterQuietModeWithExpire(const base::TimeDelta& expires_in) = 0; 142 143 // Informs the notification list whether the message center is visible. 144 // This affects whether or not a message has been "read". 145 virtual void SetVisibility(Visibility visible) = 0; 146 147 // Allows querying the visibility of the center. 148 virtual bool IsMessageCenterVisible() const = 0; 149 150 // UI classes should call this when there is cause to leave popups visible for 151 // longer than the default (for example, when the mouse hovers over a popup). 152 virtual void PausePopupTimers() = 0; 153 154 // UI classes should call this when the popup timers should restart (for 155 // example, after the mouse leaves the popup.) 156 virtual void RestartPopupTimers() = 0; 157 158 protected: 159 friend class TrayViewControllerTest; 160 friend class test::MessagePopupCollectionTest; 161 virtual void DisableTimersForTest() = 0; 162 163 MessageCenter(); 164 virtual ~MessageCenter(); 165 166 private: 167 DISALLOW_COPY_AND_ASSIGN(MessageCenter); 168}; 169 170} // namespace message_center 171 172#endif // UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 173