tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

LSDatabase.h (2575B)


      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/. */
      6 
      7 #ifndef mozilla_dom_localstorage_LSDatabase_h
      8 #define mozilla_dom_localstorage_LSDatabase_h
      9 
     10 #include <cstdint>
     11 
     12 #include "ErrorList.h"
     13 #include "mozilla/Assertions.h"
     14 #include "mozilla/StaticPtr.h"
     15 #include "nsISupports.h"
     16 #include "nsString.h"
     17 #include "nsTArrayForwardDeclare.h"
     18 
     19 namespace mozilla::dom {
     20 
     21 class LSDatabaseChild;
     22 class LSNotifyInfo;
     23 class LSObject;
     24 class LSSnapshot;
     25 
     26 class LSDatabase final {
     27  class Observer;
     28 
     29  LSDatabaseChild* mActor;
     30 
     31  LSSnapshot* mSnapshot;
     32 
     33  const nsCString mOrigin;
     34 
     35  bool mAllowedToClose;
     36  bool mRequestedAllowToClose;
     37 
     38  static StaticRefPtr<Observer> sObserver;
     39 
     40 public:
     41  explicit LSDatabase(const nsACString& aOrigin);
     42 
     43  static LSDatabase* Get(const nsACString& aOrigin);
     44 
     45  NS_INLINE_DECL_REFCOUNTING(LSDatabase)
     46 
     47  void AssertIsOnOwningThread() const { NS_ASSERT_OWNINGTHREAD(LSDatabase); }
     48 
     49  void SetActor(LSDatabaseChild* aActor);
     50 
     51  void ClearActor() {
     52    AssertIsOnOwningThread();
     53    MOZ_ASSERT(mActor);
     54 
     55    mActor = nullptr;
     56  }
     57 
     58  bool IsAllowedToClose() const {
     59    AssertIsOnOwningThread();
     60 
     61    return mAllowedToClose;
     62  }
     63 
     64  void RequestAllowToClose();
     65 
     66  void NoteFinishedSnapshot(LSSnapshot* aSnapshot);
     67 
     68  nsresult GetLength(LSObject* aObject, uint32_t* aResult);
     69 
     70  nsresult GetKey(LSObject* aObject, uint32_t aIndex, nsAString& aResult);
     71 
     72  nsresult GetItem(LSObject* aObject, const nsAString& aKey,
     73                   nsAString& aResult);
     74 
     75  nsresult GetKeys(LSObject* aObject, nsTArray<nsString>& aKeys);
     76 
     77  nsresult SetItem(LSObject* aObject, const nsAString& aKey,
     78                   const nsAString& aValue, LSNotifyInfo& aNotifyInfo);
     79 
     80  nsresult RemoveItem(LSObject* aObject, const nsAString& aKey,
     81                      LSNotifyInfo& aNotifyInfo);
     82 
     83  nsresult Clear(LSObject* aObject, LSNotifyInfo& aNotifyInfo);
     84 
     85  nsresult BeginExplicitSnapshot(LSObject* aObject);
     86 
     87  nsresult CheckpointExplicitSnapshot();
     88 
     89  nsresult EndExplicitSnapshot();
     90 
     91  bool HasSnapshot() const;
     92 
     93  int64_t GetSnapshotUsage() const;
     94 
     95 private:
     96  ~LSDatabase();
     97 
     98  nsresult EnsureSnapshot(LSObject* aObject, const nsAString& aKey,
     99                          bool aExplicit = false);
    100 
    101  void AllowToClose();
    102 };
    103 
    104 }  // namespace mozilla::dom
    105 
    106 #endif  // mozilla_dom_localstorage_LSDatabase_h