Bug 1734151 - Move the shutdown started check into public methods for shutdown step recording; r=hxu

This will allow to add a method like MaybeRecordQuotaManagerShutdownStepWith
which will take a function for generating the string.

Differential Revision: https://phabricator.services.mozilla.com/D127545
This commit is contained in:
Jan Varga 2021-10-12 12:29:42 +00:00
Родитель 9eb751c548
Коммит 53d543c18f
2 изменённых файлов: 30 добавлений и 20 удалений

Просмотреть файл

@ -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<Client::Type> 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<Client::Type> aClientType,
const nsACString& aStepDescription) {
MOZ_ASSERT(mShutdownStarted);
const TimeDuration elapsedSinceShutdownStart =
TimeStamp::NowLoRes() - *mShutdownStartedAt;

Просмотреть файл

@ -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,7 +547,9 @@ class QuotaManager final : public BackgroundThreadObject {
int64_t GenerateDirectoryLockId();
void MaybeRecordShutdownStep(Maybe<Client::Type> aClientType,
bool ShutdownStarted() const;
void RecordShutdownStep(Maybe<Client::Type> aClientType,
const nsACString& aStepDescription);
template <typename Func>