2017-05-17 08:01:14 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_SessionStorageCache_h
|
|
|
|
#define mozilla_dom_SessionStorageCache_h
|
|
|
|
|
2020-10-14 03:19:33 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
|
|
|
#include "mozilla/dom/LSWriteOptimizerImpl.h"
|
2021-03-10 13:47:47 +03:00
|
|
|
#include "nsTHashMap.h"
|
2017-05-17 08:01:14 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2020-10-14 03:19:33 +03:00
|
|
|
class SSSetItemInfo;
|
|
|
|
class SSWriteInfo;
|
|
|
|
class SessionStorageCacheChild;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Coalescing manipulation queue used by `SessionStorageCache`. Used by
|
|
|
|
* `SessionStorageCache` to buffer and coalesce manipulations before they
|
|
|
|
* are sent to the parent process.
|
|
|
|
*/
|
|
|
|
class SSWriteOptimizer final : public LSWriteOptimizer<nsAString, nsString> {
|
|
|
|
public:
|
|
|
|
void Enumerate(nsTArray<SSWriteInfo>& aWriteInfos);
|
|
|
|
};
|
2019-12-13 12:45:55 +03:00
|
|
|
|
2017-05-17 08:01:14 +03:00
|
|
|
class SessionStorageCache final {
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(SessionStorageCache)
|
|
|
|
|
|
|
|
SessionStorageCache();
|
|
|
|
|
2021-06-08 16:42:33 +03:00
|
|
|
int64_t GetOriginQuotaUsage();
|
2017-05-17 08:01:14 +03:00
|
|
|
|
2021-06-08 16:42:33 +03:00
|
|
|
uint32_t Length();
|
2017-05-17 08:01:14 +03:00
|
|
|
|
2021-06-08 16:42:33 +03:00
|
|
|
void Key(uint32_t aIndex, nsAString& aResult);
|
2017-05-17 08:01:14 +03:00
|
|
|
|
2021-06-08 16:42:33 +03:00
|
|
|
void GetItem(const nsAString& aKey, nsAString& aResult);
|
2017-05-17 08:01:14 +03:00
|
|
|
|
2021-06-08 16:42:33 +03:00
|
|
|
void GetKeys(nsTArray<nsString>& aKeys);
|
2017-05-17 08:01:14 +03:00
|
|
|
|
2021-06-08 16:42:33 +03:00
|
|
|
nsresult SetItem(const nsAString& aKey, const nsAString& aValue,
|
|
|
|
nsString& aOldValue, bool aRecordWriteInfo = true);
|
2017-05-17 08:01:14 +03:00
|
|
|
|
2021-06-08 16:42:33 +03:00
|
|
|
nsresult RemoveItem(const nsAString& aKey, nsString& aOldValue,
|
|
|
|
bool aRecordWriteInfo = true);
|
2017-05-17 08:01:14 +03:00
|
|
|
|
2021-06-08 16:42:33 +03:00
|
|
|
void Clear(bool aByUserInteraction = true, bool aRecordWriteInfo = true);
|
2020-10-14 03:19:33 +03:00
|
|
|
|
2021-06-08 16:42:33 +03:00
|
|
|
void ResetWriteInfos();
|
2017-05-17 08:01:14 +03:00
|
|
|
|
|
|
|
already_AddRefed<SessionStorageCache> Clone() const;
|
|
|
|
|
2021-06-08 16:42:33 +03:00
|
|
|
nsTArray<SSSetItemInfo> SerializeData();
|
2020-10-14 03:19:33 +03:00
|
|
|
|
2021-06-08 16:42:33 +03:00
|
|
|
nsTArray<SSWriteInfo> SerializeWriteInfos();
|
2020-10-14 03:19:33 +03:00
|
|
|
|
2021-06-08 16:42:33 +03:00
|
|
|
void DeserializeData(const nsTArray<SSSetItemInfo>& aData);
|
2020-10-14 03:19:33 +03:00
|
|
|
|
2021-06-08 16:42:33 +03:00
|
|
|
void DeserializeWriteInfos(const nsTArray<SSWriteInfo>& aInfos);
|
2020-10-14 03:19:33 +03:00
|
|
|
|
|
|
|
void SetActor(SessionStorageCacheChild* aActor);
|
|
|
|
|
|
|
|
SessionStorageCacheChild* Actor() const { return mActor; }
|
|
|
|
|
|
|
|
void ClearActor();
|
|
|
|
|
|
|
|
void SetLoadedOrCloned() { mLoadedOrCloned = true; }
|
|
|
|
|
|
|
|
bool WasLoadedOrCloned() const { return mLoadedOrCloned; }
|
2019-12-13 12:45:55 +03:00
|
|
|
|
2017-05-17 08:01:14 +03:00
|
|
|
private:
|
2020-10-14 03:19:33 +03:00
|
|
|
~SessionStorageCache();
|
2017-05-17 08:01:14 +03:00
|
|
|
|
2017-05-17 08:01:15 +03:00
|
|
|
struct DataSet {
|
|
|
|
DataSet() : mOriginQuotaUsage(0) {}
|
|
|
|
|
|
|
|
bool ProcessUsageDelta(int64_t aDelta);
|
|
|
|
|
2021-03-10 13:47:47 +03:00
|
|
|
nsTHashMap<nsStringHashKey, nsString> mKeys;
|
2020-10-14 03:19:33 +03:00
|
|
|
|
|
|
|
SSWriteOptimizer mWriteOptimizer;
|
|
|
|
|
|
|
|
int64_t mOriginQuotaUsage;
|
2017-05-17 08:01:15 +03:00
|
|
|
};
|
|
|
|
|
2021-06-08 16:42:33 +03:00
|
|
|
DataSet mDataSet;
|
2020-10-14 03:19:33 +03:00
|
|
|
|
|
|
|
SessionStorageCacheChild* mActor;
|
|
|
|
bool mLoadedOrCloned;
|
2017-05-17 08:01:14 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_SessionStorageCache_h
|