message_center.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 "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" 17 18namespace base { 19class DictionaryValue; 20} 21 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. 26 27namespace message_center { 28 29namespace test { 30class MessagePopupCollectionTest; 31} 32 33class MessageCenterObserver; 34class NotificationBlocker; 35class NotificationList; 36class NotifierSettingsDelegate; 37class NotifierSettingsProvider; 38 39class MESSAGE_CENTER_EXPORT MessageCenter { 40 public: 41 // Creates the global message center object. 42 static void Initialize(); 43 44 // Returns the global message center object. Returns NULL if Initialize is not 45 // called. 46 static MessageCenter* Get(); 47 48 // Destroys the global message_center object. 49 static void Shutdown(); 50 51 // Management of the observer list. 52 virtual void AddObserver(MessageCenterObserver* observer) = 0; 53 virtual void RemoveObserver(MessageCenterObserver* observer) = 0; 54 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; 62 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 65 // in this list. 66 virtual const NotificationList::Notifications& GetVisibleNotifications() = 0; 67 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; 72 73 // Management of NotificaitonBlockers. 74 virtual void AddNotificationBlocker(NotificationBlocker* blocker) = 0; 75 virtual void RemoveNotificationBlocker(NotificationBlocker* blocker) = 0; 76 77 // Basic operations of notification: add/remove/update. 78 79 // Adds a new notification. 80 virtual void AddNotification(scoped_ptr<Notification> notification) = 0; 81 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; 86 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; 91 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; 95 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; 100 101 // Sets the image for the icon of the specific action button. 102 virtual void SetNotificationButtonIcon(const std::string& notification_id, 103 int button_index, 104 const gfx::Image& image) = 0; 105 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; 111 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 114 // center observers. 115 virtual void ClickOnNotification(const std::string& id) = 0; 116 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 119 // center observers. 120 virtual void ClickOnNotificationButton(const std::string& id, 121 int button_index) = 0; 122 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; 129 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; 134 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 137 // NULL for tests. 138 virtual void SetNotifierSettingsProvider( 139 NotifierSettingsProvider* provider) = 0; 140 virtual NotifierSettingsProvider* GetNotifierSettingsProvider() = 0; 141 142 // This can be called to change the quiet mode state (without a timeout). 143 virtual void SetQuietMode(bool in_quiet_mode) = 0; 144 145 // Temporarily enables quiet mode for |expires_in| time. 146 virtual void EnterQuietModeWithExpire(const base::TimeDelta& expires_in) = 0; 147 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; 151 152 // Allows querying the visibility of the center. 153 virtual bool IsMessageCenterVisible() const = 0; 154 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; 158 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; 162 163 protected: 164 friend class TrayViewControllerTest; 165 friend class test::MessagePopupCollectionTest; 166 virtual void DisableTimersForTest() = 0; 167 168 MessageCenter(); 169 virtual ~MessageCenter(); 170 171 private: 172 DISALLOW_COPY_AND_ASSIGN(MessageCenter); 173}; 174 175} // namespace message_center 176 177#endif // UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 178