sync_manager/types.rs
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use std::collections::HashMap;
6use std::time::SystemTime;
7use sync15::DeviceType;
8
9#[derive(Debug)]
10pub struct SyncParams {
11 // Why are we performing this sync?
12 pub reason: SyncReason,
13 // Which engines should we sync?
14 pub engines: SyncEngineSelection,
15 // Which engines should be enabled in the "account global" list (for
16 // example, if the UI was used to change an engine's state since the last
17 // sync).
18 pub enabled_changes: HashMap<String, bool>,
19 // Keys to encrypt/decrypt data from local database files. These are
20 // separate from the key we use to encrypt the sync payload as a whole.
21 pub local_encryption_keys: HashMap<String, String>,
22 // Authorization for the sync server
23 pub auth_info: SyncAuthInfo,
24 // An opaque string, as returned in the previous sync's SyncResult and
25 // persisted to disk, or null if no such state is available. This includes
26 // information such as the list of engines previously enabled, certain
27 // server timestamps and GUIDs etc. If this value isn't correctly persisted
28 // and round-tripped, each sync may look like a "first sync".
29 pub persisted_state: Option<String>,
30 // Information about the current device, such as its name, formfactor and
31 // FxA device ID.
32 pub device_settings: DeviceSettings,
33}
34
35#[derive(Debug)]
36pub enum SyncReason {
37 Scheduled,
38 User,
39 PreSleep,
40 Startup,
41 EnabledChange,
42 Backgrounded,
43}
44
45#[derive(Debug)]
46pub enum SyncEngineSelection {
47 All,
48 Some { engines: Vec<String> },
49}
50
51#[derive(Debug)]
52pub struct SyncAuthInfo {
53 pub kid: String,
54 pub fxa_access_token: String,
55 pub sync_key: String,
56 pub tokenserver_url: String,
57}
58
59#[derive(Debug)]
60pub struct DeviceSettings {
61 pub fxa_device_id: String,
62 pub name: String,
63 pub kind: DeviceType,
64}
65
66#[derive(Debug)]
67pub struct SyncResult {
68 // Result from the sync server
69 pub status: ServiceStatus,
70 // Engines that synced successfully
71 pub successful: Vec<String>,
72 // Maps the names of engines that failed to sync to the reason why
73 pub failures: HashMap<String, String>,
74 // State that should be persisted to disk and supplied to the sync method
75 // on the next sync (See SyncParams.persisted_state).
76 pub persisted_state: String,
77 // The list of engines which are marked as "declined" (ie, disabled) on the
78 // sync server. The list of declined engines is global to the account
79 // rather than to the device. Apps should use this after every sync to
80 // update the local state (ie, to ensure that their Sync UI correctly
81 // reflects what engines are enabled and disabled), because these could
82 // change after every sync.
83 pub declined: Option<Vec<String>>,
84 // Earliest time that the next sync should happen at
85 pub next_sync_allowed_at: Option<SystemTime>,
86 // JSON string encoding a `SyncTelemetryPing` object
87 pub telemetry_json: Option<String>,
88}
89
90#[derive(Debug)]
91pub enum ServiceStatus {
92 Ok,
93 NetworkError,
94 ServiceError,
95 AuthError,
96 BackedOff,
97 OtherError,
98}
99
100impl ServiceStatus {
101 pub fn is_ok(&self) -> bool {
102 matches!(self, ServiceStatus::Ok)
103 }
104}