Skip to main content

browser_protocol/backgroundservice/
mod.rs

1//! Defines events for background web platform features.
2
3use serde::{Serialize, Deserialize};
4
5/// The Background Service that will be associated with the commands/events.
6/// Every Background Service operates independently, but they share the same
7/// API.
8
9#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
10pub enum ServiceName {
11    #[default]
12    BackgroundFetch,
13    BackgroundSync,
14    PushMessaging,
15    Notifications,
16    PaymentHandler,
17    PeriodicBackgroundSync,
18}
19
20/// A key-value pair for additional event information to pass along.
21
22#[derive(Debug, Clone, Serialize, Deserialize, Default)]
23#[serde(rename_all = "camelCase")]
24pub struct EventMetadata {
25
26    pub key: String,
27
28    pub value: String,
29}
30
31
32#[derive(Debug, Clone, Serialize, Deserialize, Default)]
33#[serde(rename_all = "camelCase")]
34pub struct BackgroundServiceEvent {
35    /// Timestamp of the event (in seconds).
36
37    pub timestamp: crate::network::TimeSinceEpoch,
38    /// The origin this event belongs to.
39
40    pub origin: String,
41    /// The Service Worker ID that initiated the event.
42
43    pub serviceWorkerRegistrationId: crate::serviceworker::RegistrationID,
44    /// The Background Service this event belongs to.
45
46    pub service: ServiceName,
47    /// A description of the event.
48
49    pub eventName: String,
50    /// An identifier that groups related events together.
51
52    pub instanceId: String,
53    /// A list of event-specific information.
54
55    pub eventMetadata: Vec<EventMetadata>,
56    /// Storage key this event belongs to.
57
58    pub storageKey: String,
59}
60
61/// Enables event updates for the service.
62
63#[derive(Debug, Clone, Serialize, Deserialize, Default)]
64#[serde(rename_all = "camelCase")]
65pub struct StartObservingParams {
66
67    pub service: ServiceName,
68}
69
70/// Disables event updates for the service.
71
72#[derive(Debug, Clone, Serialize, Deserialize, Default)]
73#[serde(rename_all = "camelCase")]
74pub struct StopObservingParams {
75
76    pub service: ServiceName,
77}
78
79/// Set the recording state for the service.
80
81#[derive(Debug, Clone, Serialize, Deserialize, Default)]
82#[serde(rename_all = "camelCase")]
83pub struct SetRecordingParams {
84
85    pub shouldRecord: bool,
86
87    pub service: ServiceName,
88}
89
90/// Clears all stored data for the service.
91
92#[derive(Debug, Clone, Serialize, Deserialize, Default)]
93#[serde(rename_all = "camelCase")]
94pub struct ClearEventsParams {
95
96    pub service: ServiceName,
97}