FileSystemAccessHandle.h (3061B)
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/. */ 6 7 #ifndef DOM_FS_PARENT_FILESYSTEMACCESSHANDLE_H_ 8 #define DOM_FS_PARENT_FILESYSTEMACCESSHANDLE_H_ 9 10 #include "FileSystemStreamCallbacks.h" 11 #include "mozilla/MozPromise.h" 12 #include "mozilla/NotNull.h" 13 #include "mozilla/RefPtr.h" 14 #include "mozilla/dom/FileSystemTypes.h" 15 #include "mozilla/dom/quota/ForwardDecls.h" 16 #include "nsISupportsImpl.h" 17 #include "nsString.h" 18 19 enum class nsresult : uint32_t; 20 21 namespace mozilla { 22 23 class TaskQueue; 24 25 namespace ipc { 26 class RandomAccessStreamParams; 27 } 28 29 namespace dom { 30 31 class FileSystemAccessHandleControlParent; 32 class FileSystemAccessHandleParent; 33 34 namespace fs { 35 36 template <class T> 37 class Registered; 38 39 namespace data { 40 41 class FileSystemDataManager; 42 43 } // namespace data 44 } // namespace fs 45 46 class FileSystemAccessHandle : public FileSystemStreamCallbacks { 47 public: 48 using CreateResult = std::pair<fs::Registered<FileSystemAccessHandle>, 49 mozilla::ipc::RandomAccessStreamParams>; 50 // IsExclusive is true because we want to allow moving of CreateResult. 51 // There's always just one consumer anyway (When IsExclusive is true, there 52 // can be at most one call to either Then or ChainTo). 53 using CreatePromise = MozPromise<CreateResult, nsresult, 54 /* IsExclusive */ true>; 55 static RefPtr<CreatePromise> Create( 56 RefPtr<fs::data::FileSystemDataManager> aDataManager, 57 const fs::EntryId& aEntryId); 58 59 NS_DECL_ISUPPORTS_INHERITED 60 61 void Register(); 62 63 void Unregister(); 64 65 void RegisterActor(NotNull<FileSystemAccessHandleParent*> aActor); 66 67 void UnregisterActor(NotNull<FileSystemAccessHandleParent*> aActor); 68 69 void RegisterControlActor( 70 NotNull<FileSystemAccessHandleControlParent*> aControlActor); 71 72 void UnregisterControlActor( 73 NotNull<FileSystemAccessHandleControlParent*> aControlActor); 74 75 bool IsOpen() const; 76 77 RefPtr<BoolPromise> BeginClose(); 78 79 private: 80 FileSystemAccessHandle(RefPtr<fs::data::FileSystemDataManager> aDataManager, 81 const fs::EntryId& aEntryId, 82 MovingNotNull<RefPtr<TaskQueue>> aIOTaskQueue); 83 84 ~FileSystemAccessHandle(); 85 86 bool IsInactive() const; 87 88 using InitPromise = 89 MozPromise<mozilla::ipc::RandomAccessStreamParams, nsresult, 90 /* IsExclusive */ true>; 91 RefPtr<InitPromise> BeginInit(); 92 93 const fs::EntryId mEntryId; 94 RefPtr<fs::data::FileSystemDataManager> mDataManager; 95 const NotNull<RefPtr<TaskQueue>> mIOTaskQueue; 96 FileSystemAccessHandleParent* mActor; 97 FileSystemAccessHandleControlParent* mControlActor; 98 nsAutoRefCnt mRegCount; 99 bool mLocked; 100 bool mRegistered; 101 bool mClosed; 102 }; 103 104 } // namespace dom 105 } // namespace mozilla 106 107 #endif // DOM_FS_PARENT_FILESYSTEMACCESSHANDLE_H_