Bug 1697115 - Rationalize QuotaManager::DecreaseUsageForClient arguments; r=dom-storage-reviewers,sg

Note that the method DecreaseUsageForOrigin has been renamed to
DecreaseUsageForClient.

Differential Revision: https://phabricator.services.mozilla.com/D107615
This commit is contained in:
Jan Varga 2021-03-17 06:56:39 +00:00
parent de33fe2cf6
commit b59182de8d
8 changed files with 27 additions and 17 deletions

View File

@ -533,8 +533,8 @@ void DecreaseUsageForQuotaInfo(const QuotaInfo& aQuotaInfo,
QuotaManager* quotaManager = QuotaManager::Get();
MOZ_DIAGNOSTIC_ASSERT(quotaManager);
quotaManager->DecreaseUsageForOrigin(PERSISTENCE_TYPE_DEFAULT, aQuotaInfo,
Client::DOMCACHE, aUpdatingSize);
quotaManager->DecreaseUsageForClient(
quota::ClientMetadata{aQuotaInfo, Client::DOMCACHE}, aUpdatingSize);
}
bool DirectoryPaddingFileExists(nsIFile& aBaseDir,

1
dom/cache/Types.h vendored
View File

@ -30,6 +30,7 @@ typedef int64_t CacheId;
static const CacheId INVALID_CACHE_ID = -1;
// XXX Rename to OriginMetadata.
// XXX Consider inheritance from ClientMetadata.
struct QuotaInfo : quota::OriginMetadata {
nsCOMPtr<nsIFile> mDir;
int64_t mDirectoryLockId = -1;

View File

@ -2195,6 +2195,7 @@ class Database final
RefPtr<DatabaseConnection> mConnection;
const PrincipalInfo mPrincipalInfo;
const Maybe<ContentParentId> mOptionalContentParentId;
// XXX Consider changing this to ClientMetadata.
const quota::OriginMetadata mOriginMetadata;
const nsCString mId;
const nsString mFilePath;
@ -5765,8 +5766,8 @@ nsresult DeleteFile(nsIFile& aFile, QuotaManager* const aQuotaManager,
if (fileSize.value() > 0) {
MOZ_ASSERT(aQuotaManager);
aQuotaManager->DecreaseUsageForOrigin(aPersistenceType, aOriginMetadata,
Client::IDB, fileSize.value());
aQuotaManager->DecreaseUsageForClient(
ClientMetadata{aOriginMetadata, Client::IDB}, fileSize.value());
}
return NS_OK;
@ -5878,8 +5879,8 @@ Result<Ok, nsresult> DeleteFileManagerDirectory(
});
if (usageValue) {
aQuotaManager->DecreaseUsageForOrigin(aPersistenceType, aOriginMetadata,
Client::IDB, usageValue);
aQuotaManager->DecreaseUsageForClient(
ClientMetadata{aOriginMetadata, Client::IDB}, usageValue);
}
return res;

View File

@ -1203,6 +1203,7 @@ class Connection final : public CachingDatabaseConnection {
nsCOMPtr<nsITimer> mFlushTimer;
UniquePtr<ArchivedOriginScope> mArchivedOriginScope;
ConnectionWriteOptimizer mWriteOptimizer;
// XXX Consider changing this to ClientMetadata.
const OriginMetadata mOriginMetadata;
nsString mDirectoryPath;
/**

View File

@ -3895,29 +3895,28 @@ int64_t QuotaManager::NoteOriginDirectoryCreated(
return timestamp;
}
void QuotaManager::DecreaseUsageForOrigin(PersistenceType aPersistenceType,
const OriginMetadata& aOriginMetadata,
Client::Type aClientType,
void QuotaManager::DecreaseUsageForClient(const ClientMetadata& aClientMetadata,
int64_t aSize) {
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aPersistenceType != PERSISTENCE_TYPE_PERSISTENT);
MOZ_ASSERT(IsBestEffortPersistenceType(aClientMetadata.mPersistenceType));
MutexAutoLock lock(mQuotaMutex);
GroupInfoPair* pair;
if (!mGroupInfoPairs.Get(aOriginMetadata.mGroup, &pair)) {
if (!mGroupInfoPairs.Get(aClientMetadata.mGroup, &pair)) {
return;
}
RefPtr<GroupInfo> groupInfo = pair->LockedGetGroupInfo(aPersistenceType);
RefPtr<GroupInfo> groupInfo =
pair->LockedGetGroupInfo(aClientMetadata.mPersistenceType);
if (!groupInfo) {
return;
}
RefPtr<OriginInfo> originInfo =
groupInfo->LockedGetOriginInfo(aOriginMetadata.mOrigin);
groupInfo->LockedGetOriginInfo(aClientMetadata.mOrigin);
if (originInfo) {
originInfo->LockedDecreaseUsage(aClientType, aSize);
originInfo->LockedDecreaseUsage(aClientMetadata.mClientType, aSize);
}
}

View File

@ -8,6 +8,7 @@
#define DOM_QUOTA_COMMONMETADATA_H_
#include <utility>
#include "mozilla/dom/quota/Client.h"
#include "mozilla/dom/quota/PersistenceType.h"
#include "nsString.h"
@ -59,6 +60,13 @@ struct FullOriginMetadata : OriginMetadata {
mLastAccessTime(aLastAccessTime) {}
};
struct ClientMetadata : OriginMetadata {
const Client::Type mClientType;
ClientMetadata(OriginMetadata aOriginMetadata, Client::Type aClientType)
: OriginMetadata(std::move(aOriginMetadata)), mClientType(aClientType) {}
};
} // namespace mozilla::dom::quota
#endif // DOM_QUOTA_COMMONMETADATA_H_

View File

@ -168,9 +168,8 @@ class QuotaManager final : public BackgroundThreadObject {
bool aPersisted);
// XXX clients can use QuotaObject instead of calling this method directly.
void DecreaseUsageForOrigin(PersistenceType aPersistenceType,
const OriginMetadata& aOriginMetadata,
Client::Type aClientType, int64_t aSize);
void DecreaseUsageForClient(const ClientMetadata& aClientMetadata,
int64_t aSize);
void ResetUsageForClient(PersistenceType aPersistenceType,
const OriginMetadata& aOriginMetadata,

View File

@ -346,6 +346,7 @@ class OpenOp final : public ConnectionOperationBase,
const SDBRequestOpenParams mParams;
RefPtr<DirectoryLock> mDirectoryLock;
nsCOMPtr<nsIFileStream> mFileStream;
// XXX Consider changing this to ClientMetadata.
quota::OriginMetadata mOriginMetadata;
State mState;
bool mFileStreamOpen;