mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
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
This commit is contained in:
parent
00dceeab95
commit
0d91cacd5b
@ -255,6 +255,16 @@ void QuotaRequestChild::HandleResponse(bool aResponse) {
|
||||
mRequest->SetResult(variant);
|
||||
}
|
||||
|
||||
void QuotaRequestChild::HandleResponse(const nsAString& aResponse) {
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT(mRequest);
|
||||
|
||||
RefPtr<nsVariant> 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;
|
||||
|
@ -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<nsCString>& aResponse);
|
||||
|
@ -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<QuotaRequestBase> 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();
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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> 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());
|
||||
|
@ -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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user