Bug 1733107 - Rework remaining QuotaManagerService clearing methods to use asynchronous messages instead of creating sub actors; r=dom-storage-reviewers,jstutte

QuotaManagerService::ClearStoragesForOriginAttributesPattern and
QuotaManagerService::ClearStoragesForPrincipal still create sub actors which
makes it hard to add new clearing operations which would use async IPC messages
and which would inherit from the ClearRequestBase class as well.

Changes done in this patch:
- added QuotaManager::ClearStoragesForOrigin
- added QuotaManager::ClearStoragesForOriginAttributesPattern
- changed ClearRequestBase to inherit from ResolvableNormalOriginOp
- QuotaManagerService::ClearStoragesForOriginAttributesPattern reworked to use
  an asynchronous message instead of a sub actor
- QuotaManagerService::ClearStoragesForPrincipal reworked to use an
  asynchronous message instead of a sub actor
- added a new mactor QM_CUF_AND_IPC_FAIL similar to QM_IPC_FAIL

creating a sub actor

Differential Revision: https://phabricator.services.mozilla.com/D186628
This commit is contained in:
Jan Varga 2023-09-25 16:28:38 +00:00
Родитель 34e0e8625a
Коммит b3f56d4188
10 изменённых файлов: 258 добавлений и 165 удалений

Просмотреть файл

