Bug 1874684 - Part 6: Limit day length calculations to safe integers. r=mgaudet
[gecko.git] / dom / storage / SessionStorageCache.h
blob6e5a57d3da19135e87e221d23f90b6dc712927b9
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 {
16 class SSSetItemInfo;
17 class SSWriteInfo;
18 class SessionStorageCacheChild;
20 /**
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> {
26 public:
27 void Enumerate(nsTArray<SSWriteInfo>& aWriteInfos);
30 class SessionStorageCache final {
31 public:
32 NS_INLINE_DECL_REFCOUNTING(SessionStorageCache)
34 SessionStorageCache();
36 int64_t GetOriginQuotaUsage();
38 uint32_t Length();
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; }
70 void ClearActor();
72 void SetLoadedOrCloned() { mLoadedOrCloned = true; }
74 bool WasLoadedOrCloned() const { return mLoadedOrCloned; }
76 private:
77 ~SessionStorageCache();
79 struct DataSet {
80 DataSet() : mOriginQuotaUsage(0) {}
82 bool ProcessUsageDelta(int64_t aDelta);
84 nsTHashMap<nsStringHashKey, nsString> mKeys;
86 SSWriteOptimizer mWriteOptimizer;
88 int64_t mOriginQuotaUsage;
91 DataSet mDataSet;
93 SessionStorageCacheChild* mActor;
94 bool mLoadedOrCloned;
97 } // namespace mozilla::dom
99 #endif // mozilla_dom_SessionStorageCache_h