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"
12 #include "SafeRefPtr.h"
14 namespace mozilla::dom::indexedDB
{
18 using IdType
= int64_t;
20 IdType
Id() const { return mFileId
; }
23 explicit FileInfoBase(const int64_t aFileId
) : mFileId(aFileId
) {
24 MOZ_ASSERT(mFileId
> 0);
31 template <typename FileManager
>
32 class FileInfo final
: public FileInfoBase
{
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);
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;
52 bool LockedClearDBRefs(
53 const typename
FileManager::FileInfoManagerGuard
& aGuard
);
56 void UpdateReferences(ThreadSafeAutoRefCnt
& aRefCount
, int32_t aDelta
,
57 bool aSyncDeleteFile
= false);
61 ThreadSafeAutoRefCnt mRefCnt
;
62 ThreadSafeAutoRefCnt mDBRefCnt
;
64 const SafeRefPtr
<FileManager
> mFileManager
;
67 } // namespace mozilla::dom::indexedDB
69 #endif // DOM_INDEXEDDB_FILEINFO_H_