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 SessionStorageCache final {
16
public:
17
NS_INLINE_DECL_REFCOUNTING(SessionStorageCache)
18
19
SessionStorageCache();
20
21
enum DataSetType {
22
eDefaultSetType,
23
eSessionSetType,
24
};
25
26
int64_t GetOriginQuotaUsage(DataSetType aDataSetType);
27
28
uint32_t Length(DataSetType aDataSetType);
29
30
void Key(DataSetType aDataSetType, uint32_t aIndex, nsAString& aResult);
31
32
void GetItem(DataSetType aDataSetType, const nsAString& aKey,
33
nsAString& aResult);
34
35
void GetKeys(DataSetType aDataSetType, nsTArray<nsString>& aKeys);
36
37
nsresult SetItem(DataSetType aDataSetType, const nsAString& aKey,
38
const nsAString& aValue, nsString& aOldValue);
39
40
nsresult RemoveItem(DataSetType aDataSetType, const nsAString& aKey,
41
nsString& aOldValue);
42
43
void Clear(DataSetType aDataSetType, bool aByUserInteraction = true);
44
45
already_AddRefed<SessionStorageCache> Clone() const;
46
47
private:
48
~SessionStorageCache() = default;
49
50
struct DataSet {
51
DataSet() : mOriginQuotaUsage(0) {}
52
53
bool ProcessUsageDelta(int64_t aDelta);
54
55
int64_t mOriginQuotaUsage;
56
nsDataHashtable<nsStringHashKey, nsString> mKeys;
57
};
58
59
DataSet* Set(DataSetType aDataSetType);
60
61
DataSet mDefaultSet;
62
DataSet mSessionSet;
63
};
64
65
} // namespace dom
66
} // namespace mozilla
67
68
#endif // mozilla_dom_SessionStorageCache_h