diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/filehandle/ActorsParent.h | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/filehandle/ActorsParent.h')
-rw-r--r-- | dom/filehandle/ActorsParent.h | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/dom/filehandle/ActorsParent.h b/dom/filehandle/ActorsParent.h new file mode 100644 index 0000000000..c42cab34e0 --- /dev/null +++ b/dom/filehandle/ActorsParent.h @@ -0,0 +1,174 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_filehandle_ActorsParent_h +#define mozilla_dom_filehandle_ActorsParent_h + +#include "mozilla/dom/FileHandleStorage.h" +#include "mozilla/dom/PBackgroundMutableFileParent.h" +#include "mozilla/ipc/BackgroundParent.h" +#include "mozilla/UniquePtr.h" +#include "nsClassHashtable.h" +#include "nsCOMPtr.h" +#include "nsHashKeys.h" +#include "nsString.h" +#include "nsTArrayForwardDeclare.h" +#include "nsTHashtable.h" + +template <class> +struct already_AddRefed; +class nsIFile; +class nsIRunnable; +class nsIThreadPool; + +namespace mozilla { + +namespace ipc { + +class PBackgroundParent; + +} // namespace ipc + +namespace dom { + +class BlobImpl; +class FileHandle; +class FileHandleOp; + +class FileHandleThreadPool final { + class FileHandleQueue; + struct DelayedEnqueueInfo; + class DirectoryInfo; + struct StoragesCompleteCallback; + + nsCOMPtr<nsIThreadPool> mThreadPool; + nsCOMPtr<nsIEventTarget> mOwningEventTarget; + + nsClassHashtable<nsCStringHashKey, DirectoryInfo> mDirectoryInfos; + + nsTArray<UniquePtr<StoragesCompleteCallback>> mCompleteCallbacks; + + bool mShutdownRequested; + bool mShutdownComplete; + + public: + static already_AddRefed<FileHandleThreadPool> Create(); + +#ifdef DEBUG + void AssertIsOnOwningThread() const; + + nsIEventTarget* GetThreadPoolEventTarget() const; +#else + void AssertIsOnOwningThread() const {} +#endif + + void Enqueue(FileHandle* aFileHandle, FileHandleOp* aFileHandleOp, + bool aFinish); + + NS_INLINE_DECL_REFCOUNTING(FileHandleThreadPool) + + void WaitForDirectoriesToComplete(nsTArray<nsCString>&& aDirectoryIds, + nsIRunnable* aCallback); + + void Shutdown(); + + private: + FileHandleThreadPool(); + + // Reference counted. + ~FileHandleThreadPool(); + + nsresult Init(); + + void Cleanup(); + + void FinishFileHandle(FileHandle* aFileHandle); + + bool MaybeFireCallback(StoragesCompleteCallback* aCallback); +}; + +class BackgroundMutableFileParentBase : public PBackgroundMutableFileParent { + friend PBackgroundMutableFileParent; + + nsTHashtable<nsPtrHashKey<FileHandle>> mFileHandles; + nsCString mDirectoryId; + nsString mFileName; + FileHandleStorage mStorage; + bool mInvalidated; + bool mActorWasAlive; + bool mActorDestroyed; + + protected: + nsCOMPtr<nsIFile> mFile; + + public: + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BackgroundMutableFileParentBase) + + void Invalidate(); + + FileHandleStorage Storage() const { return mStorage; } + + const nsCString& DirectoryId() const { return mDirectoryId; } + + const nsString& FileName() const { return mFileName; } + + bool RegisterFileHandle(FileHandle* aFileHandle); + + void UnregisterFileHandle(FileHandle* aFileHandle); + + void SetActorAlive(); + + bool IsActorDestroyed() const { + mozilla::ipc::AssertIsOnBackgroundThread(); + + return mActorWasAlive && mActorDestroyed; + } + + bool IsInvalidated() const { + mozilla::ipc::AssertIsOnBackgroundThread(); + + return mInvalidated; + } + + virtual void NoteActiveState() {} + + virtual void NoteInactiveState() {} + + virtual mozilla::ipc::PBackgroundParent* GetBackgroundParent() const = 0; + + virtual already_AddRefed<nsISupports> CreateStream(bool aReadOnly); + + virtual already_AddRefed<BlobImpl> CreateBlobImpl() { return nullptr; } + + protected: + BackgroundMutableFileParentBase(FileHandleStorage aStorage, + const nsACString& aDirectoryId, + const nsAString& aFileName, nsIFile* aFile); + + // Reference counted. + ~BackgroundMutableFileParentBase(); + + // IPDL methods are only called by IPDL. + virtual void ActorDestroy(ActorDestroyReason aWhy) override; + + virtual PBackgroundFileHandleParent* AllocPBackgroundFileHandleParent( + const FileMode& aMode); + + virtual mozilla::ipc::IPCResult RecvPBackgroundFileHandleConstructor( + PBackgroundFileHandleParent* aActor, const FileMode& aMode) override; + + virtual bool DeallocPBackgroundFileHandleParent( + PBackgroundFileHandleParent* aActor); + + mozilla::ipc::IPCResult RecvDeleteMe(); + + virtual mozilla::ipc::IPCResult RecvGetFileId(int64_t* aFileId); +}; + +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_filehandle_ActorsParent_h |