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"
21 class LSDatabaseChild
;
26 class LSDatabase final
{
29 LSDatabaseChild
* mActor
;
31 LSSnapshot
* mSnapshot
;
33 const nsCString mOrigin
;
36 bool mRequestedAllowToClose
;
38 static StaticRefPtr
<Observer
> sObserver
;
41 explicit LSDatabase(const nsACString
& aOrigin
);
43 static LSDatabase
* Get(const nsACString
& aOrigin
);
45 NS_INLINE_DECL_REFCOUNTING(LSDatabase
)
47 void AssertIsOnOwningThread() const { NS_ASSERT_OWNINGTHREAD(LSDatabase
); }
49 void SetActor(LSDatabaseChild
* aActor
);
52 AssertIsOnOwningThread();
58 bool IsAllowedToClose() const {
59 AssertIsOnOwningThread();
61 return mAllowedToClose
;
64 void RequestAllowToClose();
66 void NoteFinishedSnapshot(LSSnapshot
* aSnapshot
);
68 nsresult
GetLength(LSObject
* aObject
, uint32_t* aResult
);
70 nsresult
GetKey(LSObject
* aObject
, uint32_t aIndex
, nsAString
& aResult
);
72 nsresult
GetItem(LSObject
* aObject
, const nsAString
& aKey
,
75 nsresult
GetKeys(LSObject
* aObject
, nsTArray
<nsString
>& aKeys
);
77 nsresult
SetItem(LSObject
* aObject
, const nsAString
& aKey
,
78 const nsAString
& aValue
, LSNotifyInfo
& aNotifyInfo
);
80 nsresult
RemoveItem(LSObject
* aObject
, const nsAString
& aKey
,
81 LSNotifyInfo
& aNotifyInfo
);
83 nsresult
Clear(LSObject
* aObject
, LSNotifyInfo
& aNotifyInfo
);
85 nsresult
BeginExplicitSnapshot(LSObject
* aObject
);
87 nsresult
CheckpointExplicitSnapshot();
89 nsresult
EndExplicitSnapshot();
91 bool HasSnapshot() const;
93 int64_t GetSnapshotUsage() const;
98 nsresult
EnsureSnapshot(LSObject
* aObject
, const nsAString
& aKey
,
99 bool aExplicit
= false);
105 } // namespace mozilla
107 #endif // mozilla_dom_localstorage_LSDatabase_h