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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_idbmutablefile_h__
8 #define mozilla_dom_idbmutablefile_h__
10 #include "js/TypeDecls.h"
11 #include "mozilla/Atomics.h"
12 #include "mozilla/Attributes.h"
13 #include "mozilla/DOMEventTargetHelper.h"
14 #include "mozilla/dom/FileModeBinding.h"
15 #include "nsCycleCollectionParticipant.h"
16 #include "nsHashKeys.h"
18 #include "nsTHashSet.h"
32 class BackgroundMutableFileChild
;
35 class IDBMutableFile final
: public DOMEventTargetHelper
{
36 RefPtr
<IDBDatabase
> mDatabase
;
38 indexedDB::BackgroundMutableFileChild
* mBackgroundActor
;
40 nsTHashSet
<IDBFileHandle
*> mFileHandles
;
45 Atomic
<bool> mInvalidated
;
48 IDBMutableFile(IDBDatabase
* aDatabase
,
49 indexedDB::BackgroundMutableFileChild
* aActor
,
50 const nsAString
& aName
, const nsAString
& aType
);
52 void AssertIsOnOwningThread() const
60 indexedDB::BackgroundMutableFileChild
* GetBackgroundActor() const {
61 AssertIsOnOwningThread();
63 return mBackgroundActor
;
66 void ClearBackgroundActor() {
67 AssertIsOnOwningThread();
69 mBackgroundActor
= nullptr;
72 const nsString
& Name() const {
73 AssertIsOnOwningThread();
78 const nsString
& Type() const {
79 AssertIsOnOwningThread();
84 void SetLazyData(const nsAString
& aName
, const nsAString
& aType
) {
89 int64_t GetFileId() const;
93 bool IsInvalidated() const {
94 AssertIsOnOwningThread();
99 void RegisterFileHandle(IDBFileHandle
* aFileHandle
);
101 void UnregisterFileHandle(IDBFileHandle
* aFileHandle
);
103 void AbortFileHandles();
106 void GetName(nsString
& aName
) const { aName
= mName
; }
108 void GetType(nsString
& aType
) const { aType
= mType
; }
110 IDBDatabase
* Database() const;
112 [[nodiscard
]] RefPtr
<IDBFileHandle
> Open(FileMode aMode
, ErrorResult
& aError
);
114 IMPL_EVENT_HANDLER(abort
)
115 IMPL_EVENT_HANDLER(error
)
117 NS_DECL_ISUPPORTS_INHERITED
118 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBMutableFile
, DOMEventTargetHelper
)
121 virtual JSObject
* WrapObject(JSContext
* aCx
,
122 JS::Handle
<JSObject
*> aGivenProto
) override
;
129 } // namespace mozilla
131 #endif // mozilla_dom_idbmutablefile_h__