tor-browser

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

FileInfo.h (1815B)


      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 DOM_INDEXEDDB_FILEINFO_H_
      8 #define DOM_INDEXEDDB_FILEINFO_H_
      9 
     10 #include "SafeRefPtr.h"
     11 #include "nsCOMPtr.h"
     12 #include "nsISupportsImpl.h"
     13 
     14 namespace mozilla::dom::indexedDB {
     15 
     16 class FileInfoBase {
     17 public:
     18  using IdType = int64_t;
     19 
     20  IdType Id() const { return mFileId; }
     21 
     22 protected:
     23  explicit FileInfoBase(const int64_t aFileId) : mFileId(aFileId) {
     24    MOZ_ASSERT(mFileId > 0);
     25  }
     26 
     27 private:
     28  const IdType mFileId;
     29 };
     30 
     31 template <typename FileManager>
     32 class FileInfo final : public FileInfoBase {
     33 public:
     34  using AutoLockType = typename FileManager::AutoLockType;
     35 
     36  FileInfo(const typename FileManager::FileInfoManagerGuard& aGuard,
     37           SafeRefPtr<FileManager> aFileManager, const int64_t aFileId,
     38           const nsrefcnt aInitialDBRefCnt = 0);
     39 
     40  void AddRef();
     41  void Release(const bool aSyncDeleteFile = false);
     42 
     43  void UpdateDBRefs(int32_t aDelta);
     44 
     45  void GetReferences(int32_t* aRefCnt, int32_t* aDBRefCnt);
     46 
     47  FileManager& Manager() const;
     48 
     49  nsCOMPtr<nsIFile> GetFileForFileInfo() const;
     50 
     51  void LockedAddRef();
     52  bool LockedClearDBRefs(
     53      const typename FileManager::FileInfoManagerGuard& aGuard);
     54 
     55 private:
     56  void UpdateReferences(ThreadSafeAutoRefCnt& aRefCount, int32_t aDelta,
     57                        bool aSyncDeleteFile = false);
     58 
     59  void Cleanup();
     60 
     61  ThreadSafeAutoRefCnt mRefCnt;
     62  ThreadSafeAutoRefCnt mDBRefCnt;
     63 
     64  const SafeRefPtr<FileManager> mFileManager;
     65 };
     66 
     67 }  // namespace mozilla::dom::indexedDB
     68 
     69 #endif  // DOM_INDEXEDDB_FILEINFO_H_