blob: 5ea0af11c29a21f055649cc7cbf6cca719271313 [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2013 The Chromium Authors
[email protected]b78d79a52013-09-12 01:52:212// 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 Sandersde5fee542022-03-23 02:47:447#include "base/observer_list.h"
[email protected]b78d79a52013-09-12 01:52:218#include "ui/message_center/message_center.h"
9
10namespace message_center {
11
12NotificationBlocker::NotificationBlocker(MessageCenter* message_center)
Elliot Tuck267b8462023-07-14 00:48:4013 : message_center_(message_center) {}
[email protected]b78d79a52013-09-12 01:52:2114
15NotificationBlocker::~NotificationBlocker() {
16 if (message_center_)
17 message_center_->RemoveNotificationBlocker(this);
18}
19
Elliot Tuck267b8462023-07-14 00:48:4020void 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]b78d79a52013-09-12 01:52:2129void NotificationBlocker::AddObserver(NotificationBlocker::Observer* observer) {
30 observers_.AddObserver(observer);
31}
32
33void NotificationBlocker::RemoveObserver(
34 NotificationBlocker::Observer* observer) {
35 observers_.RemoveObserver(observer);
36}
37
[email protected]33aa554d2013-12-06 00:47:5338bool NotificationBlocker::ShouldShowNotification(
bmalcolmb34f4992016-08-03 19:42:0039 const Notification& notification) const {
[email protected]33aa554d2013-12-06 00:47:5340 return true;
41}
42
43void NotificationBlocker::NotifyBlockingStateChanged() {
ericwilligersdfd9e462016-10-17 19:38:1744 for (auto& observer : observers_)
45 observer.OnBlockingStateChanged(this);
[email protected]33aa554d2013-12-06 00:47:5346}
47
[email protected]b78d79a52013-09-12 01:52:2148} // namespace message_center