Bug 1841538 - Fix punctuation r=glandium
[gecko.git] / dom / localstorage / LSDatabase.h
blobb85798eeacbab807f64a24820b152e5fd126b56c
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::dom {
20 class LSDatabaseChild;
21 class LSNotifyInfo;
22 class LSObject;
23 class LSSnapshot;
25 class LSDatabase final {
26 class Observer;
28 LSDatabaseChild* mActor;
30 LSSnapshot* mSnapshot;
32 const nsCString mOrigin;
34 bool mAllowedToClose;
35 bool mRequestedAllowToClose;
37 static StaticRefPtr<Observer> sObserver;
39 public:
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);
50 void ClearActor() {
51 AssertIsOnOwningThread();
52 MOZ_ASSERT(mActor);
54 mActor = nullptr;
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,
72 nsAString& aResult);
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;
94 private:
95 ~LSDatabase();
97 nsresult EnsureSnapshot(LSObject* aObject, const nsAString& aKey,
98 bool aExplicit = false);
100 void AllowToClose();
103 } // namespace mozilla::dom
105 #endif // mozilla_dom_localstorage_LSDatabase_h