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/. */ 6 7 #ifndef mozilla_dom_idbmutablefile_h__ 8 #define mozilla_dom_idbmutablefile_h__ 9 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" 19 20 namespace mozilla { 21 22 class ErrorResult; 23 24 namespace dom { 25 26 class DOMRequest; 27 class File; 28 class IDBDatabase; 29 class IDBFileHandle; 30 31 namespace indexedDB { 32 class BackgroundMutableFileChild; 33 } 34 35 class IDBMutableFile final : public DOMEventTargetHelper { 36 RefPtr<IDBDatabase> mDatabase; 37 38 indexedDB::BackgroundMutableFileChild* mBackgroundActor; 39 40 nsTHashSet<IDBFileHandle*> mFileHandles; 41 42 nsString mName; 43 nsString mType; 44 45 Atomic<bool> mInvalidated; 46 47 public: 48 IDBMutableFile(IDBDatabase* aDatabase, 49 indexedDB::BackgroundMutableFileChild* aActor, 50 const nsAString& aName, const nsAString& aType); 51 52 void AssertIsOnOwningThread() const 53 #ifdef DEBUG 54 ; 55 #else 56 { 57 } 58 #endif 59 GetBackgroundActor()60 indexedDB::BackgroundMutableFileChild* GetBackgroundActor() const { 61 AssertIsOnOwningThread(); 62 63 return mBackgroundActor; 64 } 65 ClearBackgroundActor()66 void ClearBackgroundActor() { 67 AssertIsOnOwningThread(); 68 69 mBackgroundActor = nullptr; 70 } 71 Name()72 const nsString& Name() const { 73 AssertIsOnOwningThread(); 74 75 return mName; 76 } 77 Type()78 const nsString& Type() const { 79 AssertIsOnOwningThread(); 80 81 return mType; 82 } 83 SetLazyData(const nsAString & aName,const nsAString & aType)84 void SetLazyData(const nsAString& aName, const nsAString& aType) { 85 mName = aName; 86 mType = aType; 87 } 88 89 int64_t GetFileId() const; 90 91 void Invalidate(); 92 IsInvalidated()93 bool IsInvalidated() const { 94 AssertIsOnOwningThread(); 95 96 return mInvalidated; 97 } 98 99 void RegisterFileHandle(IDBFileHandle* aFileHandle); 100 101 void UnregisterFileHandle(IDBFileHandle* aFileHandle); 102 103 void AbortFileHandles(); 104 105 // WebIDL GetName(nsString & aName)106 void GetName(nsString& aName) const { aName = mName; } 107 GetType(nsString & aType)108 void GetType(nsString& aType) const { aType = mType; } 109 110 IDBDatabase* Database() const; 111 112 [[nodiscard]] RefPtr<IDBFileHandle> Open(FileMode aMode, ErrorResult& aError); 113 114 IMPL_EVENT_HANDLER(abort) 115 IMPL_EVENT_HANDLER(error) 116 117 NS_DECL_ISUPPORTS_INHERITED 118 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBMutableFile, DOMEventTargetHelper) 119 120 // nsWrapperCache 121 virtual JSObject* WrapObject(JSContext* aCx, 122 JS::Handle<JSObject*> aGivenProto) override; 123 124 private: 125 ~IDBMutableFile(); 126 }; 127 128 } // namespace dom 129 } // namespace mozilla 130 131 #endif // mozilla_dom_idbmutablefile_h__ 132