@ -362,9 +362,7 @@ mozilla::ipc::IPCResult QuotaRequestChild::Recv__delete__(
break;
case RequestResponse::TInitTemporaryStorageResponse:
case RequestResponse::TClearOriginResponse:
case RequestResponse::TResetOriginResponse:
case RequestResponse::TClearDataResponse:
case RequestResponse::TPersistResponse:
HandleResponse();
break;

Просмотреть файл

@ -5296,6 +5296,37 @@ nsresult QuotaManager::EnsureTemporaryStorageIsInitialized() {
"dom::quota::FirstInitializationAttempt::TemporaryStorage"_ns, innerFunc);
}
RefPtr<BoolPromise> QuotaManager::ClearStoragesForOrigin(
const Maybe<PersistenceType>& aPersistenceType,
const PrincipalInfo& aPrincipalInfo, const Maybe<Client::Type>& aClientType,
const bool& aClearAll) {
AssertIsOnOwningThread();
auto clearOriginOp =
CreateClearOriginOp(WrapMovingNotNullUnchecked(this), aPersistenceType,
aPrincipalInfo, aClientType, aClearAll);
RegisterNormalOriginOp(*clearOriginOp);
clearOriginOp->RunImmediately();
return clearOriginOp->OnResults();
}
RefPtr<BoolPromise> QuotaManager::ClearStoragesForOriginAttributesPattern(
const OriginAttributesPattern& aPattern) {
AssertIsOnOwningThread();
auto clearDataOp =
CreateClearDataOp(WrapMovingNotNullUnchecked(this), aPattern);
RegisterNormalOriginOp(*clearDataOp);
clearDataOp->RunImmediately();
return clearDataOp->OnResults();
}
RefPtr<BoolPromise> QuotaManager::ClearPrivateRepository() {
AssertIsOnOwningThread();

Просмотреть файл

@ -458,7 +458,8 @@ class ClearStorageOp final
void CloseDirectory() override;
};
class ClearRequestBase : public OpenStorageDirectoryHelper<QuotaRequestBase> {
class ClearRequestBase
: public OpenStorageDirectoryHelper<ResolvableNormalOriginOp<bool>> {
protected:
ClearRequestBase(MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const char* aName)
@ -479,7 +480,10 @@ class ClearOriginOp final : public ClearRequestBase {
public:
ClearOriginOp(MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const RequestParams& aParams);
const mozilla::Maybe<PersistenceType>& aPersistenceType,
const PrincipalInfo& aPrincipalInfo,
const mozilla::Maybe<Client::Type>& aClientType,
const bool& aClearAll);
private:
~ClearOriginOp() = default;
@ -488,7 +492,7 @@ class ClearOriginOp final : public ClearRequestBase {
nsresult DoDirectoryWork(QuotaManager& aQuotaManager) override;
void GetResponse(RequestResponse& aResponse) override;
bool GetResolveValue() override;
void CloseDirectory() override;
};
@ -498,7 +502,7 @@ class ClearDataOp final : public ClearRequestBase {
public:
ClearDataOp(MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const RequestParams& aParams);
const OriginAttributesPattern& aPattern);
private:
~ClearDataOp() = default;
@ -507,7 +511,7 @@ class ClearDataOp final : public ClearRequestBase {
nsresult DoDirectoryWork(QuotaManager& aQuotaManager) override;
void GetResponse(RequestResponse& aResponse) override;
bool GetResolveValue() override;
void CloseDirectory() override;
};
@ -717,16 +721,19 @@ RefPtr<ResolvableNormalOriginOp<bool>> CreateClearStorageOp(
return MakeRefPtr<ClearStorageOp>(std::move(aQuotaManager));
}
RefPtr<QuotaRequestBase> CreateClearOriginOp(
RefPtr<ResolvableNormalOriginOp<bool>> CreateClearOriginOp(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const RequestParams& aParams) {
return MakeRefPtr<ClearOriginOp>(std::move(aQuotaManager), aParams);
const Maybe<PersistenceType>& aPersistenceType,
const PrincipalInfo& aPrincipalInfo, const Maybe<Client::Type>& aClientType,
const bool& aClearAll) {
return MakeRefPtr<ClearOriginOp>(std::move(aQuotaManager), aPersistenceType,
aPrincipalInfo, aClientType, aClearAll);
}
RefPtr<QuotaRequestBase> CreateClearDataOp(
RefPtr<ResolvableNormalOriginOp<bool>> CreateClearDataOp(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const RequestParams& aParams) {
return MakeRefPtr<ClearDataOp>(std::move(aQuotaManager), aParams);
const OriginAttributesPattern& aPattern) {
return MakeRefPtr<ClearDataOp>(std::move(aQuotaManager), aPattern);
}
RefPtr<QuotaRequestBase> CreateResetOriginOp(
@ -1891,31 +1898,28 @@ void ClearRequestBase::DeleteFiles(QuotaManager& aQuotaManager,
"ClearRequestBase: Completed deleting files"_ns);
}
ClearOriginOp::ClearOriginOp(MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const RequestParams& aParams)
ClearOriginOp::ClearOriginOp(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const mozilla::Maybe<PersistenceType>& aPersistenceType,
const PrincipalInfo& aPrincipalInfo,
const mozilla::Maybe<Client::Type>& aClientType, const bool& aClearAll)
: ClearRequestBase(std::move(aQuotaManager), "dom::quota::ClearOriginOp") {
MOZ_ASSERT(aParams.type() == RequestParams::TClearOriginParams);
const ClearOriginParams& params = aParams.get_ClearOriginParams();
const ClearResetOriginParams& commonParams = params.commonParams();
// Figure out which origin we're dealing with.
const auto origin = QuotaManager::GetOriginFromValidatedPrincipalInfo(
commonParams.principalInfo());
const auto origin =
QuotaManager::GetOriginFromValidatedPrincipalInfo(aPrincipalInfo);
if (params.matchAll()) {
if (aClearAll) {
mOriginScope.SetFromPrefix(origin);
} else {
mOriginScope.SetFromOrigin(origin);
}
if (commonParams.persistenceTypeIsExplicit()) {
mPersistenceType.SetValue(commonParams.persistenceType());
if (aPersistenceType) {
mPersistenceType.SetValue(*aPersistenceType);
}
if (commonParams.clientTypeIsExplicit()) {
mClientType.SetValue(commonParams.clientType());
if (aClientType) {
mClientType.SetValue(*aClientType);
}
}
@ -1944,10 +1948,10 @@ nsresult ClearOriginOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
return NS_OK;
}
void ClearOriginOp::GetResponse(RequestResponse& aResponse) {
bool ClearOriginOp::GetResolveValue() {
AssertIsOnOwningThread();
aResponse = ClearOriginResponse();
return true;
}
void ClearOriginOp::CloseDirectory() {
@ -1957,11 +1961,9 @@ void ClearOriginOp::CloseDirectory() {
}
ClearDataOp::ClearDataOp(MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const RequestParams& aParams)
const OriginAttributesPattern& aPattern)
: ClearRequestBase(std::move(aQuotaManager), "dom::quota::ClearDataOp"),
mPattern(aParams.get_ClearDataParams().pattern()) {
MOZ_ASSERT(aParams.type() == RequestParams::TClearDataParams);
}
mPattern(aPattern) {}
RefPtr<BoolPromise> ClearDataOp::OpenDirectory() {
AssertIsOnOwningThread();
@ -1985,10 +1987,10 @@ nsresult ClearDataOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
return NS_OK;
}
void ClearDataOp::GetResponse(RequestResponse& aResponse) {
bool ClearDataOp::GetResolveValue() {
AssertIsOnOwningThread();
aResponse = ClearDataResponse();
return true;
}
void ClearDataOp::CloseDirectory() {
@ -2033,9 +2035,9 @@ nsresult ResetOriginOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
AUTO_PROFILER_LABEL("ResetOriginOp::DoDirectoryWork", OTHER);
// All the work is handled by NormalOriginOperationBase parent class. In this
// particular case, we just needed to acquire an exclusive directory lock and
// that's it.
// All the work is handled by NormalOriginOperationBase parent class. In
// this particular case, we just needed to acquire an exclusive directory
// lock and that's it.
return NS_OK;
}
@ -2162,8 +2164,8 @@ nsresult PersistOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
AUTO_PROFILER_LABEL("PersistOp::DoDirectoryWork", OTHER);
// Update directory metadata on disk first. Then, create/update the originInfo
// if needed.
// Update directory metadata on disk first. Then, create/update the
// originInfo if needed.
QM_TRY_INSPECT(const auto& directory,
aQuotaManager.GetOriginDirectory(originMetadata));
@ -2265,8 +2267,8 @@ nsresult EstimateOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
// Ensure temporary storage is initialized. If temporary storage hasn't been
// initialized yet, the method will initialize it by traversing the
// repositories for temporary and default storage (including origins belonging
// to our group).
// repositories for temporary and default storage (including origins
// belonging to our group).
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureTemporaryStorageIsInitialized()));
// Get cached usage (the method doesn't have to stat any files).
@ -2318,8 +2320,8 @@ nsresult ListOriginsOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
}
// TraverseRepository above only consulted the file-system to get a list of
// known origins, but we also need to include origins that have pending quota
// usage.
// known origins, but we also need to include origins that have pending
// quota usage.
aQuotaManager.CollectPendingOriginsForListing([this](const auto& originInfo) {
mOrigins.AppendElement(originInfo->Origin());

Просмотреть файл

@ -9,6 +9,8 @@
#include <cstdint>
#include "mozilla/dom/quota/Client.h"
#include "mozilla/dom/quota/PersistenceType.h"
#include "nsTArrayForwardDeclare.h"
template <class T>
@ -16,8 +18,11 @@ class RefPtr;
namespace mozilla {
template <class T>
class Maybe;
template <typename T>
class MovingNotNull;
class OriginAttributesPattern;
namespace dom::quota {
@ -89,13 +94,15 @@ RefPtr<QuotaRequestBase> CreateGetFullOriginMetadataOp(
RefPtr<ResolvableNormalOriginOp<bool>> CreateClearStorageOp(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager);
RefPtr<QuotaRequestBase> CreateClearOriginOp(
RefPtr<ResolvableNormalOriginOp<bool>> CreateClearOriginOp(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const RequestParams& aParams);
const Maybe<PersistenceType>& aPersistenceType,
const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
const Maybe<Client::Type>& aClientType, const bool& aClearAll);
RefPtr<QuotaRequestBase> CreateClearDataOp(
RefPtr<ResolvableNormalOriginOp<bool>> CreateClearDataOp(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
const RequestParams& aParams);
const OriginAttributesPattern& aPattern);
RefPtr<QuotaRequestBase> CreateResetOriginOp(
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,

Просмотреть файл

@ -96,22 +96,11 @@ struct ClearResetOriginParams
bool clientTypeIsExplicit;
};
struct ClearOriginParams
{
ClearResetOriginParams commonParams;
bool matchAll;
};
struct ResetOriginParams
{
ClearResetOriginParams commonParams;
};
struct ClearDataParams
{
OriginAttributesPattern pattern;
};
struct PersistedParams
{
PrincipalInfo principalInfo;
@ -140,9 +129,7 @@ union RequestParams
InitializePersistentOriginParams;
InitializeTemporaryOriginParams;
GetFullOriginMetadataParams;
ClearOriginParams;
ResetOriginParams;
ClearDataParams;
PersistedParams;
PersistParams;
EstimateParams;
@ -167,6 +154,16 @@ parent:
async InitializeStorage()
returns(BoolResponse response);
async ClearStoragesForOrigin(PersistenceType? persistenceType,
PrincipalInfo principalInfo,
Type? clientType,
bool clearAll)
returns(BoolResponse response);
// This can only be called from some other thread in the parent process!
async ClearStoragesForOriginAttributesPattern(OriginAttributesPattern pattern)
returns(BoolResponse response);
async ClearStoragesForPrivateBrowsing()
returns(BoolResponse response);

Просмотреть файл

@ -47,18 +47,10 @@ struct GetFullOriginMetadataResponse
FullOriginMetadata? maybeFullOriginMetadata;
};
struct ClearOriginResponse
{
};
struct ResetOriginResponse
{
};
struct ClearDataResponse
{
};
struct PersistedResponse
{
bool persisted;
@ -89,9 +81,7 @@ union RequestResponse
InitializePersistentOriginResponse;
InitializeTemporaryOriginResponse;
GetFullOriginMetadataResponse;
ClearOriginResponse;
ResetOriginResponse;
ClearDataResponse;
PersistedResponse;
PersistResponse;
EstimateResponse;

Просмотреть файл

@ -52,6 +52,7 @@ class nsPIDOMWindowOuter;
namespace mozilla {
class OriginAttributes;
class OriginAttributesPattern;
namespace ipc {
@ -355,6 +356,14 @@ class QuotaManager final : public BackgroundThreadObject {
nsresult EnsureTemporaryStorageIsInitialized();
RefPtr<BoolPromise> ClearStoragesForOrigin(
const Maybe<PersistenceType>& aPersistenceType,
const PrincipalInfo& aPrincipalInfo,
const Maybe<Client::Type>& aClientType, const bool& aClearAll);
RefPtr<BoolPromise> ClearStoragesForOriginAttributesPattern(
const OriginAttributesPattern& aPattern);
RefPtr<BoolPromise> ClearPrivateRepository();
RefPtr<BoolPromise> ClearStorage();

Просмотреть файл

@ -771,21 +771,16 @@ QuotaManagerService::ClearStoragesForOriginAttributesPattern(
const nsAString& aPattern, nsIQuotaRequest** _retval) {
MOZ_ASSERT(NS_IsMainThread());
QM_TRY(MOZ_TO_RESULT(EnsureBackgroundActor()));
OriginAttributesPattern pattern;
MOZ_ALWAYS_TRUE(pattern.Init(aPattern));
RefPtr<Request> request = new Request();
ClearDataParams params;
params.pattern() = pattern;
RequestInfo info(request, params);
nsresult rv = InitiateRequest(info);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mBackgroundActor->SendClearStoragesForOriginAttributesPattern(pattern)->Then(
GetCurrentSerialEventTarget(), __func__,
BoolResponsePromiseResolveOrRejectCallback(request));
request.forget(_retval);
return NS_OK;
@ -798,35 +793,64 @@ QuotaManagerService::ClearStoragesForPrincipal(
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aPrincipal);
nsCString suffix;
aPrincipal->OriginAttributesRef().CreateSuffix(suffix);
QM_TRY(MOZ_TO_RESULT(EnsureBackgroundActor()));
if (NS_WARN_IF(aClearAll && !suffix.IsEmpty())) {
// The originAttributes should be default originAttributes when the
// aClearAll flag is set.
return NS_ERROR_INVALID_ARG;
}
QM_TRY_INSPECT(
const auto& persistenceType,
([&aPersistenceType]() -> Result<Maybe<PersistenceType>, nsresult> {
if (aPersistenceType.IsVoid()) {
return Maybe<PersistenceType>();
}
RefPtr<Request> request = new Request(aPrincipal);
const auto persistenceType =
PersistenceTypeFromString(aPersistenceType, fallible);
QM_TRY(MOZ_TO_RESULT(persistenceType.isSome()),
Err(NS_ERROR_INVALID_ARG));
ClearResetOriginParams commonParams;
return persistenceType;
}()));
nsresult rv = GetClearResetOriginParams(aPrincipal, aPersistenceType,
aClientType, commonParams);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
QM_TRY_INSPECT(
const auto& principalInfo,
([&aPrincipal, &aClearAll]() -> Result<PrincipalInfo, nsresult> {
if (aClearAll) {
nsCString suffix;
aPrincipal->OriginAttributesRef().CreateSuffix(suffix);
ClearOriginParams params;
params.commonParams() = std::move(commonParams);
params.matchAll() = aClearAll;
QM_TRY(MOZ_TO_RESULT(suffix.IsEmpty()), Err(NS_ERROR_INVALID_ARG));
}
RequestInfo info(request, params);
PrincipalInfo principalInfo;
QM_TRY(MOZ_TO_RESULT(
PrincipalToPrincipalInfo(aPrincipal, &principalInfo)));
rv = InitiateRequest(info);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
QM_TRY(MOZ_TO_RESULT(QuotaManager::IsPrincipalInfoValid(principalInfo)),
Err(NS_ERROR_INVALID_ARG));
return principalInfo;
}()));
QM_TRY_INSPECT(const auto& clientType,
([&aClientType]() -> Result<Maybe<Client::Type>, nsresult> {
if (aClientType.IsVoid()) {
return Maybe<Client::Type>();
}
Client::Type clientType;
QM_TRY(MOZ_TO_RESULT(Client::TypeFromText(
aClientType, clientType, fallible)),
Err(NS_ERROR_INVALID_ARG));
return Some(clientType);
}()));
RefPtr<Request> request = new Request();
mBackgroundActor
->SendClearStoragesForOrigin(persistenceType, principalInfo, clientType,
aClearAll)
->Then(GetCurrentSerialEventTarget(), __func__,
BoolResponsePromiseResolveOrRejectCallback(request));
request.forget(_retval);
return NS_OK;

Просмотреть файл

@ -20,6 +20,13 @@
#include "QuotaRequestBase.h"
#include "QuotaUsageRequestBase.h"
// CUF == CRASH_UNLESS_FUZZING
#define QM_CUF_AND_IPC_FAIL(actor) \
[&_actor = *actor](const auto& aFunc, const auto& aExpr) { \
MOZ_CRASH_UNLESS_FUZZING(); \
return QM_IPC_FAIL(&_actor)(aFunc, aExpr); \
}
namespace mozilla::dom::quota {
using namespace mozilla::ipc;
@ -99,6 +106,17 @@ Quota::Quota()
Quota::~Quota() { MOZ_ASSERT(mActorDestroyed); }
bool Quota::TrustParams() const {
#ifdef DEBUG
// Never trust parameters in DEBUG builds!
bool trustParams = false;
#else
bool trustParams = !BackgroundParent::IsOtherProcessActor(Manager());
#endif
return trustParams;
}
bool Quota::VerifyRequestParams(const UsageRequestParams& aParams) const {
AssertIsOnBackgroundThread();
MOZ_ASSERT(aParams.type() != UsageRequestParams::T__None);
@ -185,33 +203,6 @@ bool Quota::VerifyRequestParams(const RequestParams& aParams) const {
break;
}
case RequestParams::TClearOriginParams: {
const ClearResetOriginParams& params =
aParams.get_ClearOriginParams().commonParams();
if (NS_WARN_IF(
!QuotaManager::IsPrincipalInfoValid(params.principalInfo()))) {
MOZ_CRASH_UNLESS_FUZZING();
return false;
}
if (params.persistenceTypeIsExplicit()) {
if (NS_WARN_IF(!IsValidPersistenceType(params.persistenceType()))) {
MOZ_CRASH_UNLESS_FUZZING();
return false;
}
}
if (params.clientTypeIsExplicit()) {
if (NS_WARN_IF(!Client::IsValidType(params.clientType()))) {
MOZ_CRASH_UNLESS_FUZZING();
return false;
}
}
break;
}
case RequestParams::TResetOriginParams: {
const ClearResetOriginParams& params =
aParams.get_ResetOriginParams().commonParams();
@ -239,15 +230,6 @@ bool Quota::VerifyRequestParams(const RequestParams& aParams) const {
break;
}
case RequestParams::TClearDataParams: {
if (BackgroundParent::IsOtherProcessActor(Manager())) {
MOZ_CRASH_UNLESS_FUZZING();
return false;
}
break;
}
case RequestParams::TListOriginsParams:
break;
@ -311,14 +293,7 @@ PQuotaUsageRequestParent* Quota::AllocPQuotaUsageRequestParent(
return nullptr;
}
#ifdef DEBUG
// Always verify parameters in DEBUG builds!
bool trustParams = false;
#else
bool trustParams = !BackgroundParent::IsOtherProcessActor(Manager());
#endif
if (!trustParams && NS_WARN_IF(!VerifyRequestParams(aParams))) {
if (!TrustParams() && NS_WARN_IF(!VerifyRequestParams(aParams))) {
MOZ_CRASH_UNLESS_FUZZING();
return nullptr;
}
@ -379,14 +354,7 @@ PQuotaRequestParent* Quota::AllocPQuotaRequestParent(
return nullptr;
}
#ifdef DEBUG
// Always verify parameters in DEBUG builds!
bool trustParams = false;
#else
bool trustParams = !BackgroundParent::IsOtherProcessActor(Manager());
#endif
if (!trustParams && NS_WARN_IF(!VerifyRequestParams(aParams))) {
if (!TrustParams() && NS_WARN_IF(!VerifyRequestParams(aParams))) {
MOZ_CRASH_UNLESS_FUZZING();
return nullptr;
}
@ -418,15 +386,9 @@ PQuotaRequestParent* Quota::AllocPQuotaRequestParent(
return CreateGetFullOriginMetadataOp(
quotaManager, aParams.get_GetFullOriginMetadataParams());
case RequestParams::TClearOriginParams:
return CreateClearOriginOp(quotaManager, aParams);
case RequestParams::TResetOriginParams:
return CreateResetOriginOp(quotaManager, aParams);
case RequestParams::TClearDataParams:
return CreateClearDataOp(quotaManager, aParams);
case RequestParams::TPersistedParams:
return CreatePersistedOp(quotaManager, aParams);
@ -493,6 +455,67 @@ mozilla::ipc::IPCResult Quota::RecvInitializeStorage(
return IPC_OK();
}
mozilla::ipc::IPCResult Quota::RecvClearStoragesForOrigin(
const Maybe<PersistenceType>& aPersistenceType,
const PrincipalInfo& aPrincipalInfo, const Maybe<Type>& aClientType,
const bool& aClearAll, ClearStoragesForOriginResolver&& aResolver) {
AssertIsOnBackgroundThread();
QM_TRY(MOZ_TO_RESULT(!QuotaManager::IsShuttingDown()),
ResolveBoolResponseAndReturn(aResolver));
if (!TrustParams()) {
if (aPersistenceType) {
QM_TRY(MOZ_TO_RESULT(IsValidPersistenceType(*aPersistenceType)),
QM_CUF_AND_IPC_FAIL(this));
}
QM_TRY(MOZ_TO_RESULT(QuotaManager::IsPrincipalInfoValid(aPrincipalInfo)),
QM_CUF_AND_IPC_FAIL(this));
if (aClientType) {
QM_TRY(MOZ_TO_RESULT(Client::IsValidType(*aClientType)),
QM_CUF_AND_IPC_FAIL(this));
}
}
QM_TRY_UNWRAP(const NotNull<RefPtr<QuotaManager>> quotaManager,
QuotaManager::GetOrCreate(),
ResolveBoolResponseAndReturn(aResolver));
quotaManager
->ClearStoragesForOrigin(aPersistenceType, aPrincipalInfo, aClientType,
aClearAll)
->Then(GetCurrentSerialEventTarget(), __func__,
BoolPromiseResolveOrRejectCallback(this, std::move(aResolver)));
return IPC_OK();
}
mozilla::ipc::IPCResult Quota::RecvClearStoragesForOriginAttributesPattern(
const OriginAttributesPattern& aPattern,
ClearStoragesForOriginAttributesPatternResolver&& aResolver) {
AssertIsOnBackgroundThread();
QM_TRY(MOZ_TO_RESULT(!QuotaManager::IsShuttingDown()),
ResolveBoolResponseAndReturn(aResolver));
if (!TrustParams()) {
QM_TRY(MOZ_TO_RESULT(!BackgroundParent::IsOtherProcessActor(Manager())),
QM_CUF_AND_IPC_FAIL(this));
}
QM_TRY_UNWRAP(const NotNull<RefPtr<QuotaManager>> quotaManager,
QuotaManager::GetOrCreate(),
ResolveBoolResponseAndReturn(aResolver));
quotaManager->ClearStoragesForOriginAttributesPattern(aPattern)->Then(
GetCurrentSerialEventTarget(), __func__,
BoolPromiseResolveOrRejectCallback(this, std::move(aResolver)));
return IPC_OK();
}
mozilla::ipc::IPCResult Quota::RecvClearStoragesForPrivateBrowsing(
ClearStoragesForPrivateBrowsingResolver&& aResolver) {
AssertIsOnBackgroundThread();
@ -500,9 +523,9 @@ mozilla::ipc::IPCResult Quota::RecvClearStoragesForPrivateBrowsing(
QM_TRY(MOZ_TO_RESULT(!QuotaManager::IsShuttingDown()),
ResolveBoolResponseAndReturn(aResolver));
if (BackgroundParent::IsOtherProcessActor(Manager())) {
MOZ_CRASH_UNLESS_FUZZING();
return IPC_FAIL(this, "Wrong actor");
if (!TrustParams()) {
QM_TRY(MOZ_TO_RESULT(!BackgroundParent::IsOtherProcessActor(Manager())),
QM_CUF_AND_IPC_FAIL(this));
}
QM_TRY_UNWRAP(const NotNull<RefPtr<QuotaManager>> quotaManager,

Просмотреть файл

@ -25,6 +25,8 @@ class Quota final : public PQuotaParent {
private:
~Quota();
bool TrustParams() const;
bool VerifyRequestParams(const UsageRequestParams& aParams) const;
bool VerifyRequestParams(const RequestParams& aParams) const;
@ -53,6 +55,16 @@ class Quota final : public PQuotaParent {
virtual mozilla::ipc::IPCResult RecvInitializeStorage(
InitializeStorageResolver&& aResolver) override;
virtual mozilla::ipc::IPCResult RecvClearStoragesForOrigin(
const Maybe<PersistenceType>& aPersistenceType,
const PrincipalInfo& aPrincipalInfo, const Maybe<Type>& aClientType,
const bool& aClearAll,
ClearStoragesForOriginResolver&& aResolve) override;
virtual mozilla::ipc::IPCResult RecvClearStoragesForOriginAttributesPattern(
const OriginAttributesPattern& aPattern,
ClearStoragesForOriginAttributesPatternResolver&& aResolver) override;
virtual mozilla::ipc::IPCResult RecvClearStoragesForPrivateBrowsing(
ClearStoragesForPrivateBrowsingResolver&& aResolver) override;