Bug 1671369 - Change GetUsageForClient to return a UsageInfo. r=dom-workers-and-storage-reviewers,ttung

Differential Revision: https://phabricator.services.mozilla.com/D93777
This commit is contained in:
Simon Giesecke
2020-11-17 13:17:24 +00:00
parent daa2316347
commit 39bbcf93e6
5 changed files with 32 additions and 41 deletions

View File

@@ -384,13 +384,8 @@ Result<UsageInfo, nsresult> CacheQuotaClient::GetUsageForOriginInternal(
}()));
if (!maybePaddingSize) {
uint64_t usage;
if (qm->GetUsageForClient(PERSISTENCE_TYPE_DEFAULT, aGroupAndOrigin,
Client::DOMCACHE, usage)) {
return UsageInfo{DatabaseUsageType(Some(usage))};
}
return UsageInfo{};
return qm->GetUsageForClient(PERSISTENCE_TYPE_DEFAULT, aGroupAndOrigin,
Client::DOMCACHE);
}
CACHE_TRY_INSPECT(

View File

@@ -7373,10 +7373,11 @@ nsresult PrepareDatastoreOp::DatabaseWork() {
return rv;
}
uint64_t usage;
bool hasUsage =
quotaManager->GetUsageForClient(PERSISTENCE_TYPE_DEFAULT, mQuotaInfo,
mozilla::dom::quota::Client::LS, usage);
const UsageInfo usageInfo = quotaManager->GetUsageForClient(
PERSISTENCE_TYPE_DEFAULT, mQuotaInfo, mozilla::dom::quota::Client::LS);
const bool hasUsage = usageInfo.DatabaseUsage().isSome();
MOZ_ASSERT(usageInfo.FileUsage().isNothing());
if (!gArchivedOrigins) {
rv = LoadArchivedOrigins();
@@ -7467,7 +7468,9 @@ nsresult PrepareDatastoreOp::DatabaseWork() {
if (alreadyExisted) {
// The database does exist.
MOZ_ASSERT(hasUsage);
mUsage = usage;
// XXX Change type of mUsage to UsageInfo or DatabaseUsageType.
mUsage = usageInfo.DatabaseUsage().value();
} else {
// The database doesn't exist.
MOZ_ASSERT(!hasUsage);
@@ -9107,14 +9110,8 @@ Result<UsageInfo, nsresult> QuotaClient::GetUsageForOrigin(
QuotaManager* quotaManager = QuotaManager::Get();
MOZ_ASSERT(quotaManager);
UsageInfo res;
uint64_t usage;
if (quotaManager->GetUsageForClient(PERSISTENCE_TYPE_DEFAULT, aGroupAndOrigin,
Client::LS, usage)) {
res += DatabaseUsageType(Some(usage));
}
return res;
return quotaManager->GetUsageForClient(PERSISTENCE_TYPE_DEFAULT,
aGroupAndOrigin, Client::LS);
}
nsresult QuotaClient::AboutToClearOrigins(

View File

@@ -1013,7 +1013,7 @@ class OriginInfo final {
void LockedResetUsageForClient(Client::Type aClientType);
bool LockedGetUsageForClient(Client::Type aClientType, uint64_t& aUsage);
UsageInfo LockedGetUsageForClient(Client::Type aClientType);
void LockedUpdateAccessTime(int64_t aAccessTime) {
AssertCurrentThreadOwnsQuotaMutex();
@@ -4247,10 +4247,9 @@ void QuotaManager::ResetUsageForClient(PersistenceType aPersistenceType,
}
}
bool QuotaManager::GetUsageForClient(PersistenceType aPersistenceType,
const GroupAndOrigin& aGroupAndOrigin,
Client::Type aClientType,
uint64_t& aUsage) {
UsageInfo QuotaManager::GetUsageForClient(PersistenceType aPersistenceType,
const GroupAndOrigin& aGroupAndOrigin,
Client::Type aClientType) {
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aPersistenceType != PERSISTENCE_TYPE_PERSISTENT);
@@ -4258,21 +4257,21 @@ bool QuotaManager::GetUsageForClient(PersistenceType aPersistenceType,
GroupInfoPair* pair;
if (!mGroupInfoPairs.Get(aGroupAndOrigin.mGroup, &pair)) {
return false;
return UsageInfo{};
}
RefPtr<GroupInfo> groupInfo = pair->LockedGetGroupInfo(aPersistenceType);
if (!groupInfo) {
return false;
return UsageInfo{};
}
RefPtr<OriginInfo> originInfo =
groupInfo->LockedGetOriginInfo(aGroupAndOrigin.mOrigin);
if (!originInfo) {
return false;
return UsageInfo{};
}
return originInfo->LockedGetUsageForClient(aClientType, aUsage);
return originInfo->LockedGetUsageForClient(aClientType);
}
void QuotaManager::UpdateOriginAccessTime(
@@ -7970,18 +7969,16 @@ void OriginInfo::LockedResetUsageForClient(Client::Type aClientType) {
quotaManager->mTemporaryStorageUsage -= size;
}
bool OriginInfo::LockedGetUsageForClient(Client::Type aClientType,
uint64_t& aUsage) {
UsageInfo OriginInfo::LockedGetUsageForClient(Client::Type aClientType) {
AssertCurrentThreadOwnsQuotaMutex();
Maybe<uint64_t>& clientUsage = mClientUsages[aClientType];
// The current implementation of this method only supports DOMCACHE and LS,
// which only use DatabaseUsage. If this assertion is lifted, the logic below
// must be adapted.
MOZ_ASSERT(aClientType == Client::Type::DOMCACHE ||
aClientType == Client::Type::LS);
if (clientUsage.isNothing()) {
return false;
}
aUsage = clientUsage.value();
return true;
return UsageInfo{DatabaseUsageType{mClientUsages[aClientType]}};
}
void OriginInfo::LockedPersist() {

View File

@@ -219,9 +219,9 @@ class QuotaManager final : public BackgroundThreadObject {
const GroupAndOrigin& aGroupAndOrigin,
Client::Type aClientType);
bool GetUsageForClient(PersistenceType aPersistenceType,
const GroupAndOrigin& aGroupAndOrigin,
Client::Type aClientType, uint64_t& aUsage);
UsageInfo GetUsageForClient(PersistenceType aPersistenceType,
const GroupAndOrigin& aGroupAndOrigin,
Client::Type aClientType);
void UpdateOriginAccessTime(PersistenceType aPersistenceType,
const GroupAndOrigin& aGroupAndOrigin);

View File

@@ -84,6 +84,8 @@ class UsageInfo final {
return *this;
}
Maybe<uint64_t> DatabaseUsage() const { return mDatabaseUsage.GetValue(); }
Maybe<uint64_t> FileUsage() const { return mFileUsage.GetValue(); }
Maybe<uint64_t> TotalUsage() const {