mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-03 15:26:07 +00:00

Session Storage used to share implementation with Local Storage, where a distinction of a default data set from a session data set made sense. In Session Storage all data is actually scoped by the session. Since Bug 1322316 Session Storage no longer share implementation with Local Storage, which makes it safe to collapse the datasets in Session Storage to one dataset, which makes life easier, especially for Session (Re-)Store. Differential Revision: https://phabricator.services.mozilla.com/D116609
102 lines
2.6 KiB
C++
102 lines
2.6 KiB
C++
/* -*- 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
|
|
|
|
#include "mozilla/UniquePtr.h"
|
|
#include "mozilla/dom/LSWriteOptimizerImpl.h"
|
|
#include "nsTHashMap.h"
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
|
|
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);
|
|
};
|
|
|
|
class SessionStorageCache final {
|
|
public:
|
|
NS_INLINE_DECL_REFCOUNTING(SessionStorageCache)
|
|
|
|
SessionStorageCache();
|
|
|
|
int64_t GetOriginQuotaUsage();
|
|
|
|
uint32_t Length();
|
|
|
|
void Key(uint32_t aIndex, nsAString& aResult);
|
|
|
|
void GetItem(const nsAString& aKey, nsAString& aResult);
|
|
|
|
void GetKeys(nsTArray<nsString>& aKeys);
|
|
|
|
nsresult SetItem(const nsAString& aKey, const nsAString& aValue,
|
|
nsString& aOldValue, bool aRecordWriteInfo = true);
|
|
|
|
nsresult RemoveItem(const nsAString& aKey, nsString& aOldValue,
|
|
bool aRecordWriteInfo = true);
|
|
|
|
void Clear(bool aByUserInteraction = true, bool aRecordWriteInfo = true);
|
|
|
|
void ResetWriteInfos();
|
|
|
|
already_AddRefed<SessionStorageCache> Clone() const;
|
|
|
|
nsTArray<SSSetItemInfo> SerializeData();
|
|
|
|
nsTArray<SSWriteInfo> SerializeWriteInfos();
|
|
|
|
void DeserializeData(const nsTArray<SSSetItemInfo>& aData);
|
|
|
|
void DeserializeWriteInfos(const nsTArray<SSWriteInfo>& aInfos);
|
|
|
|
void SetActor(SessionStorageCacheChild* aActor);
|
|
|
|
SessionStorageCacheChild* Actor() const { return mActor; }
|
|
|
|
void ClearActor();
|
|
|
|
void SetLoadedOrCloned() { mLoadedOrCloned = true; }
|
|
|
|
bool WasLoadedOrCloned() const { return mLoadedOrCloned; }
|
|
|
|
private:
|
|
~SessionStorageCache();
|
|
|
|
struct DataSet {
|
|
DataSet() : mOriginQuotaUsage(0) {}
|
|
|
|
bool ProcessUsageDelta(int64_t aDelta);
|
|
|
|
nsTHashMap<nsStringHashKey, nsString> mKeys;
|
|
|
|
SSWriteOptimizer mWriteOptimizer;
|
|
|
|
int64_t mOriginQuotaUsage;
|
|
};
|
|
|
|
DataSet mDataSet;
|
|
|
|
SessionStorageCacheChild* mActor;
|
|
bool mLoadedOrCloned;
|
|
};
|
|
|
|
} // namespace dom
|
|
} // namespace mozilla
|
|
|
|
#endif // mozilla_dom_SessionStorageCache_h
|