Bug 1866217 - Replace uses of Nullable<PersistenceType> type with PersistenceScope; r=dom-storage-reviewers,jari

Nullable<PersistenceType> only allows to specify a concrete persistence type or
all persistence types while PersistenceScope is intended to allow specification
of multiple persistence types as well. Support for that will be added in a
separate patch. This patch is about using the new type especially in directory
locks.

Differential Revision: https://phabricator.services.mozilla.com/D195373
This commit is contained in:
Jan Varga
2024-08-14 12:46:14 +00:00
parent 302dbe3a64
commit d0a8f8f6a6
11 changed files with 153 additions and 148 deletions

View File

@@ -131,6 +131,7 @@
#include "mozilla/dom/quota/ErrorHandling.h"
#include "mozilla/dom/quota/FileStreams.h"
#include "mozilla/dom/quota/OriginScope.h"
#include "mozilla/dom/quota/PersistenceScope.h"
#include "mozilla/dom/quota/PersistenceType.h"
#include "mozilla/dom/quota/QuotaCommon.h"
#include "mozilla/dom/quota/QuotaManager.h"
@@ -13044,7 +13045,7 @@ nsresult Maintenance::OpenDirectory() {
quotaManager
->OpenStorageDirectory(
Nullable<PersistenceType>(), OriginScope::FromNull(),
PersistenceScope::CreateFromNull(), OriginScope::FromNull(),
Nullable<Client::Type>(Client::IDB), /* aExclusive */ false,
DirectoryLockCategory::None, SomeRef(mPendingDirectoryLock))
->Then(GetCurrentSerialEventTarget(), __func__,

View File

@@ -80,6 +80,7 @@
#include "mozilla/dom/quota/DirectoryLockInlines.h"
#include "mozilla/dom/quota/FirstInitializationAttemptsImpl.h"
#include "mozilla/dom/quota/OriginScope.h"
#include "mozilla/dom/quota/PersistenceScope.h"
#include "mozilla/dom/quota/PersistenceType.h"
#include "mozilla/dom/quota/QuotaCommon.h"
#include "mozilla/dom/quota/StorageHelpers.h"
@@ -2637,9 +2638,8 @@ class QuotaClient final : public mozilla::dom::quota::Client {
PersistenceType aPersistenceType, const OriginMetadata& aOriginMetadata,
const AtomicBool& aCanceled) override;
nsresult AboutToClearOrigins(
const Nullable<PersistenceType>& aPersistenceType,
const OriginScope& aOriginScope) override;
nsresult AboutToClearOrigins(const PersistenceScope& aPersistenceScope,
const OriginScope& aOriginScope) override;
void OnOriginClearCompleted(PersistenceType aPersistenceType,
const nsACString& aOrigin) override;
@@ -8458,7 +8458,7 @@ Result<UsageInfo, nsresult> QuotaClient::GetUsageForOrigin(
}
nsresult QuotaClient::AboutToClearOrigins(
const Nullable<PersistenceType>& aPersistenceType,
const PersistenceScope& aPersistenceScope,
const OriginScope& aOriginScope) {
AssertIsOnIOThread();
@@ -8476,8 +8476,8 @@ nsresult QuotaClient::AboutToClearOrigins(
// So this method clears the archived data and shadow database entries for
// given origin scope, but only if it's a privacy-related origin clearing.
if (!aPersistenceType.IsNull() &&
aPersistenceType.Value() != PERSISTENCE_TYPE_DEFAULT) {
if (!aPersistenceScope.IsNull() &&
aPersistenceScope.GetValue() != PERSISTENCE_TYPE_DEFAULT) {
return NS_OK;
}

View File

@@ -1960,20 +1960,19 @@ uint64_t QuotaManager::CollectOriginsForEviction(
nsTArray<NotNull<const DirectoryLockImpl*>> privateStorageLocks;
for (NotNull<const DirectoryLockImpl*> const lock : mDirectoryLocks) {
const Nullable<PersistenceType>& persistenceType =
lock->NullablePersistenceType();
const PersistenceScope& persistenceScope = lock->PersistenceScopeRef();
if (persistenceType.IsNull()) {
if (persistenceScope.IsNull()) {
temporaryStorageLocks.AppendElement(lock);
defaultStorageLocks.AppendElement(lock);
} else if (persistenceType.Value() == PERSISTENCE_TYPE_TEMPORARY) {
} else if (persistenceScope.GetValue() == PERSISTENCE_TYPE_TEMPORARY) {
temporaryStorageLocks.AppendElement(lock);
} else if (persistenceType.Value() == PERSISTENCE_TYPE_DEFAULT) {
} else if (persistenceScope.GetValue() == PERSISTENCE_TYPE_DEFAULT) {
defaultStorageLocks.AppendElement(lock);
} else if (persistenceType.Value() == PERSISTENCE_TYPE_PRIVATE) {
} else if (persistenceScope.GetValue() == PERSISTENCE_TYPE_PRIVATE) {
privateStorageLocks.AppendElement(lock);
} else {
MOZ_ASSERT(persistenceType.Value() == PERSISTENCE_TYPE_PERSISTENT);
MOZ_ASSERT(persistenceScope.GetValue() == PERSISTENCE_TYPE_PERSISTENT);
// Do nothing here, persistent origins don't need to be collected ever.
}
@@ -4949,7 +4948,7 @@ RefPtr<BoolPromise> QuotaManager::InitializeStorage() {
AssertIsOnOwningThread();
RefPtr<UniversalDirectoryLock> directoryLock = CreateDirectoryLockInternal(
Nullable<PersistenceType>(), OriginScope::FromNull(),
PersistenceScope::CreateFromNull(), OriginScope::FromNull(),
Nullable<Client::Type>(),
/* aExclusive */ false);
@@ -5124,14 +5123,14 @@ RefPtr<BoolPromise> QuotaManager::TemporaryStorageInitialized() {
}
RefPtr<UniversalDirectoryLockPromise> QuotaManager::OpenStorageDirectory(
const Nullable<PersistenceType>& aPersistenceType,
const OriginScope& aOriginScope, const Nullable<Client::Type>& aClientType,
bool aExclusive, DirectoryLockCategory aCategory,
const PersistenceScope& aPersistenceScope, const OriginScope& aOriginScope,
const Nullable<Client::Type>& aClientType, bool aExclusive,
DirectoryLockCategory aCategory,
Maybe<RefPtr<UniversalDirectoryLock>&> aPendingDirectoryLockOut) {
AssertIsOnOwningThread();
RefPtr<UniversalDirectoryLock> storageDirectoryLock =
CreateDirectoryLockInternal(Nullable<PersistenceType>(),
CreateDirectoryLockInternal(PersistenceScope::CreateFromNull(),
OriginScope::FromNull(),
Nullable<Client::Type>(),
/* aExclusive */ false);
@@ -5147,7 +5146,7 @@ RefPtr<UniversalDirectoryLockPromise> QuotaManager::OpenStorageDirectory(
}
RefPtr<UniversalDirectoryLock> universalDirectoryLock =
CreateDirectoryLockInternal(aPersistenceType, aOriginScope, aClientType,
CreateDirectoryLockInternal(aPersistenceScope, aOriginScope, aClientType,
aExclusive, aCategory);
RefPtr<BoolPromise> universalDirectoryLockPromise =
@@ -5209,7 +5208,7 @@ RefPtr<ClientDirectoryLockPromise> QuotaManager::OpenClientDirectory(
nsTArray<RefPtr<BoolPromise>> promises;
RefPtr<UniversalDirectoryLock> storageDirectoryLock =
CreateDirectoryLockInternal(Nullable<PersistenceType>(),
CreateDirectoryLockInternal(PersistenceScope::CreateFromNull(),
OriginScope::FromNull(),
Nullable<Client::Type>(),
/* aExclusive */ false);
@@ -5280,13 +5279,13 @@ RefPtr<ClientDirectoryLock> QuotaManager::CreateDirectoryLock(
}
RefPtr<UniversalDirectoryLock> QuotaManager::CreateDirectoryLockInternal(
const Nullable<PersistenceType>& aPersistenceType,
const OriginScope& aOriginScope, const Nullable<Client::Type>& aClientType,
bool aExclusive, DirectoryLockCategory aCategory) {
const PersistenceScope& aPersistenceScope, const OriginScope& aOriginScope,
const Nullable<Client::Type>& aClientType, bool aExclusive,
DirectoryLockCategory aCategory) {
AssertIsOnOwningThread();
return DirectoryLockImpl::CreateInternal(WrapNotNullUnchecked(this),
aPersistenceType, aOriginScope,
aPersistenceScope, aOriginScope,
aClientType, aExclusive, aCategory);
}
@@ -5304,7 +5303,7 @@ RefPtr<BoolPromise> QuotaManager::InitializePersistentOrigin(
// thread).
RefPtr<UniversalDirectoryLock> directoryLock = CreateDirectoryLockInternal(
Nullable<PersistenceType>(PERSISTENCE_TYPE_PERSISTENT),
PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT),
OriginScope::FromOrigin(principalMetadata.mOrigin),
Nullable<Client::Type>(), /* aExclusive */ false);
@@ -5413,7 +5412,7 @@ RefPtr<BoolPromise> QuotaManager::InitializeTemporaryOrigin(
// thread).
RefPtr<UniversalDirectoryLock> directoryLock = CreateDirectoryLockInternal(
Nullable<PersistenceType>(aPersistenceType),
PersistenceScope::CreateFromValue(aPersistenceType),
OriginScope::FromOrigin(principalMetadata.mOrigin),
Nullable<Client::Type>(), /* aExclusive */ false);
@@ -5576,7 +5575,7 @@ RefPtr<BoolPromise> QuotaManager::InitializeTemporaryStorage() {
AssertIsOnOwningThread();
RefPtr<UniversalDirectoryLock> directoryLock = CreateDirectoryLockInternal(
Nullable<PersistenceType>(), OriginScope::FromNull(),
PersistenceScope::CreateFromNull(), OriginScope::FromNull(),
Nullable<Client::Type>(),
/* aExclusive */ false);
@@ -5921,19 +5920,18 @@ Result<bool, nsresult> QuotaManager::EnsureOriginDirectory(
}
nsresult QuotaManager::AboutToClearOrigins(
const Nullable<PersistenceType>& aPersistenceType,
const OriginScope& aOriginScope,
const PersistenceScope& aPersistenceScope, const OriginScope& aOriginScope,
const Nullable<Client::Type>& aClientType) {
AssertIsOnIOThread();
if (aClientType.IsNull()) {
for (Client::Type type : AllClientTypes()) {
QM_TRY(MOZ_TO_RESULT((*mClients)[type]->AboutToClearOrigins(
aPersistenceType, aOriginScope)));
aPersistenceScope, aOriginScope)));
}
} else {
QM_TRY(MOZ_TO_RESULT((*mClients)[aClientType.Value()]->AboutToClearOrigins(
aPersistenceType, aOriginScope)));
aPersistenceScope, aOriginScope)));
}
return NS_OK;

View File

@@ -40,6 +40,7 @@ namespace mozilla::dom::quota {
struct OriginMetadata;
class OriginScope;
class PersistenceScope;
class QuotaManager;
class UsageInfo;
@@ -140,7 +141,7 @@ class Client {
// This method is called when origins are about to be cleared
// (except the case when clearing is triggered by the origin eviction).
virtual nsresult AboutToClearOrigins(
const Nullable<PersistenceType>& aPersistenceType,
const PersistenceScope& aPersistenceScope,
const OriginScope& aOriginScope) {
return NS_OK;
}

View File

@@ -83,8 +83,7 @@ class NS_NO_VTABLE ClientDirectoryLock : public OriginDirectoryLock {
// and its subdirectories.
class UniversalDirectoryLock : public DirectoryLock {
public:
// XXX Rename to NullablePersistenceTypeRef.
virtual const Nullable<PersistenceType>& NullablePersistenceType() const = 0;
virtual const PersistenceScope& PersistenceScopeRef() const = 0;
// XXX Rename to OriginScopeRef.
virtual const OriginScope& GetOriginScope() const = 0;

View File

@@ -14,15 +14,15 @@ namespace mozilla::dom::quota {
DirectoryLockImpl::DirectoryLockImpl(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const Nullable<PersistenceType>& aPersistenceType,
const nsACString& aSuffix, const nsACString& aGroup,
const OriginScope& aOriginScope, const nsACString& aStorageOrigin,
bool aIsPrivate, const Nullable<Client::Type>& aClientType,
const bool aExclusive, const bool aInternal,
const PersistenceScope& aPersistenceScope, const nsACString& aSuffix,
const nsACString& aGroup, const OriginScope& aOriginScope,
const nsACString& aStorageOrigin, bool aIsPrivate,
const Nullable<Client::Type>& aClientType, const bool aExclusive,
const bool aInternal,
const ShouldUpdateLockIdTableFlag aShouldUpdateLockIdTableFlag,
const DirectoryLockCategory aCategory)
: mQuotaManager(std::move(aQuotaManager)),
mPersistenceType(aPersistenceType),
mPersistenceScope(aPersistenceScope),
mSuffix(aSuffix),
mGroup(aGroup),
mOriginScope(aOriginScope),
@@ -38,9 +38,9 @@ DirectoryLockImpl::DirectoryLockImpl(
mRegistered(false) {
AssertIsOnOwningThread();
MOZ_ASSERT_IF(aOriginScope.IsOrigin(), !aOriginScope.GetOrigin().IsEmpty());
MOZ_ASSERT_IF(!aInternal, !aPersistenceType.IsNull());
MOZ_ASSERT_IF(!aInternal, !aPersistenceScope.IsNull());
MOZ_ASSERT_IF(!aInternal,
aPersistenceType.Value() != PERSISTENCE_TYPE_INVALID);
aPersistenceScope.GetValue() != PERSISTENCE_TYPE_INVALID);
MOZ_ASSERT_IF(!aInternal, !aGroup.IsEmpty());
MOZ_ASSERT_IF(!aInternal, aOriginScope.IsOrigin());
MOZ_ASSERT_IF(!aInternal, !aStorageOrigin.IsEmpty());
@@ -69,13 +69,13 @@ bool DirectoryLockImpl::Overlaps(const DirectoryLockImpl& aLock) const {
AssertIsOnOwningThread();
// If the persistence types don't overlap, the op can proceed.
if (!aLock.mPersistenceType.IsNull() && !mPersistenceType.IsNull() &&
aLock.mPersistenceType.Value() != mPersistenceType.Value()) {
bool match = aLock.mPersistenceScope.Matches(mPersistenceScope);
if (!match) {
return false;
}
// If the origin scopes don't overlap, the op can proceed.
bool match = aLock.mOriginScope.Matches(mOriginScope);
match = aLock.mOriginScope.Matches(mOriginScope);
if (!match) {
return false;
}
@@ -332,7 +332,7 @@ RefPtr<ClientDirectoryLock> DirectoryLockImpl::SpecializeForClient(
}
RefPtr<DirectoryLockImpl> lock =
Create(mQuotaManager, Nullable<PersistenceType>(aPersistenceType),
Create(mQuotaManager, PersistenceScope::CreateFromValue(aPersistenceType),
aOriginMetadata.mSuffix, aOriginMetadata.mGroup,
OriginScope::FromOrigin(aOriginMetadata.mOrigin),
aOriginMetadata.mStorageOrigin, aOriginMetadata.mIsPrivate,
@@ -378,10 +378,11 @@ void DirectoryLockImpl::Log() const {
QM_LOG(("DirectoryLockImpl [%p]", this));
nsCString persistenceType;
if (mPersistenceType.IsNull()) {
if (mPersistenceScope.IsNull()) {
persistenceType.AssignLiteral("null");
} else {
persistenceType.Assign(PersistenceTypeToString(mPersistenceType.Value()));
persistenceType.Assign(
PersistenceTypeToString(mPersistenceScope.GetValue()));
}
QM_LOG((" mPersistenceType: %s", persistenceType.get()));

View File

@@ -13,6 +13,7 @@
#include "mozilla/dom/quota/DirectoryLock.h"
#include "mozilla/dom/quota/DirectoryLockCategory.h"
#include "mozilla/dom/quota/OriginScope.h"
#include "mozilla/dom/quota/PersistenceScope.h"
namespace mozilla::dom::quota {
@@ -22,7 +23,7 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
public UniversalDirectoryLock {
const NotNull<RefPtr<QuotaManager>> mQuotaManager;
const Nullable<PersistenceType> mPersistenceType;
const PersistenceScope mPersistenceScope;
const nsCString mSuffix;
const nsCString mGroup;
const OriginScope mOriginScope;
@@ -56,7 +57,7 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
public:
DirectoryLockImpl(MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const Nullable<PersistenceType>& aPersistenceType,
const PersistenceScope& aPersistenceScope,
const nsACString& aSuffix, const nsACString& aGroup,
const OriginScope& aOriginScope,
const nsACString& aStorageOrigin, bool aIsPrivate,
@@ -70,13 +71,14 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
PersistenceType aPersistenceType,
const quota::OriginMetadata& aOriginMetadata, Client::Type aClientType,
bool aExclusive) {
return Create(
std::move(aQuotaManager), Nullable<PersistenceType>(aPersistenceType),
aOriginMetadata.mSuffix, aOriginMetadata.mGroup,
OriginScope::FromOrigin(aOriginMetadata.mOrigin),
aOriginMetadata.mStorageOrigin, aOriginMetadata.mIsPrivate,
Nullable<Client::Type>(aClientType), aExclusive, false,
ShouldUpdateLockIdTableFlag::Yes, DirectoryLockCategory::None);
return Create(std::move(aQuotaManager),
PersistenceScope::CreateFromValue(aPersistenceType),
aOriginMetadata.mSuffix, aOriginMetadata.mGroup,
OriginScope::FromOrigin(aOriginMetadata.mOrigin),
aOriginMetadata.mStorageOrigin, aOriginMetadata.mIsPrivate,
Nullable<Client::Type>(aClientType), aExclusive, false,
ShouldUpdateLockIdTableFlag::Yes,
DirectoryLockCategory::None);
}
static RefPtr<OriginDirectoryLock> CreateForEviction(
@@ -88,7 +90,7 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
MOZ_ASSERT(!aOriginMetadata.mStorageOrigin.IsEmpty());
return Create(std::move(aQuotaManager),
Nullable<PersistenceType>(aPersistenceType),
PersistenceScope::CreateFromValue(aPersistenceType),
aOriginMetadata.mSuffix, aOriginMetadata.mGroup,
OriginScope::FromOrigin(aOriginMetadata.mOrigin),
aOriginMetadata.mStorageOrigin, aOriginMetadata.mIsPrivate,
@@ -99,11 +101,11 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
static RefPtr<UniversalDirectoryLock> CreateInternal(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const Nullable<PersistenceType>& aPersistenceType,
const PersistenceScope& aPersistenceScope,
const OriginScope& aOriginScope,
const Nullable<Client::Type>& aClientType, bool aExclusive,
DirectoryLockCategory aCategory) {
return Create(std::move(aQuotaManager), aPersistenceType, ""_ns, ""_ns,
return Create(std::move(aQuotaManager), aPersistenceScope, ""_ns, ""_ns,
aOriginScope, ""_ns, false, aClientType, aExclusive, true,
ShouldUpdateLockIdTableFlag::Yes, aCategory);
}
@@ -135,7 +137,7 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
bool ShouldUpdateLockTable() {
return !mInternal &&
mPersistenceType.Value() != PERSISTENCE_TYPE_PERSISTENT;
mPersistenceScope.GetValue() != PERSISTENCE_TYPE_PERSISTENT;
}
bool Overlaps(const DirectoryLockImpl& aLock) const;
@@ -211,9 +213,9 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
// OriginDirectoryLock interface
PersistenceType GetPersistenceType() const override {
MOZ_DIAGNOSTIC_ASSERT(!mPersistenceType.IsNull());
MOZ_DIAGNOSTIC_ASSERT(!mPersistenceScope.IsNull());
return mPersistenceType.Value();
return mPersistenceScope.GetValue();
}
quota::OriginMetadata OriginMetadata() const override {
@@ -242,8 +244,8 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
// UniversalDirectoryLock interface
const Nullable<PersistenceType>& NullablePersistenceType() const override {
return mPersistenceType;
const PersistenceScope& PersistenceScopeRef() const override {
return mPersistenceScope;
}
const OriginScope& GetOriginScope() const override { return mOriginScope; }
@@ -262,17 +264,16 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
static RefPtr<DirectoryLockImpl> Create(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const Nullable<PersistenceType>& aPersistenceType,
const nsACString& aSuffix, const nsACString& aGroup,
const OriginScope& aOriginScope, const nsACString& aStorageOrigin,
bool aIsPrivate, const Nullable<Client::Type>& aClientType,
bool aExclusive, bool aInternal,
ShouldUpdateLockIdTableFlag aShouldUpdateLockIdTableFlag,
const PersistenceScope& aPersistenceScope, const nsACString& aSuffix,
const nsACString& aGroup, const OriginScope& aOriginScope,
const nsACString& aStorageOrigin, bool aIsPrivate,
const Nullable<Client::Type>& aClientType, bool aExclusive,
bool aInternal, ShouldUpdateLockIdTableFlag aShouldUpdateLockIdTableFlag,
DirectoryLockCategory aCategory) {
MOZ_ASSERT_IF(aOriginScope.IsOrigin(), !aOriginScope.GetOrigin().IsEmpty());
MOZ_ASSERT_IF(!aInternal, !aPersistenceType.IsNull());
MOZ_ASSERT_IF(!aInternal, !aPersistenceScope.IsNull());
MOZ_ASSERT_IF(!aInternal,
aPersistenceType.Value() != PERSISTENCE_TYPE_INVALID);
aPersistenceScope.GetValue() != PERSISTENCE_TYPE_INVALID);
MOZ_ASSERT_IF(!aInternal, !aGroup.IsEmpty());
MOZ_ASSERT_IF(!aInternal, aOriginScope.IsOrigin());
MOZ_ASSERT_IF(!aInternal, !aStorageOrigin.IsEmpty());
@@ -280,7 +281,7 @@ class DirectoryLockImpl final : public ClientDirectoryLock,
MOZ_ASSERT_IF(!aInternal, aClientType.Value() < Client::TypeMax());
return MakeRefPtr<DirectoryLockImpl>(
std::move(aQuotaManager), aPersistenceType, aSuffix, aGroup,
std::move(aQuotaManager), aPersistenceScope, aSuffix, aGroup,
aOriginScope, aStorageOrigin, aIsPrivate, aClientType, aExclusive,
aInternal, aShouldUpdateLockIdTableFlag, aCategory);
}

View File

@@ -33,6 +33,7 @@
#include "mozilla/dom/quota/PQuotaRequest.h"
#include "mozilla/dom/quota/PQuotaUsageRequest.h"
#include "mozilla/dom/quota/OriginScope.h"
#include "mozilla/dom/quota/PersistenceScope.h"
#include "mozilla/dom/quota/QuotaCommon.h"
#include "mozilla/dom/quota/QuotaManager.h"
#include "mozilla/dom/quota/QuotaManagerImpl.h"
@@ -75,7 +76,7 @@ class OpenStorageDirectoryHelper : public Base {
: Base(std::move(aQuotaManager), aName) {}
RefPtr<BoolPromise> OpenStorageDirectory(
const Nullable<PersistenceType>& aPersistenceType,
const PersistenceScope& aPersistenceScope,
const OriginScope& aOriginScope,
const Nullable<Client::Type>& aClientType, bool aExclusive,
DirectoryLockCategory aCategory = DirectoryLockCategory::None);
@@ -599,7 +600,7 @@ class ClearRequestBase
class ClearOriginOp final : public ClearRequestBase {
const PrincipalInfo mPrincipalInfo;
PrincipalMetadata mPrincipalMetadata;
const Nullable<PersistenceType> mPersistenceType;
const PersistenceScope mPersistenceScope;
const Nullable<Client::Type> mClientType;
public:
@@ -625,7 +626,7 @@ class ClearOriginOp final : public ClearRequestBase {
class ClearStoragesForOriginPrefixOp final
: public OpenStorageDirectoryHelper<ClearRequestBase> {
const nsCString mPrefix;
const Nullable<PersistenceType> mPersistenceType;
const PersistenceScope mPersistenceScope;
public:
ClearStoragesForOriginPrefixOp(
@@ -667,7 +668,7 @@ class ClearDataOp final : public ClearRequestBase {
class ResetOriginOp final : public QuotaRequestBase {
nsCString mOrigin;
RefPtr<UniversalDirectoryLock> mDirectoryLock;
Nullable<PersistenceType> mPersistenceType;
PersistenceScope mPersistenceScope;
Nullable<Client::Type> mClientType;
public:
@@ -951,11 +952,11 @@ RefPtr<QuotaRequestBase> CreateListOriginsOp(
template <class Base>
RefPtr<BoolPromise> OpenStorageDirectoryHelper<Base>::OpenStorageDirectory(
const Nullable<PersistenceType>& aPersistenceType,
const OriginScope& aOriginScope, const Nullable<Client::Type>& aClientType,
bool aExclusive, const DirectoryLockCategory aCategory) {
const PersistenceScope& aPersistenceScope, const OriginScope& aOriginScope,
const Nullable<Client::Type>& aClientType, bool aExclusive,
const DirectoryLockCategory aCategory) {
return Base::mQuotaManager
->OpenStorageDirectory(aPersistenceType, aOriginScope, aClientType,
->OpenStorageDirectory(aPersistenceScope, aOriginScope, aClientType,
aExclusive, aCategory)
->Then(GetCurrentSerialEventTarget(), __func__,
[self = RefPtr(this)](
@@ -1005,7 +1006,7 @@ RefPtr<BoolPromise> SaveOriginAccessTimeOp::OpenDirectory() {
AssertIsOnOwningThread();
return OpenStorageDirectory(
Nullable<PersistenceType>(mOriginMetadata.mPersistenceType),
PersistenceScope::CreateFromValue(mOriginMetadata.mPersistenceType),
OriginScope::FromOrigin(mOriginMetadata.mOrigin),
Nullable<Client::Type>(),
/* aExclusive */ false);
@@ -1051,7 +1052,7 @@ RefPtr<BoolPromise> ClearPrivateRepositoryOp::OpenDirectory() {
AssertIsOnOwningThread();
return OpenStorageDirectory(
Nullable<PersistenceType>(PERSISTENCE_TYPE_PRIVATE),
PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PRIVATE),
OriginScope::FromNull(), Nullable<Client::Type>(),
/* aExclusive */ true);
}
@@ -1097,7 +1098,7 @@ RefPtr<BoolPromise> ShutdownStorageOp::OpenDirectory() {
mQuotaManager->ClearDirectoryLockTables();
mDirectoryLock = mQuotaManager->CreateDirectoryLockInternal(
Nullable<PersistenceType>(), OriginScope::FromNull(),
PersistenceScope::CreateFromNull(), OriginScope::FromNull(),
Nullable<Client::Type>(),
/* aExclusive */ true, DirectoryLockCategory::UninitStorage);
@@ -1392,7 +1393,7 @@ nsresult GetUsageOp::ProcessOrigin(QuotaManager& aQuotaManager,
RefPtr<BoolPromise> GetUsageOp::OpenDirectory() {
AssertIsOnOwningThread();
return OpenStorageDirectory(Nullable<PersistenceType>(),
return OpenStorageDirectory(PersistenceScope::CreateFromNull(),
OriginScope::FromNull(), Nullable<Client::Type>(),
/* aExclusive */ false);
}
@@ -1465,7 +1466,7 @@ RefPtr<BoolPromise> GetOriginUsageOp::OpenDirectory() {
AssertIsOnOwningThread();
return OpenStorageDirectory(
Nullable<PersistenceType>(),
PersistenceScope::CreateFromNull(),
OriginScope::FromOrigin(mPrincipalMetadata.mOrigin),
Nullable<Client::Type>(),
/* aExclusive */ false);
@@ -1810,7 +1811,7 @@ RefPtr<BoolPromise> InitializeClientBase::OpenDirectory() {
AssertIsOnOwningThread();
mDirectoryLock = mQuotaManager->CreateDirectoryLockInternal(
Nullable(mPersistenceType),
PersistenceScope::CreateFromValue(mPersistenceType),
OriginScope::FromOrigin(mClientMetadata.mOrigin),
Nullable(mClientMetadata.mClientType), /* aExclusive */ false);
@@ -1926,7 +1927,7 @@ RefPtr<BoolPromise> GetFullOriginMetadataOp::OpenDirectory() {
AssertIsOnOwningThread();
return OpenStorageDirectory(
Nullable<PersistenceType>(mOriginMetadata.mPersistenceType),
PersistenceScope::CreateFromValue(mOriginMetadata.mPersistenceType),
OriginScope::FromOrigin(mOriginMetadata.mOrigin),
Nullable<Client::Type>(),
/* aExclusive */ false);
@@ -1992,7 +1993,7 @@ RefPtr<BoolPromise> GetCachedOriginUsageOp::OpenDirectory() {
AssertIsOnOwningThread();
return OpenStorageDirectory(
Nullable<PersistenceType>(),
PersistenceScope::CreateFromNull(),
OriginScope::FromOrigin(mPrincipalMetadata.mOrigin),
Nullable<Client::Type>(),
/* aExclusive */ false);
@@ -2041,9 +2042,9 @@ ClearStorageOp::ClearStorageOp(
void ClearStorageOp::DeleteFiles(QuotaManager& aQuotaManager) {
AssertIsOnIOThread();
nsresult rv = aQuotaManager.AboutToClearOrigins(Nullable<PersistenceType>(),
OriginScope::FromNull(),
Nullable<Client::Type>());
nsresult rv = aQuotaManager.AboutToClearOrigins(
PersistenceScope::CreateFromNull(), OriginScope::FromNull(),
Nullable<Client::Type>());
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
@@ -2090,7 +2091,7 @@ RefPtr<BoolPromise> ClearStorageOp::OpenDirectory() {
// storage again in the end.
mQuotaManager->ClearDirectoryLockTables();
return OpenStorageDirectory(Nullable<PersistenceType>(),
return OpenStorageDirectory(PersistenceScope::CreateFromNull(),
OriginScope::FromNull(), Nullable<Client::Type>(),
/* aExclusive */ true,
DirectoryLockCategory::UninitStorage);
@@ -2184,7 +2185,7 @@ void ClearRequestBase::DeleteFilesInternal(
AssertIsOnIOThread();
QM_TRY(MOZ_TO_RESULT(aQuotaManager.AboutToClearOrigins(
Nullable<PersistenceType>(aPersistenceType), aOriginScope,
PersistenceScope::CreateFromValue(aPersistenceType), aOriginScope,
aClientType)),
QM_VOID);
@@ -2361,9 +2362,9 @@ ClearOriginOp::ClearOriginOp(
const mozilla::Maybe<Client::Type>& aClientType)
: ClearRequestBase(std::move(aQuotaManager), "dom::quota::ClearOriginOp"),
mPrincipalInfo(aPrincipalInfo),
mPersistenceType(aPersistenceType
? Nullable<PersistenceType>(*aPersistenceType)
: Nullable<PersistenceType>()),
mPersistenceScope(aPersistenceType ? PersistenceScope::CreateFromValue(
*aPersistenceType)
: PersistenceScope::CreateFromNull()),
mClientType(aClientType ? Nullable<Client::Type>(*aClientType)
: Nullable<Client::Type>()) {
AssertIsOnOwningThread();
@@ -2385,7 +2386,7 @@ RefPtr<BoolPromise> ClearOriginOp::OpenDirectory() {
AssertIsOnOwningThread();
return OpenStorageDirectory(
mPersistenceType, OriginScope::FromOrigin(mPrincipalMetadata.mOrigin),
mPersistenceScope, OriginScope::FromOrigin(mPrincipalMetadata.mOrigin),
mClientType,
/* aExclusive */ true);
}
@@ -2396,15 +2397,16 @@ nsresult ClearOriginOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
AUTO_PROFILER_LABEL("ClearRequestBase::DoDirectoryWork", OTHER);
if (mPersistenceType.IsNull()) {
if (mPersistenceScope.IsNull()) {
for (const PersistenceType type : kAllPersistenceTypes) {
DeleteFiles(aQuotaManager, OriginMetadata(mPrincipalMetadata, type),
mClientType);
}
} else {
DeleteFiles(aQuotaManager,
OriginMetadata(mPrincipalMetadata, mPersistenceType.Value()),
mClientType);
DeleteFiles(
aQuotaManager,
OriginMetadata(mPrincipalMetadata, mPersistenceScope.GetValue()),
mClientType);
}
return NS_OK;
@@ -2430,16 +2432,16 @@ ClearStoragesForOriginPrefixOp::ClearStoragesForOriginPrefixOp(
"dom::quota::ClearStoragesForOriginPrefixOp"),
mPrefix(
QuotaManager::GetOriginFromValidatedPrincipalInfo(aPrincipalInfo)),
mPersistenceType(aPersistenceType
? Nullable<PersistenceType>(*aPersistenceType)
: Nullable<PersistenceType>()) {
mPersistenceScope(aPersistenceType ? PersistenceScope::CreateFromValue(
*aPersistenceType)
: PersistenceScope::CreateFromNull()) {
AssertIsOnOwningThread();
}
RefPtr<BoolPromise> ClearStoragesForOriginPrefixOp::OpenDirectory() {
AssertIsOnOwningThread();
return OpenStorageDirectory(mPersistenceType,
return OpenStorageDirectory(mPersistenceScope,
OriginScope::FromPrefix(mPrefix),
Nullable<Client::Type>(),
/* aExclusive */ true);
@@ -2451,13 +2453,13 @@ nsresult ClearStoragesForOriginPrefixOp::DoDirectoryWork(
AUTO_PROFILER_LABEL("ClearStoragesForOriginPrefixOp::DoDirectoryWork", OTHER);
if (mPersistenceType.IsNull()) {
if (mPersistenceScope.IsNull()) {
for (const PersistenceType type : kAllPersistenceTypes) {
DeleteFiles(aQuotaManager, type, OriginScope::FromPrefix(mPrefix),
Nullable<Client::Type>());
}
} else {
DeleteFiles(aQuotaManager, mPersistenceType.Value(),
DeleteFiles(aQuotaManager, mPersistenceScope.GetValue(),
OriginScope::FromPrefix(mPrefix), Nullable<Client::Type>());
}
@@ -2484,7 +2486,7 @@ ClearDataOp::ClearDataOp(MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
RefPtr<BoolPromise> ClearDataOp::OpenDirectory() {
AssertIsOnOwningThread();
return OpenStorageDirectory(Nullable<PersistenceType>(),
return OpenStorageDirectory(PersistenceScope::CreateFromNull(),
OriginScope::FromPattern(mPattern),
Nullable<Client::Type>(),
/* aExclusive */ true);
@@ -2528,7 +2530,7 @@ ResetOriginOp::ResetOriginOp(MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
QuotaManager::GetOriginFromValidatedPrincipalInfo(params.principalInfo());
if (params.persistenceTypeIsExplicit()) {
mPersistenceType.SetValue(params.persistenceType());
mPersistenceScope.SetFromValue(params.persistenceType());
}
if (params.clientTypeIsExplicit()) {
@@ -2540,7 +2542,7 @@ RefPtr<BoolPromise> ResetOriginOp::OpenDirectory() {
AssertIsOnOwningThread();
mDirectoryLock = mQuotaManager->CreateDirectoryLockInternal(
mPersistenceType, OriginScope::FromOrigin(mOrigin), mClientType,
mPersistenceScope, OriginScope::FromOrigin(mOrigin), mClientType,
/* aExclusive */ true);
return mDirectoryLock->Acquire();
@@ -2596,7 +2598,7 @@ RefPtr<BoolPromise> PersistRequestBase::OpenDirectory() {
AssertIsOnOwningThread();
return OpenStorageDirectory(
Nullable<PersistenceType>(PERSISTENCE_TYPE_DEFAULT),
PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_DEFAULT),
OriginScope::FromOrigin(mPrincipalMetadata.mOrigin),
Nullable<Client::Type>(),
/* aExclusive */ false);
@@ -2769,7 +2771,7 @@ RefPtr<BoolPromise> EstimateOp::OpenDirectory() {
// XXX In theory, we should be locking entire group, not just one origin.
return OpenStorageDirectory(
Nullable<PersistenceType>(mOriginMetadata.mPersistenceType),
PersistenceScope::CreateFromValue(mOriginMetadata.mPersistenceType),
OriginScope::FromOrigin(mOriginMetadata.mOrigin),
Nullable<Client::Type>(),
/* aExclusive */ false);
@@ -2820,7 +2822,7 @@ ListOriginsOp::ListOriginsOp(MovingNotNull<RefPtr<QuotaManager>> aQuotaManager)
RefPtr<BoolPromise> ListOriginsOp::OpenDirectory() {
AssertIsOnOwningThread();
return OpenStorageDirectory(Nullable<PersistenceType>(),
return OpenStorageDirectory(PersistenceScope::CreateFromNull(),
OriginScope::FromNull(), Nullable<Client::Type>(),
/* aExclusive */ false);
}

View File

@@ -273,7 +273,7 @@ class QuotaManager final : public BackgroundThreadObject {
const ClientMetadata& aClientMetadata) const;
RefPtr<UniversalDirectoryLockPromise> OpenStorageDirectory(
const Nullable<PersistenceType>& aPersistenceType,
const PersistenceScope& aPersistenceScope,
const OriginScope& aOriginScope,
const Nullable<Client::Type>& aClientType, bool aExclusive,
DirectoryLockCategory aCategory = DirectoryLockCategory::None,
@@ -304,7 +304,7 @@ class QuotaManager final : public BackgroundThreadObject {
// XXX RemoveMe once bug 1170279 gets fixed.
RefPtr<UniversalDirectoryLock> CreateDirectoryLockInternal(
const Nullable<PersistenceType>& aPersistenceType,
const PersistenceScope& aPersistenceScope,
const OriginScope& aOriginScope,
const Nullable<Client::Type>& aClientType, bool aExclusive,
DirectoryLockCategory aCategory = DirectoryLockCategory::None);
@@ -453,10 +453,9 @@ class QuotaManager final : public BackgroundThreadObject {
// Returns a bool indicating whether the directory was newly created.
Result<bool, nsresult> EnsureOriginDirectory(nsIFile& aDirectory);
nsresult AboutToClearOrigins(
const Nullable<PersistenceType>& aPersistenceType,
const OriginScope& aOriginScope,
const Nullable<Client::Type>& aClientType);
nsresult AboutToClearOrigins(const PersistenceScope& aPersistenceScope,
const OriginScope& aOriginScope,
const Nullable<Client::Type>& aClientType);
void OriginClearCompleted(PersistenceType aPersistenceType,
const nsACString& aOrigin,

View File

@@ -27,8 +27,9 @@ TEST_F(DOM_Quota_DirectoryLock, Drop_Timing) {
RefPtr<UniversalDirectoryLock> exclusiveDirectoryLock =
DirectoryLockImpl::CreateInternal(
WrapNotNullUnchecked(quotaManager), Nullable<PersistenceType>(),
OriginScope::FromNull(), Nullable<Client::Type>(),
WrapNotNullUnchecked(quotaManager),
PersistenceScope::CreateFromNull(), OriginScope::FromNull(),
Nullable<Client::Type>(),
/* aExclusive */ true, DirectoryLockCategory::None);
bool done = false;
@@ -46,8 +47,9 @@ TEST_F(DOM_Quota_DirectoryLock, Drop_Timing) {
RefPtr<UniversalDirectoryLock> sharedDirectoryLock =
DirectoryLockImpl::CreateInternal(
WrapNotNullUnchecked(quotaManager), Nullable<PersistenceType>(),
OriginScope::FromNull(), Nullable<Client::Type>(),
WrapNotNullUnchecked(quotaManager),
PersistenceScope::CreateFromNull(), OriginScope::FromNull(),
Nullable<Client::Type>(),
/* aExclusive */ false, DirectoryLockCategory::None);
ASSERT_TRUE(sharedDirectoryLock->MustWait());

View File

@@ -11,6 +11,7 @@
#include "mozilla/dom/quota/DirectoryLock.h"
#include "mozilla/dom/quota/DirectoryLockInlines.h"
#include "mozilla/dom/quota/OriginScope.h"
#include "mozilla/dom/quota/PersistenceScope.h"
#include "mozilla/dom/quota/QuotaManager.h"
#include "mozilla/dom/quota/ResultExtensions.h"
#include "mozilla/gtest/MozAssertions.h"
@@ -43,7 +44,7 @@ TEST_F(TestQuotaManager, OpenStorageDirectory_OngoingWithScheduledShutdown) {
promises.AppendElement(
quotaManager
->OpenStorageDirectory(
Nullable<PersistenceType>(PERSISTENCE_TYPE_PERSISTENT),
PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT),
OriginScope::FromNull(), Nullable<Client::Type>(),
/* aExclusive */ false)
->Then(GetCurrentSerialEventTarget(), __func__,
@@ -94,7 +95,7 @@ TEST_F(TestQuotaManager, OpenStorageDirectory_OngoingWithScheduledShutdown) {
promises.AppendElement(
quotaManager
->OpenStorageDirectory(
Nullable<PersistenceType>(PERSISTENCE_TYPE_PERSISTENT),
PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT),
OriginScope::FromNull(), Nullable<Client::Type>(),
/* aExclusive */ false)
->Then(GetCurrentSerialEventTarget(), __func__,
@@ -152,17 +153,17 @@ TEST_F(TestQuotaManager,
ASSERT_TRUE(quotaManager);
RefPtr<UniversalDirectoryLock> directoryLock =
quotaManager->CreateDirectoryLockInternal(Nullable<PersistenceType>(),
OriginScope::FromNull(),
Nullable<Client::Type>(),
/* aExclusive */ true);
quotaManager->CreateDirectoryLockInternal(
PersistenceScope::CreateFromNull(), OriginScope::FromNull(),
Nullable<Client::Type>(),
/* aExclusive */ true);
nsTArray<RefPtr<BoolPromise>> promises;
promises.AppendElement(
quotaManager
->OpenStorageDirectory(
Nullable<PersistenceType>(PERSISTENCE_TYPE_PERSISTENT),
PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT),
OriginScope::FromNull(), Nullable<Client::Type>(),
/* aExclusive */ false)
->Then(GetCurrentSerialEventTarget(), __func__,
@@ -186,7 +187,7 @@ TEST_F(TestQuotaManager,
promises.AppendElement(
quotaManager
->OpenStorageDirectory(
Nullable<PersistenceType>(PERSISTENCE_TYPE_PERSISTENT),
PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT),
OriginScope::FromNull(), Nullable<Client::Type>(),
/* aExclusive */ false)
->Then(GetCurrentSerialEventTarget(), __func__,
@@ -246,7 +247,7 @@ TEST_F(TestQuotaManager, OpenStorageDirectory_Finished) {
quotaManager
->OpenStorageDirectory(
Nullable<PersistenceType>(PERSISTENCE_TYPE_PERSISTENT),
PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT),
OriginScope::FromNull(), Nullable<Client::Type>(),
/* aExclusive */ false)
->Then(
@@ -273,7 +274,7 @@ TEST_F(TestQuotaManager, OpenStorageDirectory_Finished) {
quotaManager
->OpenStorageDirectory(
Nullable<PersistenceType>(PERSISTENCE_TYPE_PERSISTENT),
PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT),
OriginScope::FromNull(), Nullable<Client::Type>(),
/* aExclusive */ false)
->Then(
@@ -317,7 +318,7 @@ TEST_F(TestQuotaManager, OpenStorageDirectory_FinishedWithScheduledShutdown) {
quotaManager
->OpenStorageDirectory(
Nullable<PersistenceType>(PERSISTENCE_TYPE_PERSISTENT),
PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT),
OriginScope::FromNull(), Nullable<Client::Type>(),
/* aExclusive */ false)
->Then(
@@ -346,7 +347,7 @@ TEST_F(TestQuotaManager, OpenStorageDirectory_FinishedWithScheduledShutdown) {
promises.AppendElement(
quotaManager
->OpenStorageDirectory(
Nullable<PersistenceType>(PERSISTENCE_TYPE_PERSISTENT),
PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT),
OriginScope::FromNull(), Nullable<Client::Type>(),
/* aExclusive */ false)
->Then(GetCurrentSerialEventTarget(), __func__,
@@ -408,7 +409,7 @@ TEST_F(TestQuotaManager,
quotaManager
->OpenStorageDirectory(
Nullable<PersistenceType>(PERSISTENCE_TYPE_PERSISTENT),
PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT),
OriginScope::FromNull(), Nullable<Client::Type>(),
/* aExclusive */ false)
->Then(
@@ -449,7 +450,7 @@ TEST_F(TestQuotaManager,
quotaManager
->OpenStorageDirectory(
Nullable<PersistenceType>(PERSISTENCE_TYPE_PERSISTENT),
PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT),
OriginScope::FromNull(), Nullable<Client::Type>(),
/* aExclusive */ false)
->Then(
@@ -599,10 +600,10 @@ TEST_F(TestQuotaManager,
ASSERT_TRUE(quotaManager);
RefPtr<UniversalDirectoryLock> directoryLock =
quotaManager->CreateDirectoryLockInternal(Nullable<PersistenceType>(),
OriginScope::FromNull(),
Nullable<Client::Type>(),
/* aExclusive */ true);
quotaManager->CreateDirectoryLockInternal(
PersistenceScope::CreateFromNull(), OriginScope::FromNull(),
Nullable<Client::Type>(),
/* aExclusive */ true);
nsTArray<RefPtr<BoolPromise>> promises;
@@ -1079,10 +1080,10 @@ TEST_F(TestQuotaManager, InitializeStorage_OngoingWithExclusiveDirectoryLock) {
ASSERT_TRUE(quotaManager);
RefPtr<UniversalDirectoryLock> directoryLock =
quotaManager->CreateDirectoryLockInternal(Nullable<PersistenceType>(),
OriginScope::FromNull(),
Nullable<Client::Type>(),
/* aExclusive */ true);
quotaManager->CreateDirectoryLockInternal(
PersistenceScope::CreateFromNull(), OriginScope::FromNull(),
Nullable<Client::Type>(),
/* aExclusive */ true);
nsTArray<RefPtr<BoolPromise>> promises;