storage_traits/
lib.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 base::generic_channel::{GenericSend, GenericSender, SendResult};
6use base::{IpcSend, IpcSendResult};
7use ipc_channel::ipc::{IpcError, IpcSender};
8use malloc_size_of::malloc_size_of_is_0;
9use serde::{Deserialize, Serialize};
10
11use crate::indexeddb_thread::IndexedDBThreadMsg;
12use crate::webstorage_thread::WebStorageThreadMsg;
13
14pub mod indexeddb_thread;
15pub mod webstorage_thread;
16
17#[derive(Clone, Debug, Deserialize, Serialize)]
18pub struct StorageThreads {
19    web_storage_thread: GenericSender<WebStorageThreadMsg>,
20    idb_thread: IpcSender<IndexedDBThreadMsg>,
21}
22
23impl StorageThreads {
24    pub fn new(
25        web_storage_thread: GenericSender<WebStorageThreadMsg>,
26        idb_thread: IpcSender<IndexedDBThreadMsg>,
27    ) -> StorageThreads {
28        StorageThreads {
29            web_storage_thread,
30            idb_thread,
31        }
32    }
33}
34
35impl IpcSend<IndexedDBThreadMsg> for StorageThreads {
36    fn send(&self, msg: IndexedDBThreadMsg) -> IpcSendResult {
37        self.idb_thread.send(msg).map_err(IpcError::Bincode)
38    }
39
40    fn sender(&self) -> IpcSender<IndexedDBThreadMsg> {
41        self.idb_thread.clone()
42    }
43}
44
45impl GenericSend<WebStorageThreadMsg> for StorageThreads {
46    fn send(&self, msg: WebStorageThreadMsg) -> SendResult {
47        self.web_storage_thread.send(msg)
48    }
49
50    fn sender(&self) -> GenericSender<WebStorageThreadMsg> {
51        self.web_storage_thread.clone()
52    }
53}
54
55// Ignore the sub-fields
56malloc_size_of_is_0!(StorageThreads);