[email protected] | b78d79a5 | 2013-09-12 01:52:21 | [diff] [blame] | 1 | // Copyright 2013 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_NOTIFICATION_BLOCKER_H_ |
| 6 | #define UI_MESSAGE_CENTER_NOTIFICATION_BLOCKER_H_ |
| 7 | |
| 8 | #include "base/observer_list.h" |
| 9 | #include "ui/message_center/message_center_export.h" |
[email protected] | 33aa554d | 2013-12-06 00:47:53 | [diff] [blame] | 10 | #include "ui/message_center/notification.h" |
[email protected] | b78d79a5 | 2013-09-12 01:52:21 | [diff] [blame] | 11 | |
| 12 | namespace message_center { |
| 13 | class MessageCenter; |
| 14 | |
| 15 | // NotificationBlocker manages the availability of notifications based on the |
| 16 | // current system status. Each NotificationBlocker implementation covers a |
| 17 | // single state such as screen lock or fullscreen. |
| 18 | class MESSAGE_CENTER_EXPORT NotificationBlocker { |
| 19 | public: |
| 20 | class Observer { |
| 21 | public: |
[email protected] | 33aa554d | 2013-12-06 00:47:53 | [diff] [blame] | 22 | virtual void OnBlockingStateChanged(NotificationBlocker* blocker) = 0; |
[email protected] | b78d79a5 | 2013-09-12 01:52:21 | [diff] [blame] | 23 | }; |
| 24 | |
| 25 | explicit NotificationBlocker(MessageCenter* message_center); |
| 26 | virtual ~NotificationBlocker(); |
| 27 | |
| 28 | void AddObserver(Observer* observer); |
| 29 | void RemoveObserver(Observer* observer); |
| 30 | |
| 31 | // Checks the current state and updates the availability. |
| 32 | virtual void CheckState() {} |
| 33 | |
[email protected] | 33aa554d | 2013-12-06 00:47:53 | [diff] [blame] | 34 | // Returns true when notifications from |notifier_id| should appear in the |
| 35 | // message center. Default returns true always. |
| 36 | virtual bool ShouldShowNotification(const NotifierId& notifier_id) const; |
| 37 | |
[email protected] | b78d79a5 | 2013-09-12 01:52:21 | [diff] [blame] | 38 | // Returns true when notifications from |notifier_id| should be shown as |
| 39 | // popups on screen. If it's false, those notifications should be queued. |
| 40 | // When a blocker starts returning false for a notification which is already |
| 41 | // shown as a popup, the notification should be closed as a popup immediately. |
| 42 | virtual bool ShouldShowNotificationAsPopup( |
| 43 | const NotifierId& notifier_id) const = 0; |
| 44 | |
| 45 | protected: |
[email protected] | 33aa554d | 2013-12-06 00:47:53 | [diff] [blame] | 46 | MessageCenter* message_center() { return message_center_; } |
| 47 | void NotifyBlockingStateChanged(); |
[email protected] | b78d79a5 | 2013-09-12 01:52:21 | [diff] [blame] | 48 | |
| 49 | private: |
| 50 | ObserverList<Observer> observers_; |
| 51 | MessageCenter* message_center_; // weak |
| 52 | }; |
| 53 | |
[email protected] | 33aa554d | 2013-12-06 00:47:53 | [diff] [blame] | 54 | typedef std::vector<NotificationBlocker*> NotificationBlockers; |
| 55 | |
[email protected] | b78d79a5 | 2013-09-12 01:52:21 | [diff] [blame] | 56 | } // namespace message_center |
| 57 | |
| 58 | #endif // UI_MESSAGE_CENTER_NOTIFICATION_BLOCKER_H_ |