diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/fs/api/FileSystemWritableFileStream.h | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/fs/api/FileSystemWritableFileStream.h')
-rw-r--r-- | dom/fs/api/FileSystemWritableFileStream.h | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/dom/fs/api/FileSystemWritableFileStream.h b/dom/fs/api/FileSystemWritableFileStream.h new file mode 100644 index 0000000000..e681840962 --- /dev/null +++ b/dom/fs/api/FileSystemWritableFileStream.h @@ -0,0 +1,158 @@ +/* -*- 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 DOM_FS_FILESYSTEMWRITABLEFILESTREAM_H_ +#define DOM_FS_FILESYSTEMWRITABLEFILESTREAM_H_ + +#include "mozilla/AlreadyAddRefed.h" +#include "mozilla/MozPromise.h" +#include "mozilla/dom/FlippedOnce.h" +#include "mozilla/dom/PFileSystemManager.h" +#include "mozilla/dom/WritableStream.h" +#include "mozilla/dom/quota/ForwardDecls.h" + +class nsIGlobalObject; +class nsIRandomAccessStream; + +namespace mozilla { + +template <typename T> +class Buffer; +class ErrorResult; +class TaskQueue; + +namespace ipc { +class RandomAccessStreamParams; +} + +namespace dom { + +class ArrayBufferViewOrArrayBufferOrBlobOrUTF8StringOrWriteParams; +class Blob; +class FileSystemManager; +class FileSystemWritableFileStreamChild; +class OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString; +class Promise; +class StrongWorkerRef; + +namespace fs { +class FileSystemThreadSafeStreamOwner; +} + +class FileSystemWritableFileStream final : public WritableStream { + public: + using WriteDataPromise = + MozPromise<Maybe<int64_t>, CopyableErrorResult, /* IsExclusive */ true>; + + static Result<RefPtr<FileSystemWritableFileStream>, nsresult> Create( + const nsCOMPtr<nsIGlobalObject>& aGlobal, + RefPtr<FileSystemManager>& aManager, + mozilla::ipc::RandomAccessStreamParams&& aStreamParams, + RefPtr<FileSystemWritableFileStreamChild> aActor, + const fs::FileSystemEntryMetadata& aMetadata); + + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileSystemWritableFileStream, + WritableStream) + + void LastRelease() override; + + void ClearActor(); + + class Command; + RefPtr<Command> CreateCommand(); + + bool IsCommandActive() const; + + bool IsOpen() const; + + bool IsFinishing() const; + + bool IsDone() const; + + [[nodiscard]] RefPtr<BoolPromise> BeginAbort(); + + [[nodiscard]] RefPtr<BoolPromise> BeginClose(); + + [[nodiscard]] RefPtr<BoolPromise> OnDone(); + + already_AddRefed<Promise> Write(JSContext* aCx, JS::Handle<JS::Value> aChunk, + ErrorResult& aError); + + // WebIDL Boilerplate + JSObject* WrapObject(JSContext* aCx, + JS::Handle<JSObject*> aGivenProto) override; + + // WebIDL Interface + MOZ_CAN_RUN_SCRIPT already_AddRefed<Promise> Write( + const ArrayBufferViewOrArrayBufferOrBlobOrUTF8StringOrWriteParams& aData, + ErrorResult& aError); + + MOZ_CAN_RUN_SCRIPT already_AddRefed<Promise> Seek(uint64_t aPosition, + ErrorResult& aError); + + MOZ_CAN_RUN_SCRIPT already_AddRefed<Promise> Truncate(uint64_t aSize, + ErrorResult& aError); + + private: + class CloseHandler; + + FileSystemWritableFileStream( + const nsCOMPtr<nsIGlobalObject>& aGlobal, + RefPtr<FileSystemManager>& aManager, + mozilla::ipc::RandomAccessStreamParams&& aStreamParams, + RefPtr<FileSystemWritableFileStreamChild> aActor, + already_AddRefed<TaskQueue> aTaskQueue, + const fs::FileSystemEntryMetadata& aMetadata); + + virtual ~FileSystemWritableFileStream(); + + [[nodiscard]] RefPtr<BoolPromise> BeginFinishing(bool aShouldAbort); + + RefPtr<WriteDataPromise> Write( + ArrayBufferViewOrArrayBufferOrBlobOrUTF8StringOrWriteParams& aData); + + template <typename T> + RefPtr<Int64Promise> Write(const T& aData, const Maybe<uint64_t> aPosition); + + RefPtr<Int64Promise> WriteImpl(nsCOMPtr<nsIInputStream> aInputStream, + const Maybe<uint64_t> aPosition); + + RefPtr<BoolPromise> Seek(uint64_t aPosition); + + RefPtr<BoolPromise> Truncate(uint64_t aSize); + + nsresult EnsureStream(); + + void NoteFinishedCommand(); + + [[nodiscard]] RefPtr<BoolPromise> Finish(); + + RefPtr<FileSystemManager> mManager; + + RefPtr<FileSystemWritableFileStreamChild> mActor; + + RefPtr<TaskQueue> mTaskQueue; + + RefPtr<fs::FileSystemThreadSafeStreamOwner> mStreamOwner; + + RefPtr<StrongWorkerRef> mWorkerRef; + + mozilla::ipc::RandomAccessStreamParams mStreamParams; + + fs::FileSystemEntryMetadata mMetadata; + + RefPtr<CloseHandler> mCloseHandler; + + MozPromiseHolder<BoolPromise> mFinishPromiseHolder; + + bool mCommandActive; +}; + +} // namespace dom +} // namespace mozilla + +#endif // DOM_FS_FILESYSTEMWRITABLEFILESTREAM_H_ |