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, expand, disable, 107 // and settings. 108 // Searches through the notifications and disables any that match the 109 // extension id given. 110 virtual void DisableNotificationsByNotifier( 111 const NotifierId& notifier_id) = 0; 112 113 // Reformat a notification to show its entire text content. 114 virtual void ExpandNotification(const std::string& id) = 0; 115 116 // This should be called by UI classes when a notification is clicked to 117 // trigger the notification's delegate callback and also update the message 118 // center observers. 119 virtual void ClickOnNotification(const std::string& id) = 0; 120 121 // This should be called by UI classes when a notification button is clicked 122 // to trigger the notification's delegate callback and also update the message 123 // center observers. 124 virtual void ClickOnNotificationButton(const std::string& id, 125 int button_index) = 0; 126 127 // This should be called by UI classes after a visible notification popup 128 // closes, indicating that the notification has been shown to the user. 129 // |mark_notification_as_read|, if false, will unset the read bit on a 130 // notification, increasing the unread count of the center. 131 virtual void MarkSinglePopupAsShown(const std::string& id, 132 bool mark_notification_as_read) = 0; 133 134 // This should be called by UI classes when a notification is first displayed 135 // to the user, in order to decrement the unread_count for the tray, and to 136 // notify observers that the notification is visible. 137 virtual void DisplayedNotification(const std::string& id) = 0; 138 139 // Setter/getter of notifier settings provider. This will be a weak reference. 140 // This should be set at the initialization process. The getter may return 141 // NULL for tests. 142 virtual void SetNotifierSettingsProvider( 143 NotifierSettingsProvider* provider) = 0; 144 virtual NotifierSettingsProvider* GetNotifierSettingsProvider() = 0; 145 146 // This can be called to change the quiet mode state (without a timeout). 147 virtual void SetQuietMode(bool in_quiet_mode) = 0; 148 149 // Temporarily enables quiet mode for |expires_in| time. 150 virtual void EnterQuietModeWithExpire(const base::TimeDelta& expires_in) = 0; 151 152 // Informs the notification list whether the message center is visible. 153 // This affects whether or not a message has been "read". 154 virtual void SetVisibility(Visibility visible) = 0; 155 156 // Allows querying the visibility of the center. 157 virtual bool IsMessageCenterVisible() const = 0; 158 159 // UI classes should call this when there is cause to leave popups visible for 160 // longer than the default (for example, when the mouse hovers over a popup). 161 virtual void PausePopupTimers() = 0; 162 163 // UI classes should call this when the popup timers should restart (for 164 // example, after the mouse leaves the popup.) 165 virtual void RestartPopupTimers() = 0; 166 167 protected: 168 friend class TrayViewControllerTest; 169 friend class test::MessagePopupCollectionTest; 170 virtual void DisableTimersForTest() = 0; 171 172 MessageCenter(); 173 virtual ~MessageCenter(); 174 175 private: 176 DISALLOW_COPY_AND_ASSIGN(MessageCenter); 177}; 178 179} // namespace message_center 180 181#endif // UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 182