Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / indexedDB / FileInfo.h
blob392ab3c96a9578953a6a007296d8c4fadf9c7df5
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 DOM_INDEXEDDB_FILEINFO_H_
8 #define DOM_INDEXEDDB_FILEINFO_H_
10 #include "nsISupportsImpl.h"
11 #include "nsCOMPtr.h"
12 #include "SafeRefPtr.h"
14 namespace mozilla::dom::indexedDB {
16 class FileInfoBase {
17 public:
18 using IdType = int64_t;
20 IdType Id() const { return mFileId; }
22 protected:
23 explicit FileInfoBase(const int64_t aFileId) : mFileId(aFileId) {
24 MOZ_ASSERT(mFileId > 0);
27 private:
28 const IdType mFileId;
31 template <typename FileManager>
32 class FileInfo final : public FileInfoBase {
33 public:
34 using AutoLockType = typename FileManager::AutoLockType;
36 FileInfo(const typename FileManager::FileInfoManagerGuard& aGuard,
37 SafeRefPtr<FileManager> aFileManager, const int64_t aFileId,
38 const nsrefcnt aInitialDBRefCnt = 0);
40 void AddRef();
41 void Release(const bool aSyncDeleteFile = false);
43 void UpdateDBRefs(int32_t aDelta);
45 void GetReferences(int32_t* aRefCnt, int32_t* aDBRefCnt);
47 FileManager& Manager() const;
49 nsCOMPtr<nsIFile> GetFileForFileInfo() const;
51 void LockedAddRef();
52 bool LockedClearDBRefs(
53 const typename FileManager::FileInfoManagerGuard& aGuard);
55 private:
56 void UpdateReferences(ThreadSafeAutoRefCnt& aRefCount, int32_t aDelta,
57 bool aSyncDeleteFile = false);
59 void Cleanup();
61 ThreadSafeAutoRefCnt mRefCnt;
62 ThreadSafeAutoRefCnt mDBRefCnt;
64 const SafeRefPtr<FileManager> mFileManager;
67 } // namespace mozilla::dom::indexedDB
69 #endif // DOM_INDEXEDDB_FILEINFO_H_