#ifndef CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_EVENT_DISPATCHER_IMPL_H_
#define CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_EVENT_DISPATCHER_IMPL_H_
#include <map>
#include <string>
#include <utility>
#include "base/functional/callback_forward.h"
#include "base/memory/singleton.h"
#include "base/types/optional_ref.h"
#include "content/common/content_export.h"
#include "content/public/browser/notification_database_data.h"
#include "content/public/browser/notification_event_dispatcher.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/weak_document_ptr.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/notifications/notification_service.mojom.h"
namespace content {
class CONTENT_EXPORT NotificationEventDispatcherImpl
: public NotificationEventDispatcher {
public:
static NotificationEventDispatcherImpl* GetInstance();
NotificationEventDispatcherImpl(const NotificationEventDispatcherImpl&) =
delete;
NotificationEventDispatcherImpl& operator=(
const NotificationEventDispatcherImpl&) = delete;
void DispatchNotificationClickEvent(
BrowserContext* browser_context,
const std::string& notification_id,
const GURL& origin,
const std::optional<int>& action_index,
const std::optional<std::u16string>& reply,
NotificationDispatchCompleteCallback dispatch_complete_callback) override;
void DispatchNotificationCloseEvent(
BrowserContext* browser_context,
const std::string& notification_id,
const GURL& origin,
bool by_user,
NotificationDispatchCompleteCallback dispatch_complete_callback) override;
void DispatchNonPersistentShowEvent(
const std::string& notification_id) override;
void DispatchNonPersistentClickEvent(
const std::string& notification_id,
NotificationClickEventCallback callback) override;
void DispatchNonPersistentCloseEvent(
const std::string& notification_id,
base::OnceClosure completed_closure) override;
void RegisterNonPersistentNotificationListener(
const std::string& notification_id,
mojo::PendingRemote<blink::mojom::NonPersistentNotificationListener>
event_listener_remote,
const WeakDocumentPtr& event_document_ptr,
RenderProcessHost::NotificationServiceCreatorType creator_type);
private:
struct NonPersistentNotificationListenerInfo {
NonPersistentNotificationListenerInfo(
mojo::Remote<blink::mojom::NonPersistentNotificationListener> remote,
WeakDocumentPtr document,
RenderProcessHost::NotificationServiceCreatorType creator_type);
NonPersistentNotificationListenerInfo(
NonPersistentNotificationListenerInfo&&);
NonPersistentNotificationListenerInfo(
const NonPersistentNotificationListenerInfo&) = delete;
NonPersistentNotificationListenerInfo& operator=(
const NonPersistentNotificationListenerInfo&) = delete;
~NonPersistentNotificationListenerInfo();
mojo::Remote<blink::mojom::NonPersistentNotificationListener> remote;
WeakDocumentPtr document;
RenderProcessHost::NotificationServiceCreatorType creator_type;
};
friend class NotificationEventDispatcherImplTest;
friend struct base::DefaultSingletonTraits<NotificationEventDispatcherImpl>;
NotificationEventDispatcherImpl();
~NotificationEventDispatcherImpl() override;
base::optional_ref<NonPersistentNotificationListenerInfo>
GetListenerIfNotifiable(const std::string& notification_id);
void OnNonPersistentCloseComplete(const std::string& notification_id,
base::OnceClosure completed_closure);
void HandleConnectionErrorForNonPersistentNotificationListener(
const std::string& notification_id);
std::map<std::string, NonPersistentNotificationListenerInfo>
non_persistent_notification_listeners_;
};
}
#endif