mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 14:52:16 +00:00
Bug 1641512 - Use Result<UsageInfo, nsresult> as return type of GetUsageForOrigin. r=dom-workers-and-storage-reviewers,janv
Differential Revision: https://phabricator.services.mozilla.com/D77452
This commit is contained in:
parent
09828f53be
commit
c23800e5f2
20
dom/cache/QuotaClient.cpp
vendored
20
dom/cache/QuotaClient.cpp
vendored
@ -220,13 +220,19 @@ nsresult CacheQuotaClient::InitOrigin(PersistenceType aPersistenceType,
|
||||
/* aInitializing*/ true, aUsageInfo);
|
||||
}
|
||||
|
||||
nsresult CacheQuotaClient::GetUsageForOrigin(PersistenceType aPersistenceType,
|
||||
const nsACString& aGroup,
|
||||
const nsACString& aOrigin,
|
||||
const AtomicBool& aCanceled,
|
||||
UsageInfo* aUsageInfo) {
|
||||
return GetUsageForOriginInternal(aPersistenceType, aGroup, aOrigin, aCanceled,
|
||||
/* aInitializing*/ false, aUsageInfo);
|
||||
Result<UsageInfo, nsresult> CacheQuotaClient::GetUsageForOrigin(
|
||||
PersistenceType aPersistenceType, const nsACString& aGroup,
|
||||
const nsACString& aOrigin, const AtomicBool& aCanceled) {
|
||||
UsageInfo res;
|
||||
|
||||
nsresult rv =
|
||||
GetUsageForOriginInternal(aPersistenceType, aGroup, aOrigin, aCanceled,
|
||||
/* aInitializing*/ false, &res);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void CacheQuotaClient::OnOriginClearCompleted(PersistenceType aPersistenceType,
|
||||
|
8
dom/cache/QuotaClientImpl.h
vendored
8
dom/cache/QuotaClientImpl.h
vendored
@ -32,11 +32,9 @@ class CacheQuotaClient final : public quota::Client {
|
||||
const AtomicBool& aCanceled,
|
||||
UsageInfo* aUsageInfo) override;
|
||||
|
||||
virtual nsresult GetUsageForOrigin(PersistenceType aPersistenceType,
|
||||
const nsACString& aGroup,
|
||||
const nsACString& aOrigin,
|
||||
const AtomicBool& aCanceled,
|
||||
UsageInfo* aUsageInfo) override;
|
||||
virtual Result<UsageInfo, nsresult> GetUsageForOrigin(
|
||||
PersistenceType aPersistenceType, const nsACString& aGroup,
|
||||
const nsACString& aOrigin, const AtomicBool& aCanceled) override;
|
||||
|
||||
virtual void OnOriginClearCompleted(PersistenceType aPersistenceType,
|
||||
const nsACString& aOrigin) override;
|
||||
|
@ -8568,11 +8568,9 @@ class QuotaClient final : public mozilla::dom::quota::Client {
|
||||
const AtomicBool& aCanceled,
|
||||
UsageInfo* aUsageInfo) override;
|
||||
|
||||
nsresult GetUsageForOrigin(PersistenceType aPersistenceType,
|
||||
const nsACString& aGroup,
|
||||
const nsACString& aOrigin,
|
||||
const AtomicBool& aCanceled,
|
||||
UsageInfo* aUsageInfo) override;
|
||||
Result<UsageInfo, nsresult> GetUsageForOrigin(
|
||||
PersistenceType aPersistenceType, const nsACString& aGroup,
|
||||
const nsACString& aOrigin, const AtomicBool& aCanceled) override;
|
||||
|
||||
void OnOriginClearCompleted(PersistenceType aPersistenceType,
|
||||
const nsACString& aOrigin) override;
|
||||
@ -17193,16 +17191,21 @@ nsresult QuotaClient::InitOrigin(PersistenceType aPersistenceType,
|
||||
/* aInitializing*/ true, aUsageInfo);
|
||||
}
|
||||
|
||||
nsresult QuotaClient::GetUsageForOrigin(PersistenceType aPersistenceType,
|
||||
const nsACString& aGroup,
|
||||
const nsACString& aOrigin,
|
||||
const AtomicBool& aCanceled,
|
||||
UsageInfo* aUsageInfo) {
|
||||
Result<UsageInfo, nsresult> QuotaClient::GetUsageForOrigin(
|
||||
PersistenceType aPersistenceType, const nsACString& aGroup,
|
||||
const nsACString& aOrigin, const AtomicBool& aCanceled) {
|
||||
AssertIsOnIOThread();
|
||||
MOZ_ASSERT(aUsageInfo);
|
||||
|
||||
return GetUsageForOriginInternal(aPersistenceType, aGroup, aOrigin, aCanceled,
|
||||
/* aInitializing*/ false, aUsageInfo);
|
||||
UsageInfo res;
|
||||
|
||||
nsresult rv =
|
||||
GetUsageForOriginInternal(aPersistenceType, aGroup, aOrigin, aCanceled,
|
||||
/* aInitializing*/ false, &res);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult QuotaClient::GetUsageForOriginInternal(
|
||||
|
@ -2824,11 +2824,9 @@ class QuotaClient final : public mozilla::dom::quota::Client {
|
||||
const AtomicBool& aCanceled,
|
||||
UsageInfo* aUsageInfo) override;
|
||||
|
||||
nsresult GetUsageForOrigin(PersistenceType aPersistenceType,
|
||||
const nsACString& aGroup,
|
||||
const nsACString& aOrigin,
|
||||
const AtomicBool& aCanceled,
|
||||
UsageInfo* aUsageInfo) override;
|
||||
Result<UsageInfo, nsresult> GetUsageForOrigin(
|
||||
PersistenceType aPersistenceType, const nsACString& aGroup,
|
||||
const nsACString& aOrigin, const AtomicBool& aCanceled) override;
|
||||
|
||||
nsresult AboutToClearOrigins(
|
||||
const Nullable<PersistenceType>& aPersistenceType,
|
||||
@ -9062,14 +9060,11 @@ nsresult QuotaClient::InitOrigin(PersistenceType aPersistenceType,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult QuotaClient::GetUsageForOrigin(PersistenceType aPersistenceType,
|
||||
const nsACString& aGroup,
|
||||
const nsACString& aOrigin,
|
||||
const AtomicBool& aCanceled,
|
||||
UsageInfo* aUsageInfo) {
|
||||
Result<UsageInfo, nsresult> QuotaClient::GetUsageForOrigin(
|
||||
PersistenceType aPersistenceType, const nsACString& aGroup,
|
||||
const nsACString& aOrigin, const AtomicBool& aCanceled) {
|
||||
AssertIsOnIOThread();
|
||||
MOZ_ASSERT(aPersistenceType == PERSISTENCE_TYPE_DEFAULT);
|
||||
MOZ_ASSERT(aUsageInfo);
|
||||
|
||||
// We can't open the database at this point, since it can be already used
|
||||
// by the connection thread. Use the cached value instead.
|
||||
@ -9077,13 +9072,14 @@ nsresult QuotaClient::GetUsageForOrigin(PersistenceType aPersistenceType,
|
||||
QuotaManager* quotaManager = QuotaManager::Get();
|
||||
MOZ_ASSERT(quotaManager);
|
||||
|
||||
UsageInfo res;
|
||||
uint64_t usage;
|
||||
if (quotaManager->GetUsageForClient(PERSISTENCE_TYPE_DEFAULT, aGroup, aOrigin,
|
||||
Client::LS, usage)) {
|
||||
aUsageInfo->IncrementDatabaseUsage(Some(usage));
|
||||
res.IncrementDatabaseUsage(Some(usage));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult QuotaClient::AboutToClearOrigins(
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "mozilla/net/MozURL.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/ResultExtensions.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/StaticPrefs_dom.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
@ -9146,16 +9147,20 @@ Result<UsageInfo, nsresult> QuotaUsageRequestBase::GetUsageForOriginEntries(
|
||||
MOZ_ASSERT(client);
|
||||
|
||||
if (aInitialized) {
|
||||
rv = client->GetUsageForOrigin(aPersistenceType, aGroup, aOrigin,
|
||||
mCanceled, &usageInfo);
|
||||
auto usageInfoOrErr = client->GetUsageForOrigin(aPersistenceType, aGroup,
|
||||
aOrigin, mCanceled);
|
||||
if (NS_WARN_IF(usageInfoOrErr.isErr())) {
|
||||
return usageInfoOrErr.propagateErr();
|
||||
}
|
||||
usageInfo += usageInfoOrErr.inspect();
|
||||
} else {
|
||||
rv = client->InitOrigin(aPersistenceType, aGroup, aOrigin, mCanceled,
|
||||
&usageInfo);
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
}
|
||||
|
@ -98,11 +98,9 @@ class Client {
|
||||
const AtomicBool& aCanceled,
|
||||
UsageInfo* aUsageInfo) = 0;
|
||||
|
||||
virtual nsresult GetUsageForOrigin(PersistenceType aPersistenceType,
|
||||
const nsACString& aGroup,
|
||||
const nsACString& aOrigin,
|
||||
const AtomicBool& aCanceled,
|
||||
UsageInfo* aUsageInfo) = 0;
|
||||
virtual Result<UsageInfo, nsresult> GetUsageForOrigin(
|
||||
PersistenceType aPersistenceType, const nsACString& aGroup,
|
||||
const nsACString& aOrigin, const AtomicBool& aCanceled) = 0;
|
||||
|
||||
// This method is called when origins are about to be cleared
|
||||
// (except the case when clearing is triggered by the origin eviction).
|
||||
|
@ -452,11 +452,9 @@ class QuotaClient final : public mozilla::dom::quota::Client {
|
||||
const AtomicBool& aCanceled,
|
||||
UsageInfo* aUsageInfo) override;
|
||||
|
||||
nsresult GetUsageForOrigin(PersistenceType aPersistenceType,
|
||||
const nsACString& aGroup,
|
||||
const nsACString& aOrigin,
|
||||
const AtomicBool& aCanceled,
|
||||
UsageInfo* aUsageInfo) override;
|
||||
Result<UsageInfo, nsresult> GetUsageForOrigin(
|
||||
PersistenceType aPersistenceType, const nsACString& aGroup,
|
||||
const nsACString& aOrigin, const AtomicBool& aCanceled) override;
|
||||
|
||||
void OnOriginClearCompleted(PersistenceType aPersistenceType,
|
||||
const nsACString& aOrigin) override;
|
||||
@ -1632,21 +1630,23 @@ nsresult QuotaClient::InitOrigin(PersistenceType aPersistenceType,
|
||||
UsageInfo* aUsageInfo) {
|
||||
AssertIsOnIOThread();
|
||||
|
||||
if (!aUsageInfo) {
|
||||
return NS_OK;
|
||||
if (aUsageInfo) {
|
||||
auto usageInfoOrErr =
|
||||
GetUsageForOrigin(aPersistenceType, aGroup, aOrigin, aCanceled);
|
||||
if (NS_WARN_IF(usageInfoOrErr.isErr())) {
|
||||
return usageInfoOrErr.unwrapErr();
|
||||
}
|
||||
|
||||
return GetUsageForOrigin(aPersistenceType, aGroup, aOrigin, aCanceled,
|
||||
aUsageInfo);
|
||||
*aUsageInfo = usageInfoOrErr.unwrap();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult QuotaClient::GetUsageForOrigin(PersistenceType aPersistenceType,
|
||||
const nsACString& aGroup,
|
||||
const nsACString& aOrigin,
|
||||
const AtomicBool& aCanceled,
|
||||
UsageInfo* aUsageInfo) {
|
||||
Result<UsageInfo, nsresult> QuotaClient::GetUsageForOrigin(
|
||||
PersistenceType aPersistenceType, const nsACString& aGroup,
|
||||
const nsACString& aOrigin, const AtomicBool& aCanceled) {
|
||||
AssertIsOnIOThread();
|
||||
MOZ_ASSERT(aUsageInfo);
|
||||
|
||||
QuotaManager* quotaManager = QuotaManager::Get();
|
||||
MOZ_ASSERT(quotaManager);
|
||||
@ -1655,14 +1655,14 @@ nsresult QuotaClient::GetUsageForOrigin(PersistenceType aPersistenceType,
|
||||
nsresult rv = quotaManager->GetDirectoryForOrigin(aPersistenceType, aOrigin,
|
||||
getter_AddRefs(directory));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(directory);
|
||||
|
||||
rv = directory->Append(NS_LITERAL_STRING(SDB_DIRECTORY_NAME));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
DebugOnly<bool> exists;
|
||||
@ -1671,16 +1671,17 @@ nsresult QuotaClient::GetUsageForOrigin(PersistenceType aPersistenceType,
|
||||
nsCOMPtr<nsIDirectoryEnumerator> entries;
|
||||
rv = directory->GetDirectoryEntries(getter_AddRefs(entries));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
UsageInfo res;
|
||||
bool hasMore;
|
||||
while (NS_SUCCEEDED((rv = entries->HasMoreElements(&hasMore))) && hasMore &&
|
||||
!aCanceled) {
|
||||
nsCOMPtr<nsISupports> entry;
|
||||
rv = entries->GetNext(getter_AddRefs(entry));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFile> file = do_QueryInterface(entry);
|
||||
@ -1689,19 +1690,19 @@ nsresult QuotaClient::GetUsageForOrigin(PersistenceType aPersistenceType,
|
||||
nsAutoString leafName;
|
||||
rv = file->GetLeafName(leafName);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
if (StringEndsWith(leafName, kSDBSuffix)) {
|
||||
int64_t fileSize;
|
||||
rv = file->GetFileSize(&fileSize);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(fileSize >= 0);
|
||||
|
||||
aUsageInfo->IncrementDatabaseUsage(Some(uint64_t(fileSize)));
|
||||
res.IncrementDatabaseUsage(Some(uint64_t(fileSize)));
|
||||
|
||||
continue;
|
||||
}
|
||||
@ -1709,10 +1710,10 @@ nsresult QuotaClient::GetUsageForOrigin(PersistenceType aPersistenceType,
|
||||
UNKNOWN_FILE_WARNING(leafName);
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
return res;
|
||||
}
|
||||
|
||||
void QuotaClient::OnOriginClearCompleted(PersistenceType aPersistenceType,
|
||||
|
Loading…
Reference in New Issue
Block a user