Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | b78d79a5 | 2013-09-12 01:52:21 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #include "ui/message_center/notification_blocker.h" | ||||
6 | |||||
David Sanders | de5fee54 | 2022-03-23 02:47:44 | [diff] [blame] | 7 | #include "base/observer_list.h" |
[email protected] | b78d79a5 | 2013-09-12 01:52:21 | [diff] [blame] | 8 | #include "ui/message_center/message_center.h" |
9 | |||||
10 | namespace message_center { | ||||
11 | |||||
12 | NotificationBlocker::NotificationBlocker(MessageCenter* message_center) | ||||
Elliot Tuck | 267b846 | 2023-07-14 00:48:40 | [diff] [blame] | 13 | : message_center_(message_center) {} |
[email protected] | b78d79a5 | 2013-09-12 01:52:21 | [diff] [blame] | 14 | |
15 | NotificationBlocker::~NotificationBlocker() { | ||||
16 | if (message_center_) | ||||
17 | message_center_->RemoveNotificationBlocker(this); | ||||
18 | } | ||||
19 | |||||
Elliot Tuck | 267b846 | 2023-07-14 00:48:40 | [diff] [blame] | 20 | void NotificationBlocker::Init() { |
21 | CHECK(!is_initialized_) | ||||
22 | << "Do not initialize a NotificationBlocker more than once."; | ||||
23 | is_initialized_ = true; | ||||
24 | if (message_center_) { | ||||
25 | message_center_->AddNotificationBlocker(this); | ||||
26 | } | ||||
27 | } | ||||
28 | |||||
[email protected] | b78d79a5 | 2013-09-12 01:52:21 | [diff] [blame] | 29 | void NotificationBlocker::AddObserver(NotificationBlocker::Observer* observer) { |
30 | observers_.AddObserver(observer); | ||||
31 | } | ||||
32 | |||||
33 | void NotificationBlocker::RemoveObserver( | ||||
34 | NotificationBlocker::Observer* observer) { | ||||
35 | observers_.RemoveObserver(observer); | ||||
36 | } | ||||
37 | |||||
[email protected] | 33aa554d | 2013-12-06 00:47:53 | [diff] [blame] | 38 | bool NotificationBlocker::ShouldShowNotification( |
bmalcolm | b34f499 | 2016-08-03 19:42:00 | [diff] [blame] | 39 | const Notification& notification) const { |
[email protected] | 33aa554d | 2013-12-06 00:47:53 | [diff] [blame] | 40 | return true; |
41 | } | ||||
42 | |||||
43 | void NotificationBlocker::NotifyBlockingStateChanged() { | ||||
Keren Zhu | b2782a7 | 2024-09-27 17:32:38 | [diff] [blame] | 44 | observers_.Notify(&Observer::OnBlockingStateChanged, this); |
[email protected] | 33aa554d | 2013-12-06 00:47:53 | [diff] [blame] | 45 | } |
46 | |||||
[email protected] | b78d79a5 | 2013-09-12 01:52:21 | [diff] [blame] | 47 | } // namespace message_center |