1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
content / public / browser / platform_notification_service.h [blame]
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_PUBLIC_BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_
#define CONTENT_PUBLIC_BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_
#include <stdint.h>
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "base/functional/callback_forward.h"
#include "base/time/time.h"
#include "content/common/content_export.h"
#include "content/public/browser/notification_database_data.h"
class GURL;
namespace blink {
struct NotificationResources;
struct PlatformNotificationData;
} // namespace blink
namespace content {
// The service using which notifications can be presented to the user. There
// should be a unique instance of the PlatformNotificationService depending
// on the browsing context being used.
class CONTENT_EXPORT PlatformNotificationService {
public:
virtual ~PlatformNotificationService() {}
using DisplayedNotificationsCallback =
base::OnceCallback<void(std::set<std::string>,
bool /* supports synchronization */)>;
// Displays the notification described in |notification_data| to the user.
// This method must be called on the UI thread. |document_url| is empty when
// the display notification originates from a worker.
virtual void DisplayNotification(
const std::string& notification_id,
const GURL& origin,
const GURL& document_url,
const blink::PlatformNotificationData& notification_data,
const blink::NotificationResources& notification_resources) = 0;
// Displays the persistent notification described in |notification_data| to
// the user. This method must be called on the UI thread.
virtual void DisplayPersistentNotification(
const std::string& notification_id,
const GURL& service_worker_origin,
const GURL& origin,
const blink::PlatformNotificationData& notification_data,
const blink::NotificationResources& notification_resources) = 0;
// Closes the notification identified by |notification_id|. This method must
// be called on the UI thread.
virtual void CloseNotification(const std::string& notification_id) = 0;
// Closes the persistent notification identified by |notification_id|. This
// method must be called on the UI thread.
virtual void ClosePersistentNotification(
const std::string& notification_id) = 0;
// Retrieves the ids of all currently displaying notifications and
// posts |callback| with the result.
virtual void GetDisplayedNotifications(
DisplayedNotificationsCallback callback) = 0;
// Retrieves the ids of all currently displaying notifications associated with
// `origin` and posts `callback` with the result.
virtual void GetDisplayedNotificationsForOrigin(
const GURL& origin,
DisplayedNotificationsCallback callback) = 0;
// Schedules a job to run at |timestamp| and call TriggerNotifications
// on all PlatformNotificationContext instances.
virtual void ScheduleTrigger(base::Time timestamp) = 0;
// Reads the value of the next notification trigger time for this profile.
// This will return base::Time::Max if there is no trigger set.
virtual base::Time ReadNextTriggerTimestamp() = 0;
// Reads the value of the next persistent notification ID from the profile and
// increments the value, as it is called once per notification write.
virtual int64_t ReadNextPersistentNotificationId() = 0;
// Records a given notification to UKM.
virtual void RecordNotificationUkmEvent(
const NotificationDatabaseData& data) = 0;
};
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_