message_center.h revision 58537e28ecd584eab876aee8be7156509866d23a
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"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/observer_list.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/native_widget_types.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/message_center/message_center_export.h"
1458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ui/message_center/message_center_types.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/message_center/notification_list.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/notification_types.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class TrayViewControllerTest;
19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DictionaryValue;
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
24c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Interface to manage the NotificationList. The client (e.g. Chrome) calls
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// [Add|Remove|Update]Notification to create and update notifications in the
26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// list. It also sends those changes to its observers when a notification
27c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// is shown, closed, or clicked on.
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace message_center {
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class MessageCenterObserver;
3258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class NotificationBlocker;
33c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class NotificationList;
34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class NotifierSettingsDelegate;
35eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochclass NotifierSettingsProvider;
36c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
37c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class MESSAGE_CENTER_EXPORT MessageCenter {
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Creates the global message center object.
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static void Initialize();
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Returns the global message center object. Returns NULL if Initialize is not
4358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // called.
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static MessageCenter* Get();
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Destroys the global message_center object.
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static void Shutdown();
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Management of the observer list.
50c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void AddObserver(MessageCenterObserver* observer) = 0;
51c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void RemoveObserver(MessageCenterObserver* observer) = 0;
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
53c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Queries of current notification list status.
54c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual size_t NotificationCount() const = 0;
55c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual size_t UnreadNotificationCount() const = 0;
56c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual bool HasPopupNotifications() const = 0;
57c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual bool HasNotification(const std::string& id) = 0;
58c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual bool IsQuietMode() const = 0;
5990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual bool HasClickedListener(const std::string& id) = 0;
60c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
61c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Getters of the current notifications.
62c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual const NotificationList::Notifications& GetNotifications() = 0;
63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Gets all notifications being shown as popups.
64c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual NotificationList::PopupNotifications GetPopupNotifications() = 0;
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Management of NotificaitonBlockers.
6758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual void AddNotificationBlocker(NotificationBlocker* blocker) = 0;
6858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual void RemoveNotificationBlocker(NotificationBlocker* blocker) = 0;
6958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
70c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Basic operations of notification: add/remove/update.
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Adds a new notification.
73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void AddNotification(scoped_ptr<Notification> notification) = 0;
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Updates an existing notification with id = old_id and set its id to new_id.
76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void UpdateNotification(
77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const std::string& old_id,
78868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      scoped_ptr<Notification> new_notification) = 0;
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Removes an existing notification.
81c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void RemoveNotification(const std::string& id, bool by_user) = 0;
82c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void RemoveAllNotifications(bool by_user) = 0;
83c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
84c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Sets the icon image. Icon appears at the top-left of the notification.
85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void SetNotificationIcon(const std::string& notification_id,
86c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                   const gfx::Image& image) = 0;
87c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
88c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Sets the large image for the notifications of type == TYPE_IMAGE. Specified
89c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // image will appear below of the notification.
90c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void SetNotificationImage(const std::string& notification_id,
91c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                    const gfx::Image& image) = 0;
92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
93a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Sets the image for the icon of the specific action button.
94c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void SetNotificationButtonIcon(const std::string& notification_id,
95c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                         int button_index,
96c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                         const gfx::Image& image) = 0;
97c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Operations happening especially from GUIs: click, expand, disable,
99c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // and settings.
100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Searches through the notifications and disables any that match the
101868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // extension id given.
102424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual void DisableNotificationsByNotifier(
103424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      const NotifierId& notifier_id) = 0;
104868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
105868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Reformat a notification to show its entire text content.
106c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void ExpandNotification(const std::string& id) = 0;
107868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
108868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // This should be called by UI classes when a notification is clicked to
109868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // trigger the notification's delegate callback and also update the message
110868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // center observers.
111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void ClickOnNotification(const std::string& id) = 0;
112868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
113868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // This should be called by UI classes when a notification button is clicked
114868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // to trigger the notification's delegate callback and also update the message
115868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // center observers.
116c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void ClickOnNotificationButton(const std::string& id,
117c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                         int button_index) = 0;
118868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
119868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // This should be called by UI classes after a visible notification popup
120868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // closes, indicating that the notification has been shown to the user.
121868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // |mark_notification_as_read|, if false, will unset the read bit on a
122868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // notification, increasing the unread count of the center.
123c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void MarkSinglePopupAsShown(const std::string& id,
124c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                      bool mark_notification_as_read) = 0;
125868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
126868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // This should be called by UI classes when a notification is first displayed
127868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // to the user, in order to decrement the unread_count for the tray, and to
128868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // notify observers that the notification is visible.
129c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void DisplayedNotification(const std::string& id) = 0;
130868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
131eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Setter/getter of notifier settings provider. This will be a weak reference.
132eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // This should be set at the initialization process. The getter may return
133eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // NULL for tests.
134eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void SetNotifierSettingsProvider(
135eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      NotifierSettingsProvider* provider) = 0;
136eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual NotifierSettingsProvider* GetNotifierSettingsProvider() = 0;
137eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
138868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // This can be called to change the quiet mode state (without a timeout).
139c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void SetQuietMode(bool in_quiet_mode) = 0;
140868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
141868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Temporarily enables quiet mode for |expires_in| time.
142c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void EnterQuietModeWithExpire(const base::TimeDelta& expires_in) = 0;
143868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
144c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Informs the notification list whether the message center is visible.
145c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // This affects whether or not a message has been "read".
14658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual void SetVisibility(Visibility visible) = 0;
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
148868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Allows querying the visibility of the center.
149868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual bool IsMessageCenterVisible() = 0;
150868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
151868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // UI classes should call this when there is cause to leave popups visible for
152868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // longer than the default (for example, when the mouse hovers over a popup).
153868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void PausePopupTimers() = 0;
154868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
155868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // UI classes should call this when the popup timers should restart (for
156868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // example, after the mouse leaves the popup.)
157868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void RestartPopupTimers() = 0;
158868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
160868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  friend class ::TrayViewControllerTest;
161868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void DisableTimersForTest() = 0;
162868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  MessageCenter();
1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~MessageCenter();
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(MessageCenter);
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace message_center
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // UI_MESSAGE_CENTER_MESSAGE_CENTER_H_
173