2015-11-22 12:43:55 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "ActorsChild.h"
|
|
|
|
|
2017-03-06 20:39:29 +03:00
|
|
|
#include "nsVariant.h"
|
2015-11-22 12:43:55 +03:00
|
|
|
#include "QuotaManagerService.h"
|
|
|
|
#include "QuotaRequests.h"
|
2017-03-22 14:13:38 +03:00
|
|
|
#include "QuotaResults.h"
|
2015-11-22 12:43:55 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace quota {
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* QuotaChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
QuotaChild::QuotaChild(QuotaManagerService* aService)
|
|
|
|
: mService(aService)
|
|
|
|
#ifdef DEBUG
|
2017-06-01 23:42:05 +03:00
|
|
|
,
|
|
|
|
mOwningThread(GetCurrentThreadEventTarget())
|
2015-11-22 12:43:55 +03:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aService);
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(quota::QuotaChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
QuotaChild::~QuotaChild() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(quota::QuotaChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void QuotaChild::AssertIsOnOwningThread() const {
|
|
|
|
MOZ_ASSERT(mOwningThread);
|
|
|
|
|
|
|
|
bool current;
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(mOwningThread->IsOnCurrentThread(¤t)));
|
|
|
|
MOZ_ASSERT(current);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
void QuotaChild::ActorDestroy(ActorDestroyReason aWhy) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mService) {
|
|
|
|
mService->ClearBackgroundActor();
|
|
|
|
#ifdef DEBUG
|
|
|
|
mService = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PQuotaUsageRequestChild* QuotaChild::AllocPQuotaUsageRequestChild(
|
|
|
|
const UsageRequestParams& aParams) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_CRASH("PQuotaUsageRequestChild actors should be manually constructed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QuotaChild::DeallocPQuotaUsageRequestChild(
|
|
|
|
PQuotaUsageRequestChild* aActor) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<QuotaUsageRequestChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PQuotaRequestChild* QuotaChild::AllocPQuotaRequestChild(
|
|
|
|
const RequestParams& aParams) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_CRASH("PQuotaRequestChild actors should be manually constructed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QuotaChild::DeallocPQuotaRequestChild(PQuotaRequestChild* aActor) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
|
|
|
delete static_cast<QuotaRequestChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* QuotaUsageRequestChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
QuotaUsageRequestChild::QuotaUsageRequestChild(UsageRequest* aRequest)
|
|
|
|
: mRequest(aRequest) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(quota::QuotaUsageRequestChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
QuotaUsageRequestChild::~QuotaUsageRequestChild() {
|
|
|
|
// Can't assert owning thread here because the request is cleared.
|
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(quota::QuotaUsageRequestChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void QuotaUsageRequestChild::AssertIsOnOwningThread() const {
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
mRequest->AssertIsOnOwningThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
void QuotaUsageRequestChild::HandleResponse(nsresult aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(NS_FAILED(aResponse));
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
mRequest->SetError(aResponse);
|
|
|
|
}
|
|
|
|
|
2017-03-22 14:14:04 +03:00
|
|
|
void QuotaUsageRequestChild::HandleResponse(
|
|
|
|
const nsTArray<OriginUsage>& aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
RefPtr<nsVariant> variant = new nsVariant();
|
|
|
|
|
|
|
|
if (aResponse.IsEmpty()) {
|
|
|
|
variant->SetAsEmptyArray();
|
|
|
|
} else {
|
|
|
|
nsTArray<RefPtr<UsageResult>> usageResults;
|
|
|
|
|
|
|
|
const uint32_t count = aResponse.Length();
|
|
|
|
|
|
|
|
usageResults.SetCapacity(count);
|
|
|
|
|
|
|
|
for (uint32_t index = 0; index < count; index++) {
|
|
|
|
auto& originUsage = aResponse[index];
|
|
|
|
|
|
|
|
RefPtr<UsageResult> usageResult =
|
|
|
|
new UsageResult(originUsage.origin(), originUsage.persisted(),
|
2018-02-20 16:54:17 +03:00
|
|
|
originUsage.usage(), originUsage.lastAccessed());
|
2017-03-22 14:14:04 +03:00
|
|
|
|
|
|
|
usageResults.AppendElement(usageResult.forget());
|
|
|
|
}
|
|
|
|
|
|
|
|
variant->SetAsArray(nsIDataType::VTYPE_INTERFACE_IS,
|
|
|
|
&NS_GET_IID(nsIQuotaUsageResult), usageResults.Length(),
|
|
|
|
static_cast<void*>(usageResults.Elements()));
|
|
|
|
}
|
|
|
|
|
|
|
|
mRequest->SetResult(variant);
|
|
|
|
}
|
|
|
|
|
2017-03-22 14:13:48 +03:00
|
|
|
void QuotaUsageRequestChild::HandleResponse(
|
|
|
|
const OriginUsageResponse& aResponse) {
|
2015-11-22 12:43:55 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
2019-08-22 23:51:09 +03:00
|
|
|
RefPtr<OriginUsageResult> result =
|
|
|
|
new OriginUsageResult(aResponse.usage(), aResponse.fileUsage());
|
2017-03-22 14:13:38 +03:00
|
|
|
|
|
|
|
RefPtr<nsVariant> variant = new nsVariant();
|
2017-03-22 14:13:48 +03:00
|
|
|
variant->SetAsInterface(NS_GET_IID(nsIQuotaOriginUsageResult), result);
|
2017-03-22 14:13:38 +03:00
|
|
|
|
|
|
|
mRequest->SetResult(variant);
|
2015-11-22 12:43:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void QuotaUsageRequestChild::ActorDestroy(ActorDestroyReason aWhy) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mRequest) {
|
|
|
|
mRequest->ClearBackgroundActor();
|
|
|
|
#ifdef DEBUG
|
|
|
|
mRequest = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult QuotaUsageRequestChild::Recv__delete__(
|
|
|
|
const UsageRequestResponse& aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
switch (aResponse.type()) {
|
|
|
|
case UsageRequestResponse::Tnsresult:
|
|
|
|
HandleResponse(aResponse.get_nsresult());
|
|
|
|
break;
|
|
|
|
|
2017-03-22 14:14:04 +03:00
|
|
|
case UsageRequestResponse::TAllUsageResponse:
|
|
|
|
HandleResponse(aResponse.get_AllUsageResponse().originUsages());
|
|
|
|
break;
|
|
|
|
|
2017-03-22 14:13:48 +03:00
|
|
|
case UsageRequestResponse::TOriginUsageResponse:
|
|
|
|
HandleResponse(aResponse.get_OriginUsageResponse());
|
2015-11-22 12:43:55 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown response type!");
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-11-22 12:43:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* QuotaRequestChild
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
QuotaRequestChild::QuotaRequestChild(Request* aRequest) : mRequest(aRequest) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(quota::QuotaRequestChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
QuotaRequestChild::~QuotaRequestChild() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(quota::QuotaRequestChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void QuotaRequestChild::AssertIsOnOwningThread() const {
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
mRequest->AssertIsOnOwningThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
void QuotaRequestChild::HandleResponse(nsresult aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(NS_FAILED(aResponse));
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
mRequest->SetError(aResponse);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QuotaRequestChild::HandleResponse() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
2017-03-06 20:39:29 +03:00
|
|
|
RefPtr<nsVariant> variant = new nsVariant();
|
|
|
|
variant->SetAsVoid();
|
|
|
|
|
|
|
|
mRequest->SetResult(variant);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QuotaRequestChild::HandleResponse(bool aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
RefPtr<nsVariant> variant = new nsVariant();
|
|
|
|
variant->SetAsBool(aResponse);
|
|
|
|
|
|
|
|
mRequest->SetResult(variant);
|
2015-11-22 12:43:55 +03:00
|
|
|
}
|
|
|
|
|
2019-08-22 23:51:09 +03:00
|
|
|
void QuotaRequestChild::HandleResponse(const EstimateResponse& aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
RefPtr<EstimateResult> result =
|
|
|
|
new EstimateResult(aResponse.usage(), aResponse.limit());
|
|
|
|
|
|
|
|
RefPtr<nsVariant> variant = new nsVariant();
|
|
|
|
variant->SetAsInterface(NS_GET_IID(nsIQuotaEstimateResult), result);
|
|
|
|
|
|
|
|
mRequest->SetResult(variant);
|
|
|
|
}
|
|
|
|
|
2019-03-20 20:54:08 +03:00
|
|
|
void QuotaRequestChild::HandleResponse(const nsTArray<nsCString>& aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
RefPtr<nsVariant> variant = new nsVariant();
|
|
|
|
|
|
|
|
if (aResponse.IsEmpty()) {
|
|
|
|
variant->SetAsEmptyArray();
|
|
|
|
} else {
|
2019-10-02 10:57:52 +03:00
|
|
|
nsTArray<RefPtr<OriginsResult>> originsResults(aResponse.Length());
|
2019-03-20 20:54:08 +03:00
|
|
|
for (auto& origin : aResponse) {
|
2019-10-02 10:57:52 +03:00
|
|
|
RefPtr<OriginsResult> originsResult = new OriginsResult(origin);
|
2019-03-20 20:54:08 +03:00
|
|
|
|
2019-10-02 10:57:52 +03:00
|
|
|
originsResults.AppendElement(originsResult.forget());
|
2019-03-20 20:54:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
variant->SetAsArray(
|
2019-10-02 10:57:52 +03:00
|
|
|
nsIDataType::VTYPE_INTERFACE_IS, &NS_GET_IID(nsIQuotaOriginsResult),
|
|
|
|
originsResults.Length(), static_cast<void*>(originsResults.Elements()));
|
2019-03-20 20:54:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mRequest->SetResult(variant);
|
|
|
|
}
|
|
|
|
|
2015-11-22 12:43:55 +03:00
|
|
|
void QuotaRequestChild::ActorDestroy(ActorDestroyReason aWhy) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult QuotaRequestChild::Recv__delete__(
|
|
|
|
const RequestResponse& aResponse) {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
switch (aResponse.type()) {
|
|
|
|
case RequestResponse::Tnsresult:
|
|
|
|
HandleResponse(aResponse.get_nsresult());
|
|
|
|
break;
|
|
|
|
|
2017-03-06 20:39:21 +03:00
|
|
|
case RequestResponse::TInitResponse:
|
2018-10-02 17:08:43 +03:00
|
|
|
case RequestResponse::TInitTemporaryStorageResponse:
|
2015-11-22 12:43:55 +03:00
|
|
|
case RequestResponse::TClearOriginResponse:
|
2018-11-29 23:48:11 +03:00
|
|
|
case RequestResponse::TResetOriginResponse:
|
2017-03-06 20:39:25 +03:00
|
|
|
case RequestResponse::TClearDataResponse:
|
2015-11-22 12:43:55 +03:00
|
|
|
case RequestResponse::TClearAllResponse:
|
|
|
|
case RequestResponse::TResetAllResponse:
|
2016-08-25 05:19:31 +03:00
|
|
|
case RequestResponse::TPersistResponse:
|
2015-11-22 12:43:55 +03:00
|
|
|
HandleResponse();
|
|
|
|
break;
|
|
|
|
|
2019-11-25 18:04:43 +03:00
|
|
|
case RequestResponse::TInitStorageAndOriginResponse:
|
|
|
|
HandleResponse(aResponse.get_InitStorageAndOriginResponse().created());
|
2017-03-06 20:39:33 +03:00
|
|
|
break;
|
|
|
|
|
2016-08-25 05:19:31 +03:00
|
|
|
case RequestResponse::TPersistedResponse:
|
|
|
|
HandleResponse(aResponse.get_PersistedResponse().persisted());
|
|
|
|
break;
|
|
|
|
|
2019-08-22 23:51:09 +03:00
|
|
|
case RequestResponse::TEstimateResponse:
|
|
|
|
HandleResponse(aResponse.get_EstimateResponse());
|
|
|
|
break;
|
|
|
|
|
2019-10-02 10:57:52 +03:00
|
|
|
case RequestResponse::TListOriginsResponse:
|
|
|
|
HandleResponse(aResponse.get_ListOriginsResponse().origins());
|
2019-03-20 20:54:08 +03:00
|
|
|
break;
|
|
|
|
|
2015-11-22 12:43:55 +03:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown response type!");
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2015-11-22 12:43:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace quota
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|