Bug 1912272 - Gettting cached origin usage shouldn't trigger temporary storage initialization; r=hsingh

Currently, getting cached origin usage may trigger temporary storage
initialization which is a problem in tests when we want just compare real and
cached usage without affecting the state of initialization.

This patch changes the behavior to return Nothing if temporary storage is not
initialized.

Consumers may either explicitly make sure that temporary storage is initialized
before getting cached origin usage or they can use the other mode when real
usage is colleced from disk.

Differential Revision: https://phabricator.services.mozilla.com/D194504
This commit is contained in:
Jan Varga
2024-08-09 14:39:04 +00:00
parent b25b527877
commit aacad88741
2 changed files with 17 additions and 5 deletions

View File

@@ -1457,11 +1457,11 @@ nsresult GetOriginUsageOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
AUTO_PROFILER_LABEL("GetOriginUsageOp::DoDirectoryWork", OTHER);
if (mFromMemory) {
// Ensure temporary storage is initialized. If temporary storage hasn't been
// initialized yet, the method will initialize it by traversing the
// repositories for temporary and default storage (including our origin).
QM_TRY(MOZ_TO_RESULT(
aQuotaManager.EnsureTemporaryStorageIsInitializedInternal()));
// If temporary storage hasn't been initialized yet, there's no cached
// usage to report.
if (!aQuotaManager.IsTemporaryStorageInitializedInternal()) {
return NS_OK;
}
// 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 database usage.

View File

@@ -38,6 +38,18 @@ async function testSteps() {
// 4. Remove the file "storage/ls-archive.sqlite".
installPackage("groupMismatch_profile");
info("Initializing");
request = init();
await requestFinished(request);
info("Initializing temporary storage");
request = initTemporaryStorage();
await requestFinished(request);
info("Getting origin usage");
request = getOriginUsage(principal, /* fromMemory */ true);
await requestFinished(request);