mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-12 00:50:40 +00:00
Bug 1808294 - Rework QuotaManagerService::StorageInitialized and QuotaManager::TemporaryStorageInitialized to use asynchronous messages instead of creating sub actors; r=dom-storage-reviewers,jari
This patch also adds QuotaManager::StorageInitialized and QuotaManager::TemporaryStorageInitialized which can be then used by the QuotaManagerDependencyFixture. Differential Revision: https://phabricator.services.mozilla.com/D191930
This commit is contained in:
parent
3d32b14abc
commit
5405995e1c
@ -352,15 +352,6 @@ mozilla::ipc::IPCResult QuotaRequestChild::Recv__delete__(
|
||||
HandleResponse(aResponse.get_StorageNameResponse().name());
|
||||
break;
|
||||
|
||||
case RequestResponse::TStorageInitializedResponse:
|
||||
HandleResponse(aResponse.get_StorageInitializedResponse().initialized());
|
||||
break;
|
||||
|
||||
case RequestResponse::TTemporaryStorageInitializedResponse:
|
||||
HandleResponse(
|
||||
aResponse.get_TemporaryStorageInitializedResponse().initialized());
|
||||
break;
|
||||
|
||||
case RequestResponse::TInitTemporaryStorageResponse:
|
||||
case RequestResponse::TResetOriginResponse:
|
||||
case RequestResponse::TPersistResponse:
|
||||
|
@ -4940,6 +4940,19 @@ RefPtr<BoolPromise> QuotaManager::InitializeStorage(
|
||||
});
|
||||
}
|
||||
|
||||
RefPtr<BoolPromise> QuotaManager::StorageInitialized() {
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
auto storageInitializedOp =
|
||||
CreateStorageInitializedOp(WrapMovingNotNullUnchecked(this));
|
||||
|
||||
RegisterNormalOriginOp(*storageInitializedOp);
|
||||
|
||||
storageInitializedOp->RunImmediately();
|
||||
|
||||
return storageInitializedOp->OnResults();
|
||||
}
|
||||
|
||||
nsresult QuotaManager::EnsureStorageIsInitializedInternal() {
|
||||
DiagnosticAssertIsOnIOThread();
|
||||
|
||||
@ -5027,6 +5040,19 @@ nsresult QuotaManager::EnsureStorageIsInitializedInternal() {
|
||||
"dom::quota::FirstInitializationAttempt::Storage"_ns, innerFunc);
|
||||
}
|
||||
|
||||
RefPtr<BoolPromise> QuotaManager::TemporaryStorageInitialized() {
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
auto temporaryStorageInitializedOp =
|
||||
CreateTemporaryStorageInitializedOp(WrapMovingNotNullUnchecked(this));
|
||||
|
||||
RegisterNormalOriginOp(*temporaryStorageInitializedOp);
|
||||
|
||||
temporaryStorageInitializedOp->RunImmediately();
|
||||
|
||||
return temporaryStorageInitializedOp->OnResults();
|
||||
}
|
||||
|
||||
RefPtr<UniversalDirectoryLockPromise> QuotaManager::OpenStorageDirectory(
|
||||
const Nullable<PersistenceType>& aPersistenceType,
|
||||
const OriginScope& aOriginScope, const Nullable<Client::Type>& aClientType,
|
||||
|
@ -283,7 +283,7 @@ class StorageNameOp final : public QuotaRequestBase {
|
||||
void CloseDirectory() override;
|
||||
};
|
||||
|
||||
class InitializedRequestBase : public QuotaRequestBase {
|
||||
class InitializedRequestBase : public ResolvableNormalOriginOp<bool> {
|
||||
protected:
|
||||
bool mInitialized;
|
||||
|
||||
@ -308,7 +308,7 @@ class StorageInitializedOp final : public InitializedRequestBase {
|
||||
|
||||
nsresult DoDirectoryWork(QuotaManager& aQuotaManager) override;
|
||||
|
||||
void GetResponse(RequestResponse& aResponse) override;
|
||||
bool GetResolveValue() override;
|
||||
};
|
||||
|
||||
class TemporaryStorageInitializedOp final : public InitializedRequestBase {
|
||||
@ -323,7 +323,7 @@ class TemporaryStorageInitializedOp final : public InitializedRequestBase {
|
||||
|
||||
nsresult DoDirectoryWork(QuotaManager& aQuotaManager) override;
|
||||
|
||||
void GetResponse(RequestResponse& aResponse) override;
|
||||
bool GetResolveValue() override;
|
||||
};
|
||||
|
||||
class InitOp final : public ResolvableNormalOriginOp<bool> {
|
||||
@ -756,12 +756,12 @@ RefPtr<QuotaRequestBase> CreateStorageNameOp(
|
||||
return MakeRefPtr<StorageNameOp>(std::move(aQuotaManager));
|
||||
}
|
||||
|
||||
RefPtr<QuotaRequestBase> CreateStorageInitializedOp(
|
||||
RefPtr<ResolvableNormalOriginOp<bool>> CreateStorageInitializedOp(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager) {
|
||||
return MakeRefPtr<StorageInitializedOp>(std::move(aQuotaManager));
|
||||
}
|
||||
|
||||
RefPtr<QuotaRequestBase> CreateTemporaryStorageInitializedOp(
|
||||
RefPtr<ResolvableNormalOriginOp<bool>> CreateTemporaryStorageInitializedOp(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager) {
|
||||
return MakeRefPtr<TemporaryStorageInitializedOp>(std::move(aQuotaManager));
|
||||
}
|
||||
@ -1381,7 +1381,8 @@ void StorageNameOp::CloseDirectory() { AssertIsOnOwningThread(); }
|
||||
|
||||
InitializedRequestBase::InitializedRequestBase(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager, const char* aName)
|
||||
: QuotaRequestBase(std::move(aQuotaManager), aName), mInitialized(false) {
|
||||
: ResolvableNormalOriginOp(std::move(aQuotaManager), aName),
|
||||
mInitialized(false) {
|
||||
AssertIsOnOwningThread();
|
||||
}
|
||||
|
||||
@ -1403,14 +1404,10 @@ nsresult StorageInitializedOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void StorageInitializedOp::GetResponse(RequestResponse& aResponse) {
|
||||
bool StorageInitializedOp::GetResolveValue() {
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
StorageInitializedResponse storageInitializedResponse;
|
||||
|
||||
storageInitializedResponse.initialized() = mInitialized;
|
||||
|
||||
aResponse = storageInitializedResponse;
|
||||
return mInitialized;
|
||||
}
|
||||
|
||||
nsresult TemporaryStorageInitializedOp::DoDirectoryWork(
|
||||
@ -1424,14 +1421,10 @@ nsresult TemporaryStorageInitializedOp::DoDirectoryWork(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void TemporaryStorageInitializedOp::GetResponse(RequestResponse& aResponse) {
|
||||
bool TemporaryStorageInitializedOp::GetResolveValue() {
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
TemporaryStorageInitializedResponse temporaryStorageInitializedResponse;
|
||||
|
||||
temporaryStorageInitializedResponse.initialized() = mInitialized;
|
||||
|
||||
aResponse = temporaryStorageInitializedResponse;
|
||||
return mInitialized;
|
||||
}
|
||||
|
||||
InitOp::InitOp(MovingNotNull<RefPtr<QuotaManager>> aQuotaManager,
|
||||
|
@ -66,10 +66,10 @@ RefPtr<QuotaUsageRequestBase> CreateGetOriginUsageOp(
|
||||
RefPtr<QuotaRequestBase> CreateStorageNameOp(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager);
|
||||
|
||||
RefPtr<QuotaRequestBase> CreateStorageInitializedOp(
|
||||
RefPtr<ResolvableNormalOriginOp<bool>> CreateStorageInitializedOp(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager);
|
||||
|
||||
RefPtr<QuotaRequestBase> CreateTemporaryStorageInitializedOp(
|
||||
RefPtr<ResolvableNormalOriginOp<bool>> CreateTemporaryStorageInitializedOp(
|
||||
MovingNotNull<RefPtr<QuotaManager>> aQuotaManager);
|
||||
|
||||
RefPtr<ResolvableNormalOriginOp<bool>> CreateInitOp(
|
||||
|
@ -41,14 +41,6 @@ struct StorageNameParams
|
||||
{
|
||||
};
|
||||
|
||||
struct StorageInitializedParams
|
||||
{
|
||||
};
|
||||
|
||||
struct TemporaryStorageInitializedParams
|
||||
{
|
||||
};
|
||||
|
||||
struct InitTemporaryStorageParams
|
||||
{
|
||||
};
|
||||
@ -123,8 +115,6 @@ struct ListOriginsParams
|
||||
union RequestParams
|
||||
{
|
||||
StorageNameParams;
|
||||
StorageInitializedParams;
|
||||
TemporaryStorageInitializedParams;
|
||||
InitTemporaryStorageParams;
|
||||
InitializePersistentOriginParams;
|
||||
InitializeTemporaryOriginParams;
|
||||
@ -151,6 +141,12 @@ parent:
|
||||
|
||||
async PQuotaRequest(RequestParams params);
|
||||
|
||||
async StorageInitialized()
|
||||
returns(BoolResponse response);
|
||||
|
||||
async TemporaryStorageInitialized()
|
||||
returns(BoolResponse response);
|
||||
|
||||
async InitializeStorage()
|
||||
returns(BoolResponse response);
|
||||
|
||||
|
@ -18,16 +18,6 @@ struct StorageNameResponse
|
||||
nsString name;
|
||||
};
|
||||
|
||||
struct StorageInitializedResponse
|
||||
{
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
struct TemporaryStorageInitializedResponse
|
||||
{
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
struct InitTemporaryStorageResponse
|
||||
{
|
||||
};
|
||||
@ -75,8 +65,6 @@ union RequestResponse
|
||||
{
|
||||
nsresult;
|
||||
StorageNameResponse;
|
||||
StorageInitializedResponse;
|
||||
TemporaryStorageInitializedResponse;
|
||||
InitTemporaryStorageResponse;
|
||||
InitializePersistentOriginResponse;
|
||||
InitializeTemporaryOriginResponse;
|
||||
|
@ -322,6 +322,8 @@ class QuotaManager final : public BackgroundThreadObject {
|
||||
RefPtr<BoolPromise> InitializeStorage(
|
||||
RefPtr<UniversalDirectoryLock> aDirectoryLock);
|
||||
|
||||
RefPtr<BoolPromise> StorageInitialized();
|
||||
|
||||
bool IsStorageInitialized() const {
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
@ -341,6 +343,8 @@ class QuotaManager final : public BackgroundThreadObject {
|
||||
}
|
||||
#endif
|
||||
|
||||
RefPtr<BoolPromise> TemporaryStorageInitialized();
|
||||
|
||||
private:
|
||||
nsresult EnsureStorageIsInitializedInternal();
|
||||
|
||||
|
@ -480,16 +480,13 @@ QuotaManagerService::StorageInitialized(nsIQuotaRequest** _retval) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
QM_TRY(MOZ_TO_RESULT(EnsureBackgroundActor()));
|
||||
|
||||
RefPtr<Request> request = new Request();
|
||||
|
||||
StorageInitializedParams params;
|
||||
|
||||
RequestInfo info(request, params);
|
||||
|
||||
nsresult rv = InitiateRequest(info);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
mBackgroundActor->SendStorageInitialized()->Then(
|
||||
GetCurrentSerialEventTarget(), __func__,
|
||||
BoolResponsePromiseResolveOrRejectCallback(request));
|
||||
|
||||
request.forget(_retval);
|
||||
return NS_OK;
|
||||
@ -504,16 +501,13 @@ QuotaManagerService::TemporaryStorageInitialized(nsIQuotaRequest** _retval) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
QM_TRY(MOZ_TO_RESULT(EnsureBackgroundActor()));
|
||||
|
||||
RefPtr<Request> request = new Request();
|
||||
|
||||
TemporaryStorageInitializedParams params;
|
||||
|
||||
RequestInfo info(request, params);
|
||||
|
||||
nsresult rv = InitiateRequest(info);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
mBackgroundActor->SendTemporaryStorageInitialized()->Then(
|
||||
GetCurrentSerialEventTarget(), __func__,
|
||||
BoolResponsePromiseResolveOrRejectCallback(request));
|
||||
|
||||
request.forget(_retval);
|
||||
return NS_OK;
|
||||
|
@ -150,8 +150,6 @@ bool Quota::VerifyRequestParams(const RequestParams& aParams) const {
|
||||
|
||||
switch (aParams.type()) {
|
||||
case RequestParams::TStorageNameParams:
|
||||
case RequestParams::TStorageInitializedParams:
|
||||
case RequestParams::TTemporaryStorageInitializedParams:
|
||||
case RequestParams::TInitTemporaryStorageParams:
|
||||
break;
|
||||
|
||||
@ -367,12 +365,6 @@ PQuotaRequestParent* Quota::AllocPQuotaRequestParent(
|
||||
case RequestParams::TStorageNameParams:
|
||||
return CreateStorageNameOp(quotaManager);
|
||||
|
||||
case RequestParams::TStorageInitializedParams:
|
||||
return CreateStorageInitializedOp(quotaManager);
|
||||
|
||||
case RequestParams::TTemporaryStorageInitializedParams:
|
||||
return CreateTemporaryStorageInitializedOp(quotaManager);
|
||||
|
||||
case RequestParams::TInitTemporaryStorageParams:
|
||||
return CreateInitTemporaryStorageOp(quotaManager);
|
||||
|
||||
@ -437,6 +429,42 @@ bool Quota::DeallocPQuotaRequestParent(PQuotaRequestParent* aActor) {
|
||||
return true;
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult Quota::RecvStorageInitialized(
|
||||
StorageInitializedResolver&& aResolver) {
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
QM_TRY(MOZ_TO_RESULT(!QuotaManager::IsShuttingDown()),
|
||||
ResolveBoolResponseAndReturn(aResolver));
|
||||
|
||||
QM_TRY_UNWRAP(const NotNull<RefPtr<QuotaManager>> quotaManager,
|
||||
QuotaManager::GetOrCreate(),
|
||||
ResolveBoolResponseAndReturn(aResolver));
|
||||
|
||||
quotaManager->StorageInitialized()->Then(
|
||||
GetCurrentSerialEventTarget(), __func__,
|
||||
BoolPromiseResolveOrRejectCallback(this, std::move(aResolver)));
|
||||
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult Quota::RecvTemporaryStorageInitialized(
|
||||
TemporaryStorageInitializedResolver&& aResolver) {
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
QM_TRY(MOZ_TO_RESULT(!QuotaManager::IsShuttingDown()),
|
||||
ResolveBoolResponseAndReturn(aResolver));
|
||||
|
||||
QM_TRY_UNWRAP(const NotNull<RefPtr<QuotaManager>> quotaManager,
|
||||
QuotaManager::GetOrCreate(),
|
||||
ResolveBoolResponseAndReturn(aResolver));
|
||||
|
||||
quotaManager->TemporaryStorageInitialized()->Then(
|
||||
GetCurrentSerialEventTarget(), __func__,
|
||||
BoolPromiseResolveOrRejectCallback(this, std::move(aResolver)));
|
||||
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult Quota::RecvInitializeStorage(
|
||||
InitializeStorageResolver&& aResolver) {
|
||||
AssertIsOnBackgroundThread();
|
||||
|
@ -52,6 +52,12 @@ class Quota final : public PQuotaParent {
|
||||
|
||||
virtual bool DeallocPQuotaRequestParent(PQuotaRequestParent* aActor) override;
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvStorageInitialized(
|
||||
StorageInitializedResolver&& aResolver) override;
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvTemporaryStorageInitialized(
|
||||
TemporaryStorageInitializedResolver&& aResolver) override;
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvInitializeStorage(
|
||||
InitializeStorageResolver&& aResolver) override;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user