Bug 1910848 - Replace custom OriginUsage with a common OriginUsageMetadata struct; r=dom-storage-reviewers,jari

This is a prerequisite to make GetUsageOp independent from the actor.

Differential Revision: https://phabricator.services.mozilla.com/D194053
This commit is contained in:
Jan Varga 2024-08-07 07:53:13 +00:00
parent 4b2b6abbcb
commit d6b1701348
10 changed files with 88 additions and 22 deletions

View File

@ -125,7 +125,7 @@ void QuotaUsageRequestChild::HandleResponse(nsresult aResponse) {
}
void QuotaUsageRequestChild::HandleResponse(
const nsTArray<OriginUsage>& aResponse) {
const OriginUsageMetadataArray& aResponse) {
AssertIsOnOwningThread();
MOZ_ASSERT(mRequest);
@ -138,8 +138,8 @@ void QuotaUsageRequestChild::HandleResponse(
for (const auto& originUsage : aResponse) {
usageResults.AppendElement(MakeRefPtr<UsageResult>(
originUsage.origin(), originUsage.persisted(), originUsage.usage(),
originUsage.lastAccessed()));
originUsage.mOrigin, originUsage.mPersisted, originUsage.mUsage,
originUsage.mLastAccessTime));
}
variant->SetAsArray(nsIDataType::VTYPE_INTERFACE_IS,
@ -176,7 +176,7 @@ void QuotaUsageRequestChild::ActorDestroy(ActorDestroyReason aWhy) {
}
mozilla::ipc::IPCResult QuotaUsageRequestChild::Recv__delete__(
const UsageRequestResponse& aResponse) {
UsageRequestResponse&& aResponse) {
AssertIsOnOwningThread();
MOZ_ASSERT(mRequest);

View File

@ -95,7 +95,7 @@ class QuotaUsageRequestChild final : public PQuotaUsageRequestChild {
void HandleResponse(nsresult aResponse);
void HandleResponse(const nsTArray<OriginUsage>& aResponse);
void HandleResponse(const OriginUsageMetadataArray& aResponse);
void HandleResponse(const OriginUsageResponse& aResponse);
@ -103,7 +103,7 @@ class QuotaUsageRequestChild final : public PQuotaUsageRequestChild {
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
virtual mozilla::ipc::IPCResult Recv__delete__(
const UsageRequestResponse& aResponse) override;
UsageRequestResponse&& aResponse) override;
};
class QuotaRequestChild final : public PQuotaRequestChild {

View File

@ -77,6 +77,15 @@ struct FullOriginMetadata : OriginMetadata {
mLastAccessTime(aLastAccessTime) {}
};
struct OriginUsageMetadata : FullOriginMetadata {
uint64_t mUsage;
OriginUsageMetadata() = default;
OriginUsageMetadata(FullOriginMetadata aFullOriginMetadata, uint64_t aUsage)
: FullOriginMetadata(std::move(aFullOriginMetadata)), mUsage(aUsage) {}
};
struct ClientMetadata : OriginMetadata {
Client::Type mClientType;

View File

@ -0,0 +1,15 @@
/* -*- 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/. */
#ifndef DOM_QUOTA_COMMONMETADATAARRAY_H_
#define DOM_QUOTA_COMMONMETADATAARRAY_H_
#include "mozilla/dom/quota/CommonMetadataArrayFwd.h"
#include "mozilla/dom/quota/CommonMetadata.h"
#include "nsTArray.h"
#endif // DOM_QUOTA_COMMONMETADATAARRAY_H_

View File

@ -0,0 +1,20 @@
/* -*- 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/. */
#ifndef DOM_QUOTA_COMMONMETADATAARRAYFWD_H_
#define DOM_QUOTA_COMMONMETADATAARRAYFWD_H_
#include "nsTArrayForwardDeclare.h"
namespace mozilla::dom::quota {
struct OriginUsageMetadata;
using OriginUsageMetadataArray = nsTArray<OriginUsageMetadata>;
} // namespace mozilla::dom::quota
#endif // DOM_QUOTA_COMMONMETADATAARRAYFWD_H_

View File

@ -230,7 +230,7 @@ class GetUsageOp final
: public OpenStorageDirectoryHelper<QuotaUsageRequestBase>,
public TraverseRepositoryHelper,
public OriginUsageHelper {
nsTArray<OriginUsage> mOriginUsages;
OriginUsageMetadataArray mOriginUsages;
nsTHashMap<nsCStringHashKey, uint32_t> mOriginUsagesIndex;
bool mGetAll;
@ -1292,17 +1292,24 @@ void GetUsageOp::ProcessOriginInternal(QuotaManager* aQuotaManager,
entry.Insert(mOriginUsages.Length());
return mOriginUsages.EmplaceBack(nsCString{aOrigin}, false, 0, 0);
OriginUsageMetadata metadata;
metadata.mOrigin = aOrigin;
metadata.mPersistenceType = PERSISTENCE_TYPE_DEFAULT;
metadata.mPersisted = false;
metadata.mLastAccessTime = 0;
metadata.mUsage = 0;
return mOriginUsages.EmplaceBack(std::move(metadata));
});
if (aPersistenceType == PERSISTENCE_TYPE_DEFAULT) {
originUsage->persisted() = aPersisted;
originUsage->mPersisted = aPersisted;
}
originUsage->usage() = originUsage->usage() + aUsage;
originUsage->mUsage = originUsage->mUsage + aUsage;
originUsage->lastAccessed() =
std::max<int64_t>(originUsage->lastAccessed(), aTimestamp);
originUsage->mLastAccessTime =
std::max<int64_t>(originUsage->mLastAccessTime, aTimestamp);
}
const Atomic<bool>& GetUsageOp::GetIsCanceledFlag() {

View File

@ -6,6 +6,9 @@ include protocol PQuota;
include "mozilla/dom/quota/SerializationHelpers.h";
[MoveOnly] using mozilla::dom::quota::OriginUsageMetadataArray
from "mozilla/dom/quota/CommonMetadataArray.h";
using mozilla::dom::quota::UsageInfo
from "mozilla/dom/quota/UsageInfo.h";
@ -13,17 +16,9 @@ namespace mozilla {
namespace dom {
namespace quota {
struct OriginUsage
{
nsCString origin;
bool persisted;
uint64_t usage;
uint64_t lastAccessed;
};
struct AllUsageResponse
{
OriginUsage[] originUsages;
OriginUsageMetadataArray originUsages;
};
struct OriginUsageResponse

View File

@ -36,7 +36,8 @@ void QuotaUsageRequestBase::SendResults() {
response = mResultCode;
}
Unused << PQuotaUsageRequestParent::Send__delete__(this, response);
Unused << PQuotaUsageRequestParent::Send__delete__(this,
std::move(response));
}
}

View File

@ -58,6 +58,23 @@ struct ParamTraits<mozilla::dom::quota::FullOriginMetadata> {
}
};
template <>
struct ParamTraits<mozilla::dom::quota::OriginUsageMetadata> {
using ParamType = mozilla::dom::quota::OriginUsageMetadata;
static void Write(MessageWriter* aWriter, const ParamType& aParam) {
ParamTraits<mozilla::dom::quota::FullOriginMetadata>::Write(aWriter,
aParam);
WriteParam(aWriter, aParam.mUsage);
}
static bool Read(MessageReader* aReader, ParamType* aResult) {
return ParamTraits<mozilla::dom::quota::FullOriginMetadata>::Read(
aReader, aResult) &&
ReadParam(aReader, &aResult->mUsage);
}
};
template <>
struct ParamTraits<mozilla::OriginAttributesPattern> {
typedef mozilla::OriginAttributesPattern paramType;

View File

@ -38,6 +38,8 @@ EXPORTS.mozilla.dom.quota += [
"Client.h",
"ClientImpl.h",
"CommonMetadata.h",
"CommonMetadataArray.h",
"CommonMetadataArrayFwd.h",
"Config.h",
"Constants.h",
"DebugOnlyMacro.h",