Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_dom_SessionStorageCache_h
8
#define mozilla_dom_SessionStorageCache_h
9
10
#include "nsDataHashtable.h"
11
12
namespace mozilla {
13
namespace dom {
14
15
class KeyValuePair;
16
17
class SessionStorageCache final {
18
public:
19
NS_INLINE_DECL_REFCOUNTING(SessionStorageCache)
20
21
SessionStorageCache();
22
23
enum DataSetType {
24
eDefaultSetType,
25
eSessionSetType,
26
};
27
28
int64_t GetOriginQuotaUsage(DataSetType aDataSetType);
29
30
uint32_t Length(DataSetType aDataSetType);
31
32
void Key(DataSetType aDataSetType, uint32_t aIndex, nsAString& aResult);
33
34
void GetItem(DataSetType aDataSetType, const nsAString& aKey,
35
nsAString& aResult);
36
37
void GetKeys(DataSetType aDataSetType, nsTArray<nsString>& aKeys);
38
39
nsresult SetItem(DataSetType aDataSetType, const nsAString& aKey,
40
const nsAString& aValue, nsString& aOldValue);
41
42
nsresult RemoveItem(DataSetType aDataSetType, const nsAString& aKey,
43
nsString& aOldValue);
44
45
void Clear(DataSetType aDataSetType, bool aByUserInteraction = true);
46
47
already_AddRefed<SessionStorageCache> Clone() const;
48
49
nsTArray<KeyValuePair> SerializeData(DataSetType aDataSetType);
50
void DeserializeData(DataSetType aDataSetType,
51
const nsTArray<KeyValuePair>& aData);
52
53
private:
54
~SessionStorageCache() = default;
55
56
struct DataSet {
57
DataSet() : mOriginQuotaUsage(0) {}
58
59
bool ProcessUsageDelta(int64_t aDelta);
60
61
int64_t mOriginQuotaUsage;
62
nsDataHashtable<nsStringHashKey, nsString> mKeys;
63
};
64
65
DataSet* Set(DataSetType aDataSetType);
66
67
DataSet mDefaultSet;
68
DataSet mSessionSet;
69
};
70
71
} // namespace dom
72
} // namespace mozilla
73
74
#endif // mozilla_dom_SessionStorageCache_h