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_localstorage_LSDatabase_h
8 #define mozilla_dom_localstorage_LSDatabase_h
11 #include "ErrorList.h"
12 #include "mozilla/Assertions.h"
13 #include "mozilla/StaticPtr.h"
14 #include "nsISupports.h"
16 #include "nsTArrayForwardDeclare.h"
18 namespace mozilla::dom
{
20 class LSDatabaseChild
;
25 class LSDatabase final
{
28 LSDatabaseChild
* mActor
;
30 LSSnapshot
* mSnapshot
;
32 const nsCString mOrigin
;
35 bool mRequestedAllowToClose
;
37 static StaticRefPtr
<Observer
> sObserver
;
40 explicit LSDatabase(const nsACString
& aOrigin
);
42 static LSDatabase
* Get(const nsACString
& aOrigin
);
44 NS_INLINE_DECL_REFCOUNTING(LSDatabase
)
46 void AssertIsOnOwningThread() const { NS_ASSERT_OWNINGTHREAD(LSDatabase
); }
48 void SetActor(LSDatabaseChild
* aActor
);
51 AssertIsOnOwningThread();
57 bool IsAllowedToClose() const {
58 AssertIsOnOwningThread();
60 return mAllowedToClose
;
63 void RequestAllowToClose();
65 void NoteFinishedSnapshot(LSSnapshot
* aSnapshot
);
67 nsresult
GetLength(LSObject
* aObject
, uint32_t* aResult
);
69 nsresult
GetKey(LSObject
* aObject
, uint32_t aIndex
, nsAString
& aResult
);
71 nsresult
GetItem(LSObject
* aObject
, const nsAString
& aKey
,
74 nsresult
GetKeys(LSObject
* aObject
, nsTArray
<nsString
>& aKeys
);
76 nsresult
SetItem(LSObject
* aObject
, const nsAString
& aKey
,
77 const nsAString
& aValue
, LSNotifyInfo
& aNotifyInfo
);
79 nsresult
RemoveItem(LSObject
* aObject
, const nsAString
& aKey
,
80 LSNotifyInfo
& aNotifyInfo
);
82 nsresult
Clear(LSObject
* aObject
, LSNotifyInfo
& aNotifyInfo
);
84 nsresult
BeginExplicitSnapshot(LSObject
* aObject
);
86 nsresult
CheckpointExplicitSnapshot();
88 nsresult
EndExplicitSnapshot();
90 bool HasSnapshot() const;
92 int64_t GetSnapshotUsage() const;
97 nsresult
EnsureSnapshot(LSObject
* aObject
, const nsAString
& aKey
,
98 bool aExplicit
= false);
103 } // namespace mozilla::dom
105 #endif // mozilla_dom_localstorage_LSDatabase_h