Bug 1903874 - Change DirectoryLock::Drop to be asynchronous; r=dom-storage-reviewers,jari

For now, asynchronous Drop is only needed for replacing counting of pending
clear/shutdown storage operations with evaluation of existing directory locks.
In future, asynchronous Drop will also allow to do IO, for example if we decide
to wait for saving of origin access time to be finished.

Differential Revision: https://phabricator.services.mozilla.com/D197298
This commit is contained in:
Jan Varga 2024-06-23 08:27:58 +00:00
parent 2dee63ed3c
commit da0de838c2
4 changed files with 25 additions and 8 deletions

View File

@ -46,7 +46,7 @@ class NS_NO_VTABLE DirectoryLock {
virtual void AssertIsAcquiredExclusively() = 0;
virtual void Drop() = 0;
virtual RefPtr<BoolPromise> Drop() = 0;
virtual void OnInvalidate(std::function<void()>&& aCallback) = 0;

View File

@ -295,15 +295,20 @@ void DirectoryLockImpl::AssertIsAcquiredExclusively() {
}
#endif
void DirectoryLockImpl::Drop() {
RefPtr<BoolPromise> DirectoryLockImpl::Drop() {
AssertIsOnOwningThread();
MOZ_ASSERT_IF(!mRegistered, mBlocking.IsEmpty());
mDropped.Flip();
if (mRegistered) {
Unregister();
}
return InvokeAsync(GetCurrentSerialEventTarget(), __func__,
[self = RefPtr(this)]() {
if (self->mRegistered) {
self->Unregister();
}
return BoolPromise::CreateAndResolve(true, __func__);
});
}
void DirectoryLockImpl::OnInvalidate(std::function<void()>&& aCallback) {

View File

@ -202,7 +202,7 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
}
#endif
void Drop() override;
RefPtr<BoolPromise> Drop() override;
void OnInvalidate(std::function<void()>&& aCallback) override;

View File

@ -19,7 +19,7 @@ class DOM_Quota_DirectoryLock : public QuotaManagerDependencyFixture {
static void TearDownTestCase() { ASSERT_NO_FATAL_FAILURE(ShutdownFixture()); }
};
// Test that Drop unregisters directory lock synchronously.
// Test that Drop unregisters directory lock asynchronously.
TEST_F(DOM_Quota_DirectoryLock, Drop_Timing) {
PerformOnBackgroundThread([]() {
QuotaManager* quotaManager = QuotaManager::Get();
@ -41,7 +41,7 @@ TEST_F(DOM_Quota_DirectoryLock, Drop_Timing) {
SpinEventLoopUntil("Promise is fulfilled"_ns, [&done]() { return done; });
exclusiveDirectoryLock->Drop();
auto exclusiveDirectoryLockDropPromise = exclusiveDirectoryLock->Drop();
exclusiveDirectoryLock = nullptr;
RefPtr<UniversalDirectoryLock> sharedDirectoryLock =
@ -50,6 +50,18 @@ TEST_F(DOM_Quota_DirectoryLock, Drop_Timing) {
OriginScope::FromNull(), Nullable<Client::Type>(),
/* aExclusive */ false, DirectoryLockCategory::None);
ASSERT_TRUE(sharedDirectoryLock->MustWait());
done = false;
exclusiveDirectoryLockDropPromise->Then(
GetCurrentSerialEventTarget(), __func__,
[&done](const BoolPromise::ResolveOrRejectValue& aValue) {
done = true;
});
SpinEventLoopUntil("Promise is fulfilled"_ns, [&done]() { return done; });
ASSERT_FALSE(sharedDirectoryLock->MustWait());
sharedDirectoryLock = nullptr;