зеркало из 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,93 +9058,106 @@ 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;
|
||||
bool initialized;
|
||||
|
||||
if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
|
||||
initialized = aQuotaManager.IsOriginInitialized(aOrigin);
|
||||
} else {
|
||||
initialized = aQuotaManager.IsTemporaryStorageInitialized();
|
||||
}
|
||||
if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
|
||||
initialized = aQuotaManager.IsOriginInitialized(aOrigin);
|
||||
} else {
|
||||
initialized = aQuotaManager.IsTemporaryStorageInitialized();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDirectoryEnumerator> entries;
|
||||
rv = directory->GetDirectoryEntries(getter_AddRefs(entries));
|
||||
nsCOMPtr<nsIDirectoryEnumerator> entries;
|
||||
rv = directory->GetDirectoryEntries(getter_AddRefs(entries));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
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 = aEntries.GetNextFile(getter_AddRefs(file)))) &&
|
||||
file && !mCanceled) {
|
||||
bool isDirectory;
|
||||
rv = file->IsDirectory(&isDirectory);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFile> file;
|
||||
while (NS_SUCCEEDED((rv = entries->GetNextFile(getter_AddRefs(file)))) &&
|
||||
file && !mCanceled) {
|
||||
bool isDirectory;
|
||||
rv = file->IsDirectory(&isDirectory);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
nsString leafName;
|
||||
rv = file->GetLeafName(leafName);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
if (!isDirectory) {
|
||||
// We are maintaining existing behavior here (failing if the origin is
|
||||
// not yet initialized or just continuing otherwise).
|
||||
// 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) {
|
||||
rv = file->Remove(/* recursive */ false);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (IsOSMetadata(leafName) || IsDotFile(leafName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Unknown files during getting usage for an origin (even for an
|
||||
// uninitialized origin) are now allowed. Just warn if we find them.
|
||||
UNKNOWN_FILE_WARNING(leafName);
|
||||
continue;
|
||||
}
|
||||
|
||||
Client::Type clientType;
|
||||
bool ok = Client::TypeFromText(leafName, clientType, fallible);
|
||||
if (!ok) {
|
||||
// Unknown directories during getting usage for an origin (even for an
|
||||
// uninitialized origin) are now allowed. Just warn if we find them.
|
||||
UNKNOWN_FILE_WARNING(leafName);
|
||||
continue;
|
||||
}
|
||||
|
||||
Client* client = aQuotaManager.GetClient(clientType);
|
||||
MOZ_ASSERT(client);
|
||||
|
||||
if (initialized) {
|
||||
rv = client->GetUsageForOrigin(aPersistenceType, aGroup, aOrigin,
|
||||
mCanceled, &usageInfo);
|
||||
} else {
|
||||
rv = client->InitOrigin(aPersistenceType, aGroup, aOrigin, mCanceled,
|
||||
&usageInfo);
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
}
|
||||
nsString leafName;
|
||||
rv = file->GetLeafName(leafName);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
if (!isDirectory) {
|
||||
// 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 (IsTempMetadata(leafName)) {
|
||||
if (!aInitialized) {
|
||||
rv = file->Remove(/* recursive */ false);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return Err(rv);
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (IsOriginMetadata(leafName) || IsOSMetadata(leafName) ||
|
||||
IsDotFile(leafName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Unknown files during getting usage for an origin (even for an
|
||||
// uninitialized origin) are now allowed. Just warn if we find them.
|
||||
UNKNOWN_FILE_WARNING(leafName);
|
||||
continue;
|
||||
}
|
||||
|
||||
Client::Type clientType;
|
||||
bool ok = Client::TypeFromText(leafName, clientType, fallible);
|
||||
if (!ok) {
|
||||
// Unknown directories during getting usage for an origin (even for an
|
||||
// uninitialized origin) are now allowed. Just warn if we find them.
|
||||
UNKNOWN_FILE_WARNING(leafName);
|
||||
continue;
|
||||
}
|
||||
|
||||
Client* client = aQuotaManager.GetClient(clientType);
|
||||
MOZ_ASSERT(client);
|
||||
|
||||
if (aInitialized) {
|
||||
rv = client->GetUsageForOrigin(aPersistenceType, aGroup, aOrigin,
|
||||
mCanceled, &usageInfo);
|
||||
} 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);
|
||||
}
|
||||
|
||||
return usageInfo;
|
||||
|
|
Загрузка…
Ссылка в новой задаче