forked from mirrors/gecko-dev
Bug 1808294 - Extend nsIQuotaOriginUsageResult to match UsageInfo; r=dom-storage-reviewers,jari
Differential Revision: https://phabricator.services.mozilla.com/D166173
This commit is contained in:
parent
850b5077f8
commit
39b44622e6
7 changed files with 145 additions and 31 deletions
|
|
@ -172,7 +172,7 @@ void QuotaUsageRequestChild::HandleResponse(
|
|||
MOZ_ASSERT(mRequest);
|
||||
|
||||
RefPtr<OriginUsageResult> result =
|
||||
new OriginUsageResult(aResponse.usage(), aResponse.fileUsage());
|
||||
new OriginUsageResult(aResponse.usageInfo());
|
||||
|
||||
RefPtr<nsVariant> variant = new nsVariant();
|
||||
variant->SetAsInterface(NS_GET_IID(nsIQuotaOriginUsageResult), result);
|
||||
|
|
|
|||
|
|
@ -244,8 +244,7 @@ class GetOriginUsageOp final
|
|||
: public OpenStorageDirectoryHelper<QuotaUsageRequestBase> {
|
||||
const OriginUsageParams mParams;
|
||||
PrincipalMetadata mPrincipalMetadata;
|
||||
uint64_t mUsage;
|
||||
uint64_t mFileUsage;
|
||||
UsageInfo mUsageInfo;
|
||||
bool mFromMemory;
|
||||
|
||||
public:
|
||||
|
|
@ -1196,9 +1195,7 @@ GetOriginUsageOp::GetOriginUsageOp(
|
|||
const UsageRequestParams& aParams)
|
||||
: OpenStorageDirectoryHelper(std::move(aQuotaManager),
|
||||
"dom::quota::GetOriginUsageOp"),
|
||||
mParams(aParams.get_OriginUsageParams()),
|
||||
mUsage(0),
|
||||
mFileUsage(0) {
|
||||
mParams(aParams.get_OriginUsageParams()) {
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT(aParams.type() == UsageRequestParams::TOriginUsageParams);
|
||||
|
||||
|
|
@ -1231,8 +1228,7 @@ RefPtr<BoolPromise> GetOriginUsageOp::OpenDirectory() {
|
|||
nsresult GetOriginUsageOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
|
||||
AssertIsOnIOThread();
|
||||
aQuotaManager.AssertStorageIsInitializedInternal();
|
||||
MOZ_ASSERT(mUsage == 0);
|
||||
MOZ_ASSERT(mFileUsage == 0);
|
||||
MOZ_ASSERT(mUsageInfo.TotalUsage().isNothing());
|
||||
|
||||
AUTO_PROFILER_LABEL("GetOriginUsageOp::DoDirectoryWork", OTHER);
|
||||
|
||||
|
|
@ -1243,14 +1239,13 @@ nsresult GetOriginUsageOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
|
|||
QM_TRY(MOZ_TO_RESULT(aQuotaManager.EnsureTemporaryStorageIsInitialized()));
|
||||
|
||||
// Get cached usage (the method doesn't have to stat any files). File usage
|
||||
// is not tracked in memory separately, so just add to the total usage.
|
||||
mUsage = aQuotaManager.GetOriginUsage(mPrincipalMetadata);
|
||||
// is not tracked in memory separately, so just add to the database usage.
|
||||
mUsageInfo += DatabaseUsageType(
|
||||
Some(aQuotaManager.GetOriginUsage(mPrincipalMetadata)));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
UsageInfo usageInfo;
|
||||
|
||||
// Add all the persistent/temporary/default storage files we care about.
|
||||
for (const PersistenceType type : kAllPersistenceTypes) {
|
||||
const OriginMetadata originMetadata = {mPrincipalMetadata, type};
|
||||
|
|
@ -1261,12 +1256,9 @@ nsresult GetOriginUsageOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
|
|||
return usageInfoOrErr.unwrapErr();
|
||||
}
|
||||
|
||||
usageInfo += usageInfoOrErr.unwrap();
|
||||
mUsageInfo += usageInfoOrErr.unwrap();
|
||||
}
|
||||
|
||||
mUsage = usageInfo.TotalUsage().valueOr(0);
|
||||
mFileUsage = usageInfo.FileUsage().valueOr(0);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
@ -1275,8 +1267,7 @@ void GetOriginUsageOp::GetResponse(UsageRequestResponse& aResponse) {
|
|||
|
||||
OriginUsageResponse usageResponse;
|
||||
|
||||
usageResponse.usage() = mUsage;
|
||||
usageResponse.fileUsage() = mFileUsage;
|
||||
usageResponse.usageInfo() = mUsageInfo;
|
||||
|
||||
aResponse = usageResponse;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,11 @@
|
|||
|
||||
include protocol PQuota;
|
||||
|
||||
include "mozilla/dom/quota/SerializationHelpers.h";
|
||||
|
||||
using mozilla::dom::quota::UsageInfo
|
||||
from "mozilla/dom/quota/UsageInfo.h";
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace quota {
|
||||
|
|
@ -23,8 +28,7 @@ struct AllUsageResponse
|
|||
|
||||
struct OriginUsageResponse
|
||||
{
|
||||
uint64_t usage;
|
||||
uint64_t fileUsage;
|
||||
UsageInfo usageInfo;
|
||||
};
|
||||
|
||||
union UsageRequestResponse
|
||||
|
|
|
|||
|
|
@ -105,16 +105,16 @@ UsageResult::GetLastAccessed(uint64_t* aLastAccessed) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
OriginUsageResult::OriginUsageResult(uint64_t aUsage, uint64_t aFileUsage)
|
||||
: mUsage(aUsage), mFileUsage(aFileUsage) {}
|
||||
OriginUsageResult::OriginUsageResult(UsageInfo aUsageInfo)
|
||||
: mUsageInfo(aUsageInfo) {}
|
||||
|
||||
NS_IMPL_ISUPPORTS(OriginUsageResult, nsIQuotaOriginUsageResult)
|
||||
|
||||
NS_IMETHODIMP
|
||||
OriginUsageResult::GetUsage(uint64_t* aUsage) {
|
||||
MOZ_ASSERT(aUsage);
|
||||
OriginUsageResult::GetDatabaseUsage(uint64_t* aDatabaseUsage) {
|
||||
MOZ_ASSERT(aDatabaseUsage);
|
||||
|
||||
*aUsage = mUsage;
|
||||
*aDatabaseUsage = mUsageInfo.DatabaseUsage().valueOr(0);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
@ -122,10 +122,44 @@ NS_IMETHODIMP
|
|||
OriginUsageResult::GetFileUsage(uint64_t* aFileUsage) {
|
||||
MOZ_ASSERT(aFileUsage);
|
||||
|
||||
*aFileUsage = mFileUsage;
|
||||
*aFileUsage = mUsageInfo.FileUsage().valueOr(0);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
OriginUsageResult::GetUsage(uint64_t* aUsage) {
|
||||
MOZ_ASSERT(aUsage);
|
||||
|
||||
*aUsage = mUsageInfo.TotalUsage().valueOr(0);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
OriginUsageResult::GetDatabaseUsageIsExplicit(bool* aDatabaseUsageIsExplicit) {
|
||||
MOZ_ASSERT(aDatabaseUsageIsExplicit);
|
||||
|
||||
*aDatabaseUsageIsExplicit = mUsageInfo.DatabaseUsage().isSome();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
OriginUsageResult::GetFileUsageIsExplicit(bool* aFileUsageIsExplicit) {
|
||||
MOZ_ASSERT(aFileUsageIsExplicit);
|
||||
|
||||
*aFileUsageIsExplicit = mUsageInfo.FileUsage().isSome();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
OriginUsageResult::GetTotalUsageIsExplicit(bool* aTotalUsageIsExplicit) {
|
||||
MOZ_ASSERT(aTotalUsageIsExplicit);
|
||||
|
||||
*aTotalUsageIsExplicit = mUsageInfo.TotalUsage().isSome();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
UsageInfo& OriginUsageResult::GetUsageInfo() { return mUsageInfo; }
|
||||
|
||||
EstimateResult::EstimateResult(uint64_t aUsage, uint64_t aLimit)
|
||||
: mUsage(aUsage), mLimit(aLimit) {}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <cstdint>
|
||||
#include "mozilla/dom/quota/CommonMetadata.h"
|
||||
#include "mozilla/dom/quota/UsageInfo.h"
|
||||
#include "nsIQuotaResults.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
|
|
@ -47,11 +48,10 @@ class UsageResult : public nsIQuotaUsageResult {
|
|||
};
|
||||
|
||||
class OriginUsageResult : public nsIQuotaOriginUsageResult {
|
||||
uint64_t mUsage;
|
||||
uint64_t mFileUsage;
|
||||
UsageInfo mUsageInfo;
|
||||
|
||||
public:
|
||||
OriginUsageResult(uint64_t aUsage, uint64_t aFileUsage);
|
||||
explicit OriginUsageResult(UsageInfo aUsageInfo);
|
||||
|
||||
private:
|
||||
virtual ~OriginUsageResult() = default;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include "mozilla/dom/quota/Client.h"
|
||||
#include "mozilla/dom/quota/CommonMetadata.h"
|
||||
#include "mozilla/dom/quota/PersistenceType.h"
|
||||
#include "mozilla/dom/quota/UsageInfo.h"
|
||||
#include "mozilla/OriginAttributes.h"
|
||||
|
||||
namespace IPC {
|
||||
|
|
@ -78,6 +79,70 @@ struct ParamTraits<mozilla::OriginAttributesPattern> {
|
|||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::dom::quota::DatabaseUsageType> {
|
||||
using ParamType = mozilla::dom::quota::DatabaseUsageType;
|
||||
|
||||
static void Write(MessageWriter* aWriter, const ParamType& aParam) {
|
||||
WriteParam(aWriter, aParam.GetValue());
|
||||
}
|
||||
|
||||
static bool Read(MessageReader* aReader, ParamType* aResult) {
|
||||
mozilla::Maybe<uint64_t> value;
|
||||
if (!ReadParam(aReader, &value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*aResult += ParamType(value);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::dom::quota::FileUsageType> {
|
||||
using ParamType = mozilla::dom::quota::FileUsageType;
|
||||
|
||||
static void Write(MessageWriter* aWriter, const ParamType& aParam) {
|
||||
WriteParam(aWriter, aParam.GetValue());
|
||||
}
|
||||
|
||||
static bool Read(MessageReader* aReader, ParamType* aResult) {
|
||||
mozilla::Maybe<uint64_t> value;
|
||||
if (!ReadParam(aReader, &value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*aResult += ParamType(value);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::dom::quota::UsageInfo> {
|
||||
using ParamType = mozilla::dom::quota::UsageInfo;
|
||||
|
||||
static void Write(MessageWriter* aWriter, const ParamType& aParam) {
|
||||
WriteParam(aWriter, aParam.DatabaseUsage());
|
||||
WriteParam(aWriter, aParam.FileUsage());
|
||||
}
|
||||
|
||||
static bool Read(MessageReader* aReader, ParamType* aResult) {
|
||||
mozilla::Maybe<uint64_t> databaseUsage;
|
||||
if (!ReadParam(aReader, &databaseUsage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mozilla::Maybe<uint64_t> fileUsage;
|
||||
if (!ReadParam(aReader, &fileUsage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*aResult += mozilla::dom::quota::DatabaseUsageType(databaseUsage);
|
||||
*aResult += mozilla::dom::quota::FileUsageType(fileUsage);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace IPC
|
||||
|
||||
#endif // mozilla_dom_quota_SerializationHelpers_h
|
||||
|
|
|
|||
|
|
@ -6,6 +6,15 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
%{C++
|
||||
namespace mozilla::dom::quota {
|
||||
class UsageInfo;
|
||||
} // namespace mozilla::dom::quota
|
||||
%}
|
||||
|
||||
[ref] native UsageInfoRef(mozilla::dom::quota::UsageInfo);
|
||||
|
||||
|
||||
[scriptable, function, uuid(4d8def75-014e-404d-bf30-e2f0Bfcf4d89)]
|
||||
interface nsIQuotaFullOriginMetadataResult : nsISupports
|
||||
{
|
||||
|
|
@ -36,12 +45,23 @@ interface nsIQuotaUsageResult : nsISupports
|
|||
readonly attribute unsigned long long lastAccessed;
|
||||
};
|
||||
|
||||
[scriptable, function, uuid(96df03d2-116a-493f-bb0b-118c212a6b32)]
|
||||
[scriptable, builtinclass, function, uuid(96df03d2-116a-493f-bb0b-118c212a6b32)]
|
||||
interface nsIQuotaOriginUsageResult : nsISupports
|
||||
{
|
||||
readonly attribute unsigned long long usage;
|
||||
readonly attribute unsigned long long databaseUsage;
|
||||
|
||||
readonly attribute unsigned long long fileUsage;
|
||||
|
||||
// TODO: Rename to totalUsage.
|
||||
readonly attribute unsigned long long usage;
|
||||
|
||||
readonly attribute boolean databaseUsageIsExplicit;
|
||||
|
||||
readonly attribute boolean fileUsageIsExplicit;
|
||||
|
||||
readonly attribute boolean totalUsageIsExplicit;
|
||||
|
||||
[notxpcom, nostdcall] readonly attribute UsageInfoRef usageInfo;
|
||||
};
|
||||
|
||||
[scriptable, function, uuid(9827fc69-7ea9-48ef-b30d-2e2ae0451ec0)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue