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