Bug 1857155 - Remove custom ResolveCallback for FileSystemGetWritableFileStreamResponse; r=dom-storage-reviewers,jari

Differential Revision: https://phabricator.services.mozilla.com/D190181
This commit is contained in:
Jan Varga 2023-10-09 21:42:27 +00:00
Родитель 7187317ce3
Коммит a50349fed6
3 изменённых файлов: 28 добавлений и 48 удалений

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

@ -214,7 +214,7 @@ FileSystemWritableFileStream::FileSystemWritableFileStream(
mozilla::ipc::RandomAccessStreamParams&& aStreamParams,
RefPtr<FileSystemWritableFileStreamChild> aActor,
already_AddRefed<TaskQueue> aTaskQueue,
fs::FileSystemEntryMetadata&& aMetadata)
const fs::FileSystemEntryMetadata& aMetadata)
: WritableStream(aGlobal, HoldDropJSObjectsCaller::Explicit),
mManager(aManager),
mActor(std::move(aActor)),
@ -256,7 +256,7 @@ FileSystemWritableFileStream::Create(
RefPtr<FileSystemManager>& aManager,
mozilla::ipc::RandomAccessStreamParams&& aStreamParams,
RefPtr<FileSystemWritableFileStreamChild> aActor,
fs::FileSystemEntryMetadata&& aMetadata) {
const fs::FileSystemEntryMetadata& aMetadata) {
MOZ_ASSERT(aGlobal);
QM_TRY_UNWRAP(auto streamTransportService,
@ -279,7 +279,7 @@ FileSystemWritableFileStream::Create(
RefPtr<FileSystemWritableFileStream> stream =
new FileSystemWritableFileStream(
aGlobal, aManager, std::move(aStreamParams), std::move(aActor),
taskQueue.forget(), std::move(aMetadata));
taskQueue.forget(), aMetadata);
auto autoClose = MakeScopeExit([stream] {
stream->mCloseHandler->Close();

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

@ -52,7 +52,7 @@ class FileSystemWritableFileStream final : public WritableStream {
RefPtr<FileSystemManager>& aManager,
mozilla::ipc::RandomAccessStreamParams&& aStreamParams,
RefPtr<FileSystemWritableFileStreamChild> aActor,
fs::FileSystemEntryMetadata&& aMetadata);
const fs::FileSystemEntryMetadata& aMetadata);
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileSystemWritableFileStream,
@ -106,7 +106,7 @@ class FileSystemWritableFileStream final : public WritableStream {
mozilla::ipc::RandomAccessStreamParams&& aStreamParams,
RefPtr<FileSystemWritableFileStreamChild> aActor,
already_AddRefed<TaskQueue> aTaskQueue,
fs::FileSystemEntryMetadata&& aMetadata);
const fs::FileSystemEntryMetadata& aMetadata);
virtual ~FileSystemWritableFileStream();

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

@ -141,6 +141,26 @@ RefPtr<FileSystemSyncAccessHandle> MakeResolution(
return result;
}
RefPtr<FileSystemWritableFileStream> MakeResolution(
nsIGlobalObject* aGlobal,
FileSystemGetWritableFileStreamResponse&& aResponse,
const RefPtr<FileSystemWritableFileStream>& /* aReturns */,
const FileSystemEntryMetadata& aMetadata,
RefPtr<FileSystemManager>& aManager) {
auto& properties = aResponse.get_FileSystemWritableFileStreamProperties();
auto* const actor = static_cast<FileSystemWritableFileStreamChild*>(
properties.writableFileStream().AsChild().get());
QM_TRY_UNWRAP(RefPtr<FileSystemWritableFileStream> result,
FileSystemWritableFileStream::Create(
aGlobal, aManager, std::move(properties.streamParams()),
actor, aMetadata),
nullptr);
return result;
}
RefPtr<File> MakeResolution(nsIGlobalObject* aGlobal,
FileSystemGetFileResponse&& aResponse,
const RefPtr<File>& /* aResult */,
@ -239,47 +259,6 @@ void ResolveCallback(FileSystemResolveResponse&& aResponse,
aPromise->MaybeResolve(JS::NullHandleValue);
}
// NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name)
template <>
void ResolveCallback(FileSystemGetWritableFileStreamResponse&& aResponse,
// NOLINTNEXTLINE(performance-unnecessary-value-param)
RefPtr<Promise> aPromise,
RefPtr<FileSystemManager>& aManager,
const FileSystemEntryMetadata& aMetadata) {
MOZ_ASSERT(aPromise);
QM_TRY(OkIf(Promise::PromiseState::Pending == aPromise->State()), QM_VOID);
if (FileSystemGetWritableFileStreamResponse::Tnsresult == aResponse.type()) {
HandleFailedStatus(aResponse.get_nsresult(), aPromise);
return;
}
auto& properties = aResponse.get_FileSystemWritableFileStreamProperties();
auto* const actor = static_cast<FileSystemWritableFileStreamChild*>(
properties.writableFileStream().AsChild().get());
auto autoDelete = MakeScopeExit([actor = RefPtr(actor)] {
PFileSystemWritableFileStreamChild::Send__delete__(actor);
});
mozilla::ipc::RandomAccessStreamParams params =
std::move(properties.streamParams());
FileSystemEntryMetadata metadata = aMetadata;
autoDelete.release();
QM_TRY_UNWRAP(
RefPtr<FileSystemWritableFileStream> stream,
FileSystemWritableFileStream::Create(aPromise->GetParentObject(),
aManager, std::move(params), actor,
std::move(metadata)),
[aPromise](const nsresult rv) { HandleFailedStatus(rv, aPromise); });
aPromise->MaybeResolve(stream);
}
template <class TResponse, class TReturns, class... Args,
std::enable_if_t<std::is_same<TReturns, void>::value, bool> = true>
mozilla::ipc::ResolveCallback<TResponse> SelectResolveCallback(
@ -474,8 +453,9 @@ void FileSystemRequestHandler::GetWritable(RefPtr<FileSystemManager>& aManager,
aManager->BeginRequest(
[request = FileSystemGetWritableRequest(aFile.entryId(), aKeepData),
onResolve =
SelectResolveCallback<FileSystemGetWritableFileStreamResponse, void>(
aPromise, aManager, aFile),
SelectResolveCallback<FileSystemGetWritableFileStreamResponse,
RefPtr<FileSystemWritableFileStream>>(
aPromise, aFile, aManager),
onReject = GetRejectCallback(aPromise)](const auto& actor) mutable {
actor->SendGetWritable(request, std::move(onResolve),
std::move(onReject));