15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string> 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/message_center/message_center_export.h" 1258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ui/message_center/message_center_types.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/message_center/notification_list.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base { 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DictionaryValue; 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 19c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Interface to manage the NotificationList. The client (e.g. Chrome) calls 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// [Add|Remove|Update]Notification to create and update notifications in the 21c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// list. It also sends those changes to its observers when a notification 22c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// is shown, closed, or clicked on. 23f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// 24f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// MessageCenter is agnostic of profiles; it uses the string returned by 25f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// message_center::Notification::id() to uniquely identify a notification. It is 26f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// the caller's responsibility to formulate the id so that 2 different 27f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// notification should have different ids. For example, if the caller supports 28f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// multiple profiles, then caller should encode both profile characteristics and 29f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// notification front end's notification id into a new id and set it into the 30f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// notification instance before passing that in. Consequently the id passed to 31f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// observers will be this unique id, which can be used with MessageCenter 32f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// interface but probably not higher level interfaces. 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace message_center { 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace test { 37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class MessagePopupCollectionTest; 38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 40c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class MessageCenterObserver; 4158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class NotificationBlocker; 42eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochclass NotifierSettingsProvider; 43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class MESSAGE_CENTER_EXPORT MessageCenter { 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Creates the global message center object. 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static void Initialize(); 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Returns the global message center object. Returns NULL if Initialize is not 5058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // called. 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static MessageCenter* Get(); 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Destroys the global message_center object. 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static void Shutdown(); 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Management of the observer list. 57c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void AddObserver(MessageCenterObserver* observer) = 0; 58c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void RemoveObserver(MessageCenterObserver* observer) = 0; 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 60c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Queries of current notification list status. 61c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual size_t NotificationCount() const = 0; 62c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual size_t UnreadNotificationCount() const = 0; 63c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual bool HasPopupNotifications() const = 0; 64c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual bool IsQuietMode() const = 0; 6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual bool HasClickedListener(const std::string& id) = 0; 66c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 67f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Find the notification with the corresponding id. Returns NULL if not found. 68f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // The returned instance is owned by the message center. 69f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) virtual message_center::Notification* FindVisibleNotificationById( 70f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) const std::string& id) = 0; 71f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 7268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Gets all notifications to be shown to the user in the message center. Note 7368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // that queued changes due to the message center being open are not reflected 7468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // in this list. 7568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) virtual const NotificationList::Notifications& GetVisibleNotifications() = 0; 7668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 7768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Gets all notifications being shown as popups. This should not be affected 7868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // by the change queue since notifications are not held up while the state is 7968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // VISIBILITY_TRANSIENT or VISIBILITY_SETTINGS. 80c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual NotificationList::PopupNotifications GetPopupNotifications() = 0; 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 82010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Management of NotificationBlockers. 8358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual void AddNotificationBlocker(NotificationBlocker* blocker) = 0; 8458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual void RemoveNotificationBlocker(NotificationBlocker* blocker) = 0; 8558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 86c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Basic operations of notification: add/remove/update. 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Adds a new notification. 89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) virtual void AddNotification(scoped_ptr<Notification> notification) = 0; 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates an existing notification with id = old_id and set its id to new_id. 92868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) virtual void UpdateNotification( 93868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const std::string& old_id, 94868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) scoped_ptr<Notification> new_notification) = 0; 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Removes an existing notification. 97c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void RemoveNotification(const std::string& id, bool by_user) = 0; 98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void RemoveAllNotifications(bool by_user) = 0; 99a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual void RemoveAllVisibleNotifications(bool by_user) = 0; 100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 101c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Sets the icon image. Icon appears at the top-left of the notification. 102c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void SetNotificationIcon(const std::string& notification_id, 103c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const gfx::Image& image) = 0; 104c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Sets the large image for the notifications of type == TYPE_IMAGE. Specified 106c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // image will appear below of the notification. 107c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void SetNotificationImage(const std::string& notification_id, 108c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const gfx::Image& image) = 0; 109c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 110a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // Sets the image for the icon of the specific action button. 111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void SetNotificationButtonIcon(const std::string& notification_id, 112c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) int button_index, 113c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const gfx::Image& image) = 0; 114c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Operations happening especially from GUIs: click, disable, and settings. 116868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Searches through the notifications and disables any that match the 117868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // extension id given. 118424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual void DisableNotificationsByNotifier( 119424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const NotifierId& notifier_id) = 0; 120868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 121868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // This should be called by UI classes when a notification is clicked to 122868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // trigger the notification's delegate callback and also update the message 123868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // center observers. 124c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void ClickOnNotification(const std::string& id) = 0; 125868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 126868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // This should be called by UI classes when a notification button is clicked 127868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // to trigger the notification's delegate callback and also update the message 128868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // center observers. 129c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void ClickOnNotificationButton(const std::string& id, 130c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) int button_index) = 0; 131868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 132868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // This should be called by UI classes after a visible notification popup 133868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // closes, indicating that the notification has been shown to the user. 134868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // |mark_notification_as_read|, if false, will unset the read bit on a 135868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // notification, increasing the unread count of the center. 136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void MarkSinglePopupAsShown(const std::string& id, 137c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool mark_notification_as_read) = 0; 138868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 139868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // This should be called by UI classes when a notification is first displayed 140868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // to the user, in order to decrement the unread_count for the tray, and to 141868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // notify observers that the notification is visible. 142010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual void DisplayedNotification( 143010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) const std::string& id, 144010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) const DisplaySource source) = 0; 145868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 146eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Setter/getter of notifier settings provider. This will be a weak reference. 147eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // This should be set at the initialization process. The getter may return 148eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // NULL for tests. 149eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual void SetNotifierSettingsProvider( 150eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch NotifierSettingsProvider* provider) = 0; 151eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual NotifierSettingsProvider* GetNotifierSettingsProvider() = 0; 152eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 153868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // This can be called to change the quiet mode state (without a timeout). 154c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void SetQuietMode(bool in_quiet_mode) = 0; 155868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 156868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Temporarily enables quiet mode for |expires_in| time. 157c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void EnterQuietModeWithExpire(const base::TimeDelta& expires_in) = 0; 158868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 159c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Informs the notification list whether the message center is visible. 160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // This affects whether or not a message has been "read". 16158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual void SetVisibility(Visibility visible) = 0; 1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 163868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Allows querying the visibility of the center. 164a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual bool IsMessageCenterVisible() const = 0; 165868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 166868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // UI classes should call this when there is cause to leave popups visible for 167868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // longer than the default (for example, when the mouse hovers over a popup). 168868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) virtual void PausePopupTimers() = 0; 169868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 170868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // UI classes should call this when the popup timers should restart (for 171868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // example, after the mouse leaves the popup.) 172868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) virtual void RestartPopupTimers() = 0; 173868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 175a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) friend class TrayViewControllerTest; 176f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) friend class test::MessagePopupCollectionTest; 177868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) virtual void DisableTimersForTest() = 0; 178868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MessageCenter(); 1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~MessageCenter(); 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(MessageCenter); 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace message_center 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 189