Bug 1798459 - Clean up FileSystemWritableFileStream construction code; r=dom-storage-reviewers,jari

Depends on D160905

Differential Revision: https://phabricator.services.mozilla.com/D160906
This commit is contained in:
Jan Varga 2022-11-09 17:15:28 +00:00
Родитель 0dca106ad5
Коммит d7ad1e23fa
3 изменённых файлов: 40 добавлений и 40 удалений

Просмотреть файл

@ -85,6 +85,25 @@ void FileSystemWritableFileStream::ClearActor() {
mActor = nullptr;
}
FileSystemWritableFileStream::FileSystemWritableFileStream(
nsIGlobalObject* aGlobal, RefPtr<FileSystemManager>& aManager,
RefPtr<FileSystemWritableFileStreamChild> aActor,
const fs::FileSystemEntryMetadata& aMetadata)
: WritableStream(aGlobal),
mManager(aManager),
mMetadata(aMetadata),
mActor(std::move(aActor)) {
LOG(("Created WritableFileStream %p for fd %p", this,
mActor->MutableFileDescPtr()));
mActor->SetStream(this);
}
FileSystemWritableFileStream::~FileSystemWritableFileStream() {
if (mActor) {
mActor->Close();
}
}
// https://streams.spec.whatwg.org/#writablestream-set-up
// * This is fallible because of OOM handling of JSAPI. See bug 1762233.
// * Consider extracting this as UnderlyingSinkAlgorithmsWrapper if more classes
@ -95,10 +114,10 @@ void FileSystemWritableFileStream::ClearActor() {
// check automatically detect this situation?
/* static */
MOZ_CAN_RUN_SCRIPT_BOUNDARY already_AddRefed<FileSystemWritableFileStream>
FileSystemWritableFileStream::MaybeCreate(
FileSystemWritableFileStream::Create(
nsIGlobalObject* aGlobal, RefPtr<FileSystemManager>& aManager,
const fs::FileSystemEntryMetadata& aMetadata,
RefPtr<FileSystemWritableFileStreamChild>& aActor) {
RefPtr<FileSystemWritableFileStreamChild> aActor,
const fs::FileSystemEntryMetadata& aMetadata) {
AutoJSAPI jsapi;
if (!jsapi.Init(aGlobal)) {
return nullptr;
@ -108,7 +127,8 @@ FileSystemWritableFileStream::MaybeCreate(
// Step 5. Perform ! InitializeWritableStream(stream).
// (Done by the constructor)
RefPtr<FileSystemWritableFileStream> stream =
new FileSystemWritableFileStream(aGlobal, aManager, aMetadata, aActor);
new FileSystemWritableFileStream(aGlobal, aManager, std::move(aActor),
aMetadata);
// Step 1 - 3
auto algorithms =
@ -135,19 +155,6 @@ FileSystemWritableFileStream::MaybeCreate(
return stream.forget();
}
FileSystemWritableFileStream::FileSystemWritableFileStream(
nsIGlobalObject* aGlobal, RefPtr<FileSystemManager>& aManager,
const fs::FileSystemEntryMetadata& aMetadata,
RefPtr<FileSystemWritableFileStreamChild>& aActor)
: WritableStream(aGlobal),
mManager(aManager),
mMetadata(aMetadata),
mActor(std::move(aActor)) {
LOG(("Created WritableFileStream %p for fd %p", this,
mActor->MutableFileDescPtr()));
mActor->SetStream(this);
}
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(FileSystemWritableFileStream,
WritableStream)
@ -465,12 +472,6 @@ already_AddRefed<Promise> FileSystemWritableFileStream::Close(
return promise.forget();
}
FileSystemWritableFileStream::~FileSystemWritableFileStream() {
if (mActor) {
mActor->Close();
}
}
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(
WritableFileStreamUnderlyingSinkAlgorithms, UnderlyingSinkAlgorithmsBase)
NS_IMPL_CYCLE_COLLECTION_INHERITED(WritableFileStreamUnderlyingSinkAlgorithms,

Просмотреть файл

@ -41,20 +41,15 @@ class Promise;
class FileSystemWritableFileStream final : public WritableStream {
public:
static already_AddRefed<FileSystemWritableFileStream> Create(
nsIGlobalObject* aGlobal, RefPtr<FileSystemManager>& aManager,
RefPtr<FileSystemWritableFileStreamChild> aActor,
const fs::FileSystemEntryMetadata& aMetadata);
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileSystemWritableFileStream,
WritableStream)
static already_AddRefed<FileSystemWritableFileStream> MaybeCreate(
nsIGlobalObject* aGlobal, RefPtr<FileSystemManager>& aManager,
const fs::FileSystemEntryMetadata& aMetadata,
RefPtr<FileSystemWritableFileStreamChild>& aActor);
FileSystemWritableFileStream(
nsIGlobalObject* aGlobal, RefPtr<FileSystemManager>& aManager,
const fs::FileSystemEntryMetadata& aMetadata,
RefPtr<FileSystemWritableFileStreamChild>& aActor);
void ClearActor();
// WebIDL Boilerplate
@ -81,10 +76,15 @@ class FileSystemWritableFileStream final : public WritableStream {
fs::FileSystemEntryMetadata mMetadata;
private:
nsresult WriteBlob(Blob* aBlob, uint64_t& aWritten);
FileSystemWritableFileStream(nsIGlobalObject* aGlobal,
RefPtr<FileSystemManager>& aManager,
RefPtr<FileSystemWritableFileStreamChild> aActor,
const fs::FileSystemEntryMetadata& aMetadata);
virtual ~FileSystemWritableFileStream();
nsresult WriteBlob(Blob* aBlob, uint64_t& aWritten);
RefPtr<FileSystemWritableFileStreamChild> mActor;
RefPtr<TaskQueue> mTaskQueue;
};

Просмотреть файл

@ -116,14 +116,13 @@ RefPtr<FileSystemWritableFileStream> MakeResolution(
nsIGlobalObject* aGlobal,
FileSystemGetWritableFileStreamResponse&& aResponse,
const RefPtr<FileSystemWritableFileStream>& /* aReturns */,
const FileSystemEntryMetadata& aFile, RefPtr<FileSystemManager>& aManager) {
RefPtr<FileSystemWritableFileStreamChild> actor =
static_cast<FileSystemWritableFileStreamChild*>(
aResponse.get_PFileSystemWritableFileStreamChild());
const FileSystemEntryMetadata& aMetadata,
RefPtr<FileSystemManager>& aManager) {
auto* const actor = static_cast<FileSystemWritableFileStreamChild*>(
aResponse.get_PFileSystemWritableFileStreamChild());
RefPtr<FileSystemWritableFileStream> result =
FileSystemWritableFileStream::MaybeCreate(aGlobal, aManager, aFile,
actor);
FileSystemWritableFileStream::Create(aGlobal, aManager, actor, aMetadata);
return result;
}