зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1641231 - Split GetUsageForOrigin into a smaller function; r=dom-workers-and-storage-reviewers,sg,janv
Differential Revision: https://phabricator.services.mozilla.com/D77286
This commit is contained in:
Родитель
12150459e9
Коммит
50ef0fddc5
|
@ -1388,6 +1388,11 @@ class QuotaUsageRequestBase : public NormalOriginOperationBase,
|
|||
virtual void GetResponse(UsageRequestResponse& aResponse) = 0;
|
||||
|
||||
private:
|
||||
mozilla::Result<UsageInfo, nsresult> GetUsageForOriginEntries(
|
||||
QuotaManager& aQuotaManager, PersistenceType aPersistenceType,
|
||||
const nsACString& aGroup, const nsACString& aOrigin,
|
||||
nsIDirectoryEnumerator& aEntries, bool aInitialized);
|
||||
|
||||
void SendResults() override;
|
||||
|
||||
// IPDL methods.
|
||||
|
@ -9053,11 +9058,12 @@ Result<UsageInfo, nsresult> QuotaUsageRequestBase::GetUsageForOrigin(
|
|||
return Err(rv);
|
||||
}
|
||||
|
||||
UsageInfo usageInfo;
|
||||
if (!exists || mCanceled) {
|
||||
return UsageInfo();
|
||||
}
|
||||
|
||||
// If the directory exists then enumerate all the files inside, adding up
|
||||
// the sizes to get the final usage statistic.
|
||||
if (exists && !mCanceled) {
|
||||
bool initialized;
|
||||
|
||||
if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
|
||||
|
@ -9072,8 +9078,21 @@ Result<UsageInfo, nsresult> QuotaUsageRequestBase::GetUsageForOrigin(
|
|||
return Err(rv);
|
||||
}
|
||||
|
||||
return GetUsageForOriginEntries(aQuotaManager, aPersistenceType, aGroup,
|
||||
aOrigin, *entries, initialized);
|
||||
}
|
||||
|
||||
Result<UsageInfo, nsresult> QuotaUsageRequestBase::GetUsageForOriginEntries(
|
||||
QuotaManager& aQuotaManager, PersistenceType aPersistenceType,
|
||||
const nsACString& aGroup, const nsACString& aOrigin,
|
||||
nsIDirectoryEnumerator& aEntries, const bool aInitialized) {
|
||||
AssertIsOnIOThread();
|
||||
|
||||
UsageInfo usageInfo;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFile> file;
|
||||
while (NS_SUCCEEDED((rv = entries->GetNextFile(getter_AddRefs(file)))) &&
|
||||
while (NS_SUCCEEDED((rv = aEntries.GetNextFile(getter_AddRefs(file)))) &&
|
||||
file && !mCanceled) {
|
||||
bool isDirectory;
|
||||
rv = file->IsDirectory(&isDirectory);
|
||||
|
@ -9088,16 +9107,12 @@ Result<UsageInfo, nsresult> QuotaUsageRequestBase::GetUsageForOrigin(
|
|||
}
|
||||
|
||||
if (!isDirectory) {
|
||||
// We are maintaining existing behavior here (failing if the origin is
|
||||
// not yet initialized or just continuing otherwise).
|
||||
// We are maintaining existing behavior for unknown files here (just
|
||||
// continuing).
|
||||
// This can possibly be used by developers to add temporary backups into
|
||||
// origin directories without losing get usage functionality.
|
||||
if (IsOriginMetadata(leafName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (IsTempMetadata(leafName)) {
|
||||
if (!initialized) {
|
||||
if (!aInitialized) {
|
||||
rv = file->Remove(/* recursive */ false);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
|
@ -9107,7 +9122,8 @@ Result<UsageInfo, nsresult> QuotaUsageRequestBase::GetUsageForOrigin(
|
|||
continue;
|
||||
}
|
||||
|
||||
if (IsOSMetadata(leafName) || IsDotFile(leafName)) {
|
||||
if (IsOriginMetadata(leafName) || IsOSMetadata(leafName) ||
|
||||
IsDotFile(leafName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -9129,7 +9145,7 @@ Result<UsageInfo, nsresult> QuotaUsageRequestBase::GetUsageForOrigin(
|
|||
Client* client = aQuotaManager.GetClient(clientType);
|
||||
MOZ_ASSERT(client);
|
||||
|
||||
if (initialized) {
|
||||
if (aInitialized) {
|
||||
rv = client->GetUsageForOrigin(aPersistenceType, aGroup, aOrigin,
|
||||
mCanceled, &usageInfo);
|
||||
} else {
|
||||
|
@ -9140,6 +9156,8 @@ Result<UsageInfo, nsresult> QuotaUsageRequestBase::GetUsageForOrigin(
|
|||
return Err(rv);
|
||||
}
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
return usageInfo;
|
||||
|
|
Загрузка…
Ссылка в новой задаче