/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* * QuotaUsageChecker implements the quota usage checking algorithm. * * 1. Getting the given origin/group usage through QuotaManagerService. * QuotaUsageCheck::Start() implements this step. * 2. Checking if the group usage headroom is satisfied. * It could be following three situations. * a. Group headroom is satisfied without any usage mitigation. * b. Group headroom is satisfied after origin usage mitigation. * This invokes nsIClearDataService::DeleteDataFromPrincipal(). * c. Group headroom is satisfied after group usage mitigation. * This invokes nsIClearDataService::DeleteDataFromSite(). * QuotaUsageChecker::CheckQuotaHeadroom() implements this step. * * If the algorithm is done or error out, the QuotaUsageCheck::mCallback will * be called with a bool result for external handling.
*/ class QuotaUsageChecker final : public nsIQuotaCallback, public nsIQuotaUsageCallback, public nsIClearDataCallback { public:
NS_DECL_ISUPPORTS // For QuotaManagerService::Estimate()
NS_DECL_NSIQUOTACALLBACK
// For QuotaManagerService::GetUsageForPrincipal()
NS_DECL_NSIQUOTAUSAGECALLBACK
// For nsIClearDataService::DeleteDataFromPrincipal() and // nsIClearDataService::DeleteDataFromSite()
NS_DECL_NSICLEARDATACALLBACK
// This is a general help method to get nsIQuotaResult/nsIQuotaUsageResult // from nsIQuotaRequest/nsIQuotaUsageRequest template <typename T, typename U>
nsresult GetResult(T* aRequest, U&);
void CheckQuotaHeadroom();
nsCOMPtr<nsIPrincipal> mPrincipal;
// The external callback. Calling RunCallback(bool) instead of calling it // directly, RunCallback(bool) handles the internal status.
ServiceWorkerQuotaMitigationCallback mCallback; bool mGettingOriginUsageDone; bool mGettingGroupUsageDone; bool mIsChecking;
uint64_t mOriginUsage;
uint64_t mGroupUsage;
uint64_t mGroupLimit;
};
// Group usage headroom is not satisfied even removing the origin usage, // clear all group usage. if ((groupAvailable + mOriginUsage) < groupHeadroom) {
nsAutoCString baseDomain;
nsresult rv = mPrincipal->GetBaseDomain(baseDomain); if (NS_WARN_IF(NS_FAILED(rv))) { return;
}
rv = csd->DeleteDataFromSiteAndOriginAttributesPatternString(
baseDomain, u""_ns, false, nsIClearDataService::CLEAR_DOM_QUOTA, this); if (NS_WARN_IF(NS_FAILED(rv))) { return;
}
// clear the origin usage since it makes group usage headroom be satisifed.
} else {
nsresult rv = csd->DeleteDataFromPrincipal(
mPrincipal, false, nsIClearDataService::CLEAR_DOM_QUOTA, this); if (NS_WARN_IF(NS_FAILED(rv))) { return;
}
}
// Call CheckQuotaHeadroom() when both // QuotaManagerService::GetUsageForPrincipal() and // QuotaManagerService::Estimate() are done. if (mGettingOriginUsageDone && mGettingGroupUsageDone) {
CheckQuotaHeadroom();
} return NS_OK;
}
// Call CheckQuotaHeadroom() when both // QuotaManagerService::GetUsageForPrincipal() and // QuotaManagerService::Estimate() are done. if (mGettingOriginUsageDone && mGettingGroupUsageDone) {
CheckQuotaHeadroom();
} return NS_OK;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.