mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1803062 - Add a fallible way to create FileSystemSyncAccessHandle objects; r=dom-storage-reviewers,jari
This is a preparation for creating a task queue and a strong worker ref during FileSystemSyncAccessHandle construction. Differential Revision: https://phabricator.services.mozilla.com/D163562
This commit is contained in:
parent
787a36f1b3
commit
11bba396db
@ -98,6 +98,13 @@ FileSystemSyncAccessHandle::FileSystemSyncAccessHandle(
|
||||
mMetadata(aMetadata),
|
||||
mClosed(false) {
|
||||
LOG(("Created SyncAccessHandle %p for stream %p", this, mStream.get()));
|
||||
|
||||
// Connect with the actor directly in the constructor. This way the actor
|
||||
// can call `FileSystemSyncAccessHandle::ClearActor` when we call
|
||||
// `PFileSystemAccessHandleChild::Send__delete__` even when
|
||||
// FileSystemSyncAccessHandle::Create fails, in which case the not yet
|
||||
// fully constructed FileSystemSyncAccessHandle is being destroyed.
|
||||
mActor->SetAccessHandle(this);
|
||||
}
|
||||
|
||||
FileSystemSyncAccessHandle::~FileSystemSyncAccessHandle() {
|
||||
@ -105,6 +112,18 @@ FileSystemSyncAccessHandle::~FileSystemSyncAccessHandle() {
|
||||
MOZ_ASSERT(mClosed);
|
||||
}
|
||||
|
||||
// static
|
||||
Result<RefPtr<FileSystemSyncAccessHandle>, nsresult>
|
||||
FileSystemSyncAccessHandle::Create(
|
||||
nsIGlobalObject* aGlobal, RefPtr<FileSystemManager>& aManager,
|
||||
RefPtr<FileSystemAccessHandleChild> aActor,
|
||||
nsCOMPtr<nsIRandomAccessStream> aStream,
|
||||
const fs::FileSystemEntryMetadata& aMetadata) {
|
||||
RefPtr<FileSystemSyncAccessHandle> result = new FileSystemSyncAccessHandle(
|
||||
aGlobal, aManager, std::move(aActor), std::move(aStream), aMetadata);
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FileSystemSyncAccessHandle)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
|
@ -29,11 +29,11 @@ class Promise;
|
||||
class FileSystemSyncAccessHandle final : public nsISupports,
|
||||
public nsWrapperCache {
|
||||
public:
|
||||
FileSystemSyncAccessHandle(nsIGlobalObject* aGlobal,
|
||||
RefPtr<FileSystemManager>& aManager,
|
||||
RefPtr<FileSystemAccessHandleChild> aActor,
|
||||
nsCOMPtr<nsIRandomAccessStream> aStream,
|
||||
const fs::FileSystemEntryMetadata& aMetadata);
|
||||
static Result<RefPtr<FileSystemSyncAccessHandle>, nsresult> Create(
|
||||
nsIGlobalObject* aGlobal, RefPtr<FileSystemManager>& aManager,
|
||||
RefPtr<FileSystemAccessHandleChild> aActor,
|
||||
nsCOMPtr<nsIRandomAccessStream> aStream,
|
||||
const fs::FileSystemEntryMetadata& aMetadata);
|
||||
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(FileSystemSyncAccessHandle)
|
||||
@ -66,6 +66,12 @@ class FileSystemSyncAccessHandle final : public nsISupports,
|
||||
void Close();
|
||||
|
||||
private:
|
||||
FileSystemSyncAccessHandle(nsIGlobalObject* aGlobal,
|
||||
RefPtr<FileSystemManager>& aManager,
|
||||
RefPtr<FileSystemAccessHandleChild> aActor,
|
||||
nsCOMPtr<nsIRandomAccessStream> aStream,
|
||||
const fs::FileSystemEntryMetadata& aMetadata);
|
||||
|
||||
virtual ~FileSystemSyncAccessHandle();
|
||||
|
||||
uint64_t ReadOrWrite(
|
||||
|
@ -117,9 +117,16 @@ FileSystemWritableFileStream::FileSystemWritableFileStream(
|
||||
auto rawFD = aFileDescriptor.ClonePlatformHandle();
|
||||
mFileDesc = PR_ImportFile(PROsfd(rawFD.release()));
|
||||
|
||||
mozilla::HoldJSObjects(this);
|
||||
|
||||
LOG(("Created WritableFileStream %p for fd %p", this, mFileDesc));
|
||||
|
||||
// Connect with the actor directly in the constructor. This way the actor
|
||||
// can call `FileSystemWritableFileStream::ClearActor` when we call
|
||||
// `PFileSystemWritableFileStreamChild::Send__delete__` even when
|
||||
// FileSystemWritableFileStream::Create fails, in which case the not yet
|
||||
// fully constructed FileSystemWritableFileStream is being destroyed.
|
||||
mActor->SetStream(this);
|
||||
|
||||
mozilla::HoldJSObjects(this);
|
||||
}
|
||||
|
||||
FileSystemWritableFileStream::~FileSystemWritableFileStream() {
|
||||
|
@ -131,10 +131,10 @@ RefPtr<FileSystemSyncAccessHandle> MakeResolution(
|
||||
auto* const actor =
|
||||
static_cast<FileSystemAccessHandleChild*>(properties.accessHandleChild());
|
||||
|
||||
RefPtr<FileSystemSyncAccessHandle> result = new FileSystemSyncAccessHandle(
|
||||
aGlobal, aManager, actor, std::move(stream), aMetadata);
|
||||
|
||||
actor->SetAccessHandle(result);
|
||||
QM_TRY_UNWRAP(RefPtr<FileSystemSyncAccessHandle> result,
|
||||
FileSystemSyncAccessHandle::Create(
|
||||
aGlobal, aManager, actor, std::move(stream), aMetadata),
|
||||
nullptr);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -155,10 +155,6 @@ RefPtr<FileSystemWritableFileStream> MakeResolution(
|
||||
FileSystemWritableFileStream::Create(
|
||||
aGlobal, aManager, actor, properties.fileDescriptor(), aMetadata);
|
||||
|
||||
if (result) {
|
||||
actor->SetStream(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user