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/. */
7 #ifndef mozilla_dom_SessionStorageCache_h
8 #define mozilla_dom_SessionStorageCache_h
10 #include "mozilla/UniquePtr.h"
11 #include "mozilla/dom/LSWriteOptimizerImpl.h"
12 #include "nsTHashMap.h"
14 namespace mozilla::dom
{
18 class SessionStorageCacheChild
;
21 * Coalescing manipulation queue used by `SessionStorageCache`. Used by
22 * `SessionStorageCache` to buffer and coalesce manipulations before they
23 * are sent to the parent process.
25 class SSWriteOptimizer final
: public LSWriteOptimizer
<nsAString
, nsString
> {
27 void Enumerate(nsTArray
<SSWriteInfo
>& aWriteInfos
);
30 class SessionStorageCache final
{
32 NS_INLINE_DECL_REFCOUNTING(SessionStorageCache
)
34 SessionStorageCache();
36 int64_t GetOriginQuotaUsage();
40 void Key(uint32_t aIndex
, nsAString
& aResult
);
42 void GetItem(const nsAString
& aKey
, nsAString
& aResult
);
44 void GetKeys(nsTArray
<nsString
>& aKeys
);
46 nsresult
SetItem(const nsAString
& aKey
, const nsAString
& aValue
,
47 nsString
& aOldValue
, bool aRecordWriteInfo
= true);
49 nsresult
RemoveItem(const nsAString
& aKey
, nsString
& aOldValue
,
50 bool aRecordWriteInfo
= true);
52 void Clear(bool aByUserInteraction
= true, bool aRecordWriteInfo
= true);
54 void ResetWriteInfos();
56 already_AddRefed
<SessionStorageCache
> Clone() const;
58 nsTArray
<SSSetItemInfo
> SerializeData();
60 nsTArray
<SSWriteInfo
> SerializeWriteInfos();
62 void DeserializeData(const nsTArray
<SSSetItemInfo
>& aData
);
64 void DeserializeWriteInfos(const nsTArray
<SSWriteInfo
>& aInfos
);
66 void SetActor(SessionStorageCacheChild
* aActor
);
68 SessionStorageCacheChild
* Actor() const { return mActor
; }
72 void SetLoadedOrCloned() { mLoadedOrCloned
= true; }
74 bool WasLoadedOrCloned() const { return mLoadedOrCloned
; }
77 ~SessionStorageCache();
80 DataSet() : mOriginQuotaUsage(0) {}
82 bool ProcessUsageDelta(int64_t aDelta
);
84 nsTHashMap
<nsStringHashKey
, nsString
> mKeys
;
86 SSWriteOptimizer mWriteOptimizer
;
88 int64_t mOriginQuotaUsage
;
93 SessionStorageCacheChild
* mActor
;
97 } // namespace mozilla::dom
99 #endif // mozilla_dom_SessionStorageCache_h