aboutsummaryrefslogtreecommitdiffstats
path: root/components/net_traits/storage_task.rs
blob: 261e6cb1f7be262e52f920309a5d6f31b5c8be1c (plain) (blame)
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
34
35
36
37
38
39
40
41
42
43
44
45
/* 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 ipc_channel::ipc::IpcSender;
use url::Url;

use util::str::DOMString;

#[derive(Copy, Clone, Deserialize, Serialize, HeapSizeOf)]
pub enum StorageType {
    Session,
    Local
}

/// Request operations on the storage data associated with a particular url
#[derive(Deserialize, Serialize)]
pub enum StorageTaskMsg {
    /// gets the number of key/value pairs present in the associated storage data
    Length(IpcSender<usize>, Url, StorageType),

    /// gets the name of the key at the specified index in the associated storage data
    Key(IpcSender<Option<DOMString>>, Url, StorageType, u32),

    /// gets the value associated with the given key in the associated storage data
    GetItem(IpcSender<Option<DOMString>>, Url, StorageType, DOMString),

    /// sets the value of the given key in the associated storage data
    /// TODO throw QuotaExceededError in case of error
    SetItem(IpcSender<(bool, Option<DOMString>)>, Url, StorageType, DOMString, DOMString),

    /// removes the key/value pair for the given key in the associated storage data
    RemoveItem(IpcSender<Option<DOMString>>, Url, StorageType, DOMString),

    /// clears the associated storage data by removing all the key/value pairs
    Clear(IpcSender<bool>, Url, StorageType),

    /// shut down this task
    Exit
}

/// Handle to a storage task
pub type StorageTask = IpcSender<StorageTaskMsg>;