// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_MESSAGE_CENTER_NOTIFICATION_BLOCKER_H_ #define UI_MESSAGE_CENTER_NOTIFICATION_BLOCKER_H_ #include "base/memory/raw_ptr.h" #include "base/observer_list.h" #include "base/observer_list_types.h" #include "ui/message_center/message_center_export.h" #include "ui/message_center/public/cpp/notification.h" namespace message_center { class MessageCenter; // NotificationBlocker manages the availability of notifications based on the // current system status. Each NotificationBlocker implementation covers a // single state such as screen lock or fullscreen. // // The current notification state is automatically updated when a blocker is // initialized or destroyed. For instance, the `WelcomeTourNotificationBlocker` // blocks all existing notifications when it is initialized (see below for how // to properly initialize a `NotificationBlocker` subclass), and unblocks // notifications when it is destructed. // // An object of a class that derives from this is not ready until `Init()` has // been called. The following example demonstrates how to properly initialize // such an object: // // class MyNotificationBlocker : public NotificationBlocker { // public: // MyNotificationBlocker(MessageCenter* message_center, ...) // : NotificationBlocker(message_center), ... { ... } // ... // }; // // void foo() { // MessageCenter* message_center = ...; // std::unique_ptr<MyNotificationBlocker> my_blocker = // std::make_unique<MyNotificationBlocker>(message_center, ...); // my_blocker->Init(); /* DON'T FORGET THIS LINE! */ // ... // } // // TODO(b/290637034): Improve upon the `Init()` pattern as it is easy to forget // to call `Init()` when initializing a `NotificationBlocker` subclass. class MESSAGE_CENTER_EXPORT NotificationBlocker { … }; NotificationBlockers; } // namespace message_center #endif // UI_MESSAGE_CENTER_NOTIFICATION_BLOCKER_H_