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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use crate::error::*;
use serde_derive::{Deserialize, Serialize};

#[derive(Debug, Clone, Hash, PartialEq, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct TabsRecordTab {
    pub title: String,
    pub url_history: Vec<String>,
    pub icon: Option<String>,
    pub last_used: u64, // Seconds since epoch!
}

#[derive(Debug, Clone, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TabsRecord {
    pub id: String, // `String` instead of `SyncGuid` because some IDs are FxA device ID.
    pub client_name: String,
    pub tabs: Vec<TabsRecordTab>,
    #[serde(default)]
    pub ttl: u32,
}

impl TabsRecord {
    #[inline]
    pub fn from_payload(payload: sync15::Payload) -> Result<Self> {
        let record: TabsRecord = payload.into_record()?;
        Ok(record)
    }
}