diff --git a/dom/serviceworkers/ServiceWorkerManager.cpp b/dom/serviceworkers/ServiceWorkerManager.cpp index 4dc18b191991..01c6393285df 100644 --- a/dom/serviceworkers/ServiceWorkerManager.cpp +++ b/dom/serviceworkers/ServiceWorkerManager.cpp @@ -2268,6 +2268,32 @@ int32_t ServiceWorkerManager::GetPrincipalQuotaUsageCheckCount( return data->mQuotaUsageCheckCount; } +void ServiceWorkerManager::CheckPrincipalQuotaUsage(nsIPrincipal* aPrincipal, + const nsACString& aScope) { + MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(aPrincipal); + + nsAutoCString scopeKey; + nsresult rv = PrincipalToScopeKey(aPrincipal, scopeKey); + if (NS_WARN_IF(NS_FAILED(rv))) { + return; + } + + RegistrationDataPerPrincipal* data; + if (!mRegistrationInfos.Get(scopeKey, &data)) { + return; + } + + // Had already schedule a quota usage check. + if (data->mQuotaUsageCheckCount != 0) { + return; + } + + ++data->mQuotaUsageCheckCount; + + // Perform quota usage checking here with QuotaManager in the following patch. +} + void ServiceWorkerManager::SoftUpdate(const OriginAttributes& aOriginAttributes, const nsACString& aScope) { MOZ_ASSERT(NS_IsMainThread()); diff --git a/dom/serviceworkers/ServiceWorkerManager.h b/dom/serviceworkers/ServiceWorkerManager.h index 8605b7714a1f..fe0cd14289f8 100644 --- a/dom/serviceworkers/ServiceWorkerManager.h +++ b/dom/serviceworkers/ServiceWorkerManager.h @@ -254,6 +254,9 @@ class ServiceWorkerManager final : public nsIServiceWorkerManager, int32_t GetPrincipalQuotaUsageCheckCount(nsIPrincipal* aPrincipal); + void CheckPrincipalQuotaUsage(nsIPrincipal* aPrincipal, + const nsACString& aScope); + // Returns the shutdown state ID (may be an invalid ID if an // nsIAsyncShutdownBlocker is not used). uint32_t MaybeInitServiceWorkerShutdownProgress() const; diff --git a/dom/serviceworkers/ServiceWorkerRegistrationInfo.cpp b/dom/serviceworkers/ServiceWorkerRegistrationInfo.cpp index 0177df1d298f..37af15ee7547 100644 --- a/dom/serviceworkers/ServiceWorkerRegistrationInfo.cpp +++ b/dom/serviceworkers/ServiceWorkerRegistrationInfo.cpp @@ -517,6 +517,7 @@ void ServiceWorkerRegistrationInfo::MaybeScheduleUpdate() { // Disable unregister mitigation when navigation fault threshold is 0. if (navigationFaultThreshold <= navigationFaultCount && navigationFaultThreshold != 0) { + CheckQuotaUsage(); swm->Unregister(mPrincipal, nullptr, NS_ConvertUTF8toUTF16(Scope())); return; } @@ -895,5 +896,14 @@ void ServiceWorkerRegistrationInfo::ForEachWorker( } } +void ServiceWorkerRegistrationInfo::CheckQuotaUsage() { + MOZ_ASSERT(NS_IsMainThread()); + + RefPtr swm = ServiceWorkerManager::GetInstance(); + MOZ_ASSERT(swm); + + swm->CheckPrincipalQuotaUsage(mPrincipal, Scope()); +} + } // namespace dom } // namespace mozilla diff --git a/dom/serviceworkers/ServiceWorkerRegistrationInfo.h b/dom/serviceworkers/ServiceWorkerRegistrationInfo.h index 4f31ced7186b..13ecf3edc75c 100644 --- a/dom/serviceworkers/ServiceWorkerRegistrationInfo.h +++ b/dom/serviceworkers/ServiceWorkerRegistrationInfo.h @@ -261,6 +261,8 @@ class ServiceWorkerRegistrationInfo final // call to `aFunc`, so `aFunc` will always get a reference to a non-null // pointer. void ForEachWorker(void (*aFunc)(RefPtr&)); + + void CheckQuotaUsage(); }; } // namespace dom