Bug 1755316 - Add audio tests with simultaneous processes r=alwu
[gecko.git] / dom / localstorage / LSDatabase.h
blob6304a24bc861998d2a1ff7ec12d74709743fbac8
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
10 #include <cstdint>
11 #include "ErrorList.h"
12 #include "mozilla/Assertions.h"
13 #include "mozilla/StaticPtr.h"
14 #include "nsISupports.h"
15 #include "nsString.h"
16 #include "nsTArrayForwardDeclare.h"
18 namespace mozilla {
19 namespace dom {
21 class LSDatabaseChild;
22 class LSNotifyInfo;
23 class LSObject;
24 class LSSnapshot;
26 class LSDatabase final {
27 class Observer;
29 LSDatabaseChild* mActor;
31 LSSnapshot* mSnapshot;
33 const nsCString mOrigin;
35 bool mAllowedToClose;
36 bool mRequestedAllowToClose;
38 static StaticRefPtr<Observer> sObserver;
40 public:
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);
51 void ClearActor() {
52 AssertIsOnOwningThread();
53 MOZ_ASSERT(mActor);
55 mActor = nullptr;
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,
73 nsAString& aResult);
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;
95 private:
96 ~LSDatabase();
98 nsresult EnsureSnapshot(LSObject* aObject, const nsAString& aKey,
99 bool aExplicit = false);
101 void AllowToClose();
104 } // namespace dom
105 } // namespace mozilla
107 #endif // mozilla_dom_localstorage_LSDatabase_h