diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index 5fdc72c4da35..8538578e8da5 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -3733,13 +3733,28 @@ nsresult QuotaManager::Init() { return NS_OK; } +// static +void QuotaManager::MaybeRecordQuotaClientShutdownStep( + const Client::Type aClientType, const nsACString& aStepDescription) { + // Callable on any thread. + + auto* const quotaManager = QuotaManager::Get(); + MOZ_DIAGNOSTIC_ASSERT(quotaManager); + + if (quotaManager->ShutdownStarted()) { + quotaManager->RecordShutdownStep(Some(aClientType), aStepDescription); + } +} + // static void QuotaManager::SafeMaybeRecordQuotaClientShutdownStep( const Client::Type aClientType, const nsACString& aStepDescription) { // Callable on any thread. - if (auto* const quotaManager = QuotaManager::Get()) { - quotaManager->MaybeRecordShutdownStep(Some(aClientType), aStepDescription); + auto* const quotaManager = QuotaManager::Get(); + + if (quotaManager && quotaManager->ShutdownStarted()) { + quotaManager->RecordShutdownStep(Some(aClientType), aStepDescription); } } @@ -3747,17 +3762,16 @@ void QuotaManager::MaybeRecordQuotaManagerShutdownStep( const nsACString& aStepDescription) { // Callable on any thread. - MaybeRecordShutdownStep(Nothing{}, aStepDescription); + if (ShutdownStarted()) { + RecordShutdownStep(Nothing{}, aStepDescription); + } } -void QuotaManager::MaybeRecordShutdownStep( - const Maybe aClientType, const nsACString& aStepDescription) { - if (!mShutdownStarted) { - // We are not shutting down yet, we intentionally ignore this here to avoid - // that every caller has to make a distinction for shutdown vs. non-shutdown - // situations. - return; - } +bool QuotaManager::ShutdownStarted() const { return mShutdownStarted; } + +void QuotaManager::RecordShutdownStep(const Maybe aClientType, + const nsACString& aStepDescription) { + MOZ_ASSERT(mShutdownStarted); const TimeDuration elapsedSinceShutdownStart = TimeStamp::NowLoRes() - *mShutdownStartedAt; diff --git a/dom/quota/QuotaManager.h b/dom/quota/QuotaManager.h index 0fd665df41fa..024950858dfb 100644 --- a/dom/quota/QuotaManager.h +++ b/dom/quota/QuotaManager.h @@ -374,13 +374,7 @@ class QuotaManager final : public BackgroundThreadObject { // Record a quota client shutdown step, if shutting down. // Assumes that the QuotaManager singleton is alive. static void MaybeRecordQuotaClientShutdownStep( - const Client::Type aClientType, const nsACString& aStepDescription) { - // Callable on any thread. - - MOZ_DIAGNOSTIC_ASSERT(QuotaManager::Get()); - QuotaManager::Get()->MaybeRecordShutdownStep(Some(aClientType), - aStepDescription); - } + const Client::Type aClientType, const nsACString& aStepDescription); // Record a quota client shutdown step, if shutting down. // Checks if the QuotaManager singleton is alive. @@ -553,8 +547,10 @@ class QuotaManager final : public BackgroundThreadObject { int64_t GenerateDirectoryLockId(); - void MaybeRecordShutdownStep(Maybe aClientType, - const nsACString& aStepDescription); + bool ShutdownStarted() const; + + void RecordShutdownStep(Maybe aClientType, + const nsACString& aStepDescription); template auto ExecuteInitialization(Initialization aInitialization, Func&& aFunc)