Bug 1749504 - Convert IndexedDB to use the new way to access a client directory; r=dom-storage-reviewers,jstutte

IndexedDB currently creates a client directory lock first and then when the
client directorylock is acquired, it bounces to the QuotaManager I/O thread
where it ensures that storage is initialized. This can be now replaced by just
calling QuotaManager::OpenClientDirectory.
The database maintenance can't use QuotaManager::OpenClientDirectory, a special
method will have to be added to QuotaManager for that.

Changes done in this patch:
- replaced QuotaManager::CreateDirectoryLock calls with
  QuotaManager::OpenClientDirectory calls
- removed QuotaManager::EnsureStorageIsInitializedInternal call from
  OpenDatabaseOp::DoDatabaseWork
- changed FactoryOp to not inherit from OpenDirectoryListener
- changed DeleteFilesRunnable to not inherit from OpenDirectoryListener

Differential Revision: https://phabricator.services.mozilla.com/D186120
This commit is contained in:
Jan Varga
2023-09-17 06:37:28 +00:00
parent a650db260b
commit 0935354d58

View File

@@ -2943,7 +2943,6 @@ class VersionChangeTransaction final
class FactoryOp
: public DatabaseOperationBase,
public OpenDirectoryListener,
public PBackgroundIDBFactoryRequestParent,
public SupportsCheckedUnsafePtr<CheckIf<DiagnosticAssertEnabled>> {
public:
@@ -3131,18 +3130,13 @@ class FactoryOp
// Should only be called by Run().
virtual void SendResults() = 0;
// We need to declare refcounting unconditionally, because
// OpenDirectoryListener has pure-virtual refcounting.
NS_DECL_ISUPPORTS_INHERITED
// Common nsIRunnable implementation that subclasses may not override.
NS_IMETHOD
Run() final;
// OpenDirectoryListener overrides.
void DirectoryLockAcquired(DirectoryLock* aLock) override;
void DirectoryLockAcquired(DirectoryLock* aLock);
void DirectoryLockFailed() override;
void DirectoryLockFailed();
// IPDL methods.
void ActorDestroy(ActorDestroyReason aWhy) override;
@@ -4830,8 +4824,7 @@ class QuotaClient final : public mozilla::dom::quota::Client {
void ProcessMaintenanceQueue();
};
class DeleteFilesRunnable final : public Runnable,
public OpenDirectoryListener {
class DeleteFilesRunnable final : public Runnable {
using DirectoryLock = mozilla::dom::quota::DirectoryLock;
enum State {
@@ -4878,13 +4871,11 @@ class DeleteFilesRunnable final : public Runnable,
void UnblockOpen();
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIRUNNABLE
// OpenDirectoryListener overrides.
virtual void DirectoryLockAcquired(DirectoryLock* aLock) override;
void DirectoryLockAcquired(DirectoryLock* aLock);
virtual void DirectoryLockFailed() override;
void DirectoryLockFailed();
};
class Maintenance final : public Runnable, public OpenDirectoryListener {
@@ -12724,12 +12715,21 @@ void DeleteFilesRunnable::Open() {
return;
}
RefPtr<DirectoryLock> directoryLock = quotaManager->CreateDirectoryLock(
{mFileManager->OriginMetadata(), quota::Client::IDB},
/* aExclusive */ false);
mState = State_DirectoryOpenPending;
directoryLock->Acquire(this);
quotaManager
->OpenClientDirectory(
{mFileManager->OriginMetadata(), quota::Client::IDB})
->Then(
GetCurrentSerialEventTarget(), __func__,
[self = RefPtr(this)](
const ClientDirectoryLockPromise::ResolveOrRejectValue& aValue) {
if (aValue.IsResolve()) {
self->DirectoryLockAcquired(aValue.ResolveValue());
} else {
self->DirectoryLockFailed();
}
});
}
void DeleteFilesRunnable::DoDatabaseWork() {
@@ -12766,8 +12766,6 @@ void DeleteFilesRunnable::UnblockOpen() {
mState = State_Completed;
}
NS_IMPL_ISUPPORTS_INHERITED0(DeleteFilesRunnable, Runnable)
NS_IMETHODIMP
DeleteFilesRunnable::Run() {
switch (mState) {
@@ -14953,13 +14951,19 @@ nsresult FactoryOp::FinishOpen() {
}()));
// Open directory
RefPtr<DirectoryLock> directoryLock =
quotaManager->CreateDirectoryLock({mOriginMetadata, Client::IDB},
/* aExclusive */ false);
mState = State::DirectoryOpenPending;
directoryLock->Acquire(this);
quotaManager->OpenClientDirectory({mOriginMetadata, Client::IDB})
->Then(
GetCurrentSerialEventTarget(), __func__,
[self = RefPtr(this)](
const ClientDirectoryLockPromise::ResolveOrRejectValue& aValue) {
if (aValue.IsResolve()) {
self->DirectoryLockAcquired(aValue.ResolveValue());
} else {
self->DirectoryLockFailed();
}
});
return NS_OK;
}
@@ -14975,8 +14979,6 @@ bool FactoryOp::MustWaitFor(const FactoryOp& aExistingOp) {
aExistingOp.mDatabaseId == mDatabaseId;
}
NS_IMPL_ISUPPORTS_INHERITED0(FactoryOp, DatabaseOperationBase)
// Run() assumes that the caller holds a strong reference to the object that
// can't be cleared while Run() is being executed.
// So if you call Run() directly (as opposed to dispatching to an event queue)
@@ -15136,8 +15138,6 @@ nsresult OpenDatabaseOp::DoDatabaseWork() {
QuotaManager* const quotaManager = QuotaManager::Get();
MOZ_ASSERT(quotaManager);
QM_TRY(MOZ_TO_RESULT(quotaManager->EnsureStorageIsInitializedInternal()));
QM_TRY_INSPECT(
const auto& dbDirectory,
([persistenceType, &quotaManager, this]()