Bug 1755316 - Add audio tests with simultaneous processes r=alwu
[gecko.git] / dom / indexedDB / IDBMutableFile.h
blob7165c34a2be7967d6c2caf7535dc7a25d1a2ee84
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"
17 #include "nsString.h"
18 #include "nsTHashSet.h"
20 namespace mozilla {
22 class ErrorResult;
24 namespace dom {
26 class DOMRequest;
27 class File;
28 class IDBDatabase;
29 class IDBFileHandle;
31 namespace indexedDB {
32 class BackgroundMutableFileChild;
35 class IDBMutableFile final : public DOMEventTargetHelper {
36 RefPtr<IDBDatabase> mDatabase;
38 indexedDB::BackgroundMutableFileChild* mBackgroundActor;
40 nsTHashSet<IDBFileHandle*> mFileHandles;
42 nsString mName;
43 nsString mType;
45 Atomic<bool> mInvalidated;
47 public:
48 IDBMutableFile(IDBDatabase* aDatabase,
49 indexedDB::BackgroundMutableFileChild* aActor,
50 const nsAString& aName, const nsAString& aType);
52 void AssertIsOnOwningThread() const
53 #ifdef DEBUG
55 #else
58 #endif
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();
75 return mName;
78 const nsString& Type() const {
79 AssertIsOnOwningThread();
81 return mType;
84 void SetLazyData(const nsAString& aName, const nsAString& aType) {
85 mName = aName;
86 mType = aType;
89 int64_t GetFileId() const;
91 void Invalidate();
93 bool IsInvalidated() const {
94 AssertIsOnOwningThread();
96 return mInvalidated;
99 void RegisterFileHandle(IDBFileHandle* aFileHandle);
101 void UnregisterFileHandle(IDBFileHandle* aFileHandle);
103 void AbortFileHandles();
105 // WebIDL
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)
120 // nsWrapperCache
121 virtual JSObject* WrapObject(JSContext* aCx,
122 JS::Handle<JSObject*> aGivenProto) override;
124 private:
125 ~IDBMutableFile();
128 } // namespace dom
129 } // namespace mozilla
131 #endif // mozilla_dom_idbmutablefile_h__