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::client_storage::ClientStorageThreadMessage;
12use crate::indexeddb::IndexedDBThreadMsg;
13use crate::webstorage_thread::WebStorageThreadMsg;
14
15pub mod client_storage;
16pub mod indexeddb;
17pub mod webstorage_thread;
18
19#[derive(Clone, Debug, Deserialize, Serialize)]
20pub struct StorageThreads {
21    client_storage_thread: GenericSender<ClientStorageThreadMessage>,
22    idb_thread: IpcSender<IndexedDBThreadMsg>,
23    web_storage_thread: GenericSender<WebStorageThreadMsg>,
24}
25
26impl StorageThreads {
27    pub fn new(
28        client_storage_thread: GenericSender<ClientStorageThreadMessage>,
29        idb_thread: IpcSender<IndexedDBThreadMsg>,
30        web_storage_thread: GenericSender<WebStorageThreadMsg>,
31    ) -> StorageThreads {
32        StorageThreads {
33            client_storage_thread,
34            idb_thread,
35            web_storage_thread,
36        }
37    }
38}
39
40impl GenericSend<ClientStorageThreadMessage> for StorageThreads {
41    fn send(&self, msg: ClientStorageThreadMessage) -> SendResult {
42        self.client_storage_thread.send(msg)
43    }
44
45    fn sender(&self) -> GenericSender<ClientStorageThreadMessage> {
46        self.client_storage_thread.clone()
47    }
48}
49
50impl IpcSend<IndexedDBThreadMsg> for StorageThreads {
51    fn send(&self, msg: IndexedDBThreadMsg) -> IpcSendResult {
52        self.idb_thread.send(msg).map_err(IpcError::Bincode)
53    }
54
55    fn sender(&self) -> IpcSender<IndexedDBThreadMsg> {
56        self.idb_thread.clone()
57    }
58}
59
60impl GenericSend<WebStorageThreadMsg> for StorageThreads {
61    fn send(&self, msg: WebStorageThreadMsg) -> SendResult {
62        self.web_storage_thread.send(msg)
63    }
64
65    fn sender(&self) -> GenericSender<WebStorageThreadMsg> {
66        self.web_storage_thread.clone()
67    }
68}
69
70// Ignore the sub-fields
71malloc_size_of_is_0!(StorageThreads);