mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 23:02:20 +00:00
Bug 1803062 - Don't call FileSystemSyncAccessHandle::Close when the object is already closed; r=dom-storage-reviewers,jesup
The Close method will return a MozPromise. Calling such method if the object is already closed would uselessly allocate a MozPromise and dispatch a runnable for the MozPromise resolving. So it's better to call Close only if the object is not yet closed. Differential Revision: https://phabricator.services.mozilla.com/D163564
This commit is contained in:
parent
3042af06bf
commit
d5251f60a7
@ -134,9 +134,12 @@ FileSystemSyncAccessHandle::Create(
|
||||
|
||||
workerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
RefPtr<StrongWorkerRef> workerRef =
|
||||
StrongWorkerRef::Create(workerPrivate, "FileSystemSyncAccessHandle",
|
||||
[result]() { result->CloseInternal(); });
|
||||
RefPtr<StrongWorkerRef> workerRef = StrongWorkerRef::Create(
|
||||
workerPrivate, "FileSystemSyncAccessHandle", [result]() {
|
||||
if (!result->IsClosed()) {
|
||||
result->CloseInternal();
|
||||
}
|
||||
});
|
||||
QM_TRY(MOZ_TO_RESULT(workerRef));
|
||||
|
||||
autoClose.release();
|
||||
@ -160,7 +163,9 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(FileSystemSyncAccessHandle)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal)
|
||||
// Don't unlink mManager!
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
||||
tmp->CloseInternal();
|
||||
if (!tmp->IsClosed()) {
|
||||
tmp->CloseInternal();
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(FileSystemSyncAccessHandle)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal)
|
||||
@ -189,9 +194,7 @@ void FileSystemSyncAccessHandle::ClearActor() {
|
||||
}
|
||||
|
||||
void FileSystemSyncAccessHandle::CloseInternal() {
|
||||
if (mClosed) {
|
||||
return;
|
||||
}
|
||||
MOZ_ASSERT(!mClosed);
|
||||
|
||||
LOG(("%p: Closing", mStream.get()));
|
||||
|
||||
@ -284,7 +287,11 @@ void FileSystemSyncAccessHandle::Flush(ErrorResult& aError) {
|
||||
mStream->OutputStream()->Flush();
|
||||
}
|
||||
|
||||
void FileSystemSyncAccessHandle::Close() { CloseInternal(); }
|
||||
void FileSystemSyncAccessHandle::Close() {
|
||||
if (!IsClosed()) {
|
||||
CloseInternal();
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t FileSystemSyncAccessHandle::ReadOrWrite(
|
||||
const MaybeSharedArrayBufferViewOrMaybeSharedArrayBuffer& aBuffer,
|
||||
|
@ -43,6 +43,8 @@ class FileSystemSyncAccessHandle final : public nsISupports,
|
||||
|
||||
void ClearActor();
|
||||
|
||||
bool IsClosed() const { return mClosed; }
|
||||
|
||||
void CloseInternal();
|
||||
|
||||
// WebIDL Boilerplate
|
||||
|
@ -20,8 +20,11 @@ void FileSystemManagerChild::CloseAll() {
|
||||
|
||||
for (const auto& item : ManagedPFileSystemAccessHandleChild()) {
|
||||
auto* child = static_cast<FileSystemAccessHandleChild*>(item);
|
||||
auto* handle = child->MutableAccessHandlePtr();
|
||||
|
||||
child->MutableAccessHandlePtr()->CloseInternal();
|
||||
if (!handle->IsClosed()) {
|
||||
handle->CloseInternal();
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& item : ManagedPFileSystemWritableFileStreamChild()) {
|
||||
|
Loading…
Reference in New Issue
Block a user