From 0d91cacd5b3def03d239e64d6551dfdc66456f97 Mon Sep 17 00:00:00 2001 From: Jan Varga Date: Tue, 5 May 2020 06:25:18 +0000 Subject: [PATCH] Bug 1624802 - Add a method for retrieving storage name in tests; r=dom-workers-and-storage-reviewers,ttung Differential Revision: https://phabricator.services.mozilla.com/D73144 --- dom/quota/ActorsChild.cpp | 14 +++++++ dom/quota/ActorsChild.h | 2 + dom/quota/ActorsParent.cpp | 58 ++++++++++++++++++++++++++++ dom/quota/PQuota.ipdl | 5 +++ dom/quota/PQuotaRequest.ipdl | 6 +++ dom/quota/QuotaManagerService.cpp | 24 ++++++++++++ dom/quota/nsIQuotaManagerService.idl | 9 +++++ 7 files changed, 118 insertions(+) diff --git a/dom/quota/ActorsChild.cpp b/dom/quota/ActorsChild.cpp index fce98f8bce63..bbac274b8f5a 100644 --- a/dom/quota/ActorsChild.cpp +++ b/dom/quota/ActorsChild.cpp @@ -255,6 +255,16 @@ void QuotaRequestChild::HandleResponse(bool aResponse) { mRequest->SetResult(variant); } +void QuotaRequestChild::HandleResponse(const nsAString& aResponse) { + AssertIsOnOwningThread(); + MOZ_ASSERT(mRequest); + + RefPtr variant = new nsVariant(); + variant->SetAsAString(aResponse); + + mRequest->SetResult(variant); +} + void QuotaRequestChild::HandleResponse(const EstimateResponse& aResponse) { AssertIsOnOwningThread(); MOZ_ASSERT(mRequest); @@ -304,6 +314,10 @@ mozilla::ipc::IPCResult QuotaRequestChild::Recv__delete__( HandleResponse(aResponse.get_nsresult()); break; + case RequestResponse::TStorageNameResponse: + HandleResponse(aResponse.get_StorageNameResponse().name()); + break; + case RequestResponse::TStorageInitializedResponse: HandleResponse(aResponse.get_StorageInitializedResponse().initialized()); break; diff --git a/dom/quota/ActorsChild.h b/dom/quota/ActorsChild.h index e1e3a7dc740c..ca24120b565e 100644 --- a/dom/quota/ActorsChild.h +++ b/dom/quota/ActorsChild.h @@ -129,6 +129,8 @@ class QuotaRequestChild final : public PQuotaRequestChild { void HandleResponse(bool aResponse); + void HandleResponse(const nsAString& aResponse); + void HandleResponse(const EstimateResponse& aResponse); void HandleResponse(const nsTArray& aResponse); diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index ac86a8376d80..fde7f1002fa8 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -1490,6 +1490,22 @@ class QuotaRequestBase : public NormalOriginOperationBase, virtual void ActorDestroy(ActorDestroyReason aWhy) override; }; +class StorageNameOp final : public QuotaRequestBase { + nsString mName; + + public: + StorageNameOp(); + + void Init(Quota* aQuota) override; + + private: + ~StorageNameOp() = default; + + nsresult DoDirectoryWork(QuotaManager* aQuotaManager) override; + + void GetResponse(RequestResponse& aResponse) override; +}; + class InitializedRequestBase : public QuotaRequestBase { protected: bool mInitialized; @@ -8608,6 +8624,7 @@ bool Quota::VerifyRequestParams(const RequestParams& aParams) const { MOZ_ASSERT(aParams.type() != RequestParams::T__None); switch (aParams.type()) { + case RequestParams::TStorageNameParams: case RequestParams::TStorageInitializedParams: case RequestParams::TTemporaryStorageInitializedParams: case RequestParams::TInitParams: @@ -8851,6 +8868,10 @@ PQuotaRequestParent* Quota::AllocPQuotaRequestParent( RefPtr actor; switch (aParams.type()) { + case RequestParams::TStorageNameParams: + actor = new StorageNameOp(); + break; + case RequestParams::TStorageInitializedParams: actor = new StorageInitializedOp(); break; @@ -9483,6 +9504,43 @@ void QuotaRequestBase::ActorDestroy(ActorDestroyReason aWhy) { NoteActorDestroyed(); } +StorageNameOp::StorageNameOp() : QuotaRequestBase(/* aExclusive */ false) { + AssertIsOnOwningThread(); + + // Overwrite NormalOriginOperationBase default values. + mNeedsDirectoryLocking = false; + + // Overwrite OriginOperationBase default values. + mNeedsQuotaManagerInit = true; + mNeedsStorageInit = false; +} + +void StorageNameOp::Init(Quota* aQuota) { + AssertIsOnOwningThread(); + MOZ_ASSERT(aQuota); +} + +nsresult StorageNameOp::DoDirectoryWork(QuotaManager* aQuotaManager) { + AssertIsOnIOThread(); + MOZ_ASSERT(aQuotaManager); + + AUTO_PROFILER_LABEL("StorageNameOp::DoDirectoryWork", OTHER); + + mName = aQuotaManager->GetStorageName(); + + return NS_OK; +} + +void StorageNameOp::GetResponse(RequestResponse& aResponse) { + AssertIsOnOwningThread(); + + StorageNameResponse storageNameResponse; + + storageNameResponse.name() = mName; + + aResponse = storageNameResponse; +} + InitializedRequestBase::InitializedRequestBase() : QuotaRequestBase(/* aExclusive */ false), mInitialized(false) { AssertIsOnOwningThread(); diff --git a/dom/quota/PQuota.ipdl b/dom/quota/PQuota.ipdl index 598c3d34b6c0..47681b8ca193 100644 --- a/dom/quota/PQuota.ipdl +++ b/dom/quota/PQuota.ipdl @@ -26,6 +26,10 @@ namespace mozilla { namespace dom { namespace quota { +struct StorageNameParams +{ +}; + struct StorageInitializedParams { }; @@ -121,6 +125,7 @@ struct ListOriginsParams union RequestParams { + StorageNameParams; StorageInitializedParams; TemporaryStorageInitializedParams; InitParams; diff --git a/dom/quota/PQuotaRequest.ipdl b/dom/quota/PQuotaRequest.ipdl index a97d9510db05..0d30b3a662c6 100644 --- a/dom/quota/PQuotaRequest.ipdl +++ b/dom/quota/PQuotaRequest.ipdl @@ -8,6 +8,11 @@ namespace mozilla { namespace dom { namespace quota { +struct StorageNameResponse +{ + nsString name; +}; + struct StorageInitializedResponse { bool initialized; @@ -74,6 +79,7 @@ struct ListOriginsResponse union RequestResponse { nsresult; + StorageNameResponse; StorageInitializedResponse; TemporaryStorageInitializedResponse; InitResponse; diff --git a/dom/quota/QuotaManagerService.cpp b/dom/quota/QuotaManagerService.cpp index d9a9ea4ef1dc..34febbc0ce2e 100644 --- a/dom/quota/QuotaManagerService.cpp +++ b/dom/quota/QuotaManagerService.cpp @@ -382,6 +382,30 @@ NS_IMPL_RELEASE_WITH_DESTROY(QuotaManagerService, Destroy()) NS_IMPL_QUERY_INTERFACE(QuotaManagerService, nsIQuotaManagerService, nsIObserver) +NS_IMETHODIMP +QuotaManagerService::StorageName(nsIQuotaRequest** _retval) { + MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(nsContentUtils::IsCallerChrome()); + + if (NS_WARN_IF(!StaticPrefs::dom_quotaManager_testing())) { + return NS_ERROR_UNEXPECTED; + } + + RefPtr request = new Request(); + + StorageNameParams params; + + RequestInfo info(request, params); + + nsresult rv = InitiateRequest(info); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + + request.forget(_retval); + return NS_OK; +} + NS_IMETHODIMP QuotaManagerService::StorageInitialized(nsIQuotaRequest** _retval) { MOZ_ASSERT(NS_IsMainThread()); diff --git a/dom/quota/nsIQuotaManagerService.idl b/dom/quota/nsIQuotaManagerService.idl index ea02f899a3b1..357239e27d79 100644 --- a/dom/quota/nsIQuotaManagerService.idl +++ b/dom/quota/nsIQuotaManagerService.idl @@ -15,6 +15,15 @@ interface nsIQuotaUsageRequest; [scriptable, builtinclass, uuid(1b3d0a38-8151-4cf9-89fa-4f92c2ef0e7e)] interface nsIQuotaManagerService : nsISupports { + /** + * Asynchronously retrieves storage name and returns it as a plain string. + * + * If the dom.quotaManager.testing preference is not true the call will be + * a no-op. + */ + [must_use] nsIQuotaRequest + storageName(); + /** * Check if storage is initialized. *