Bug 1788986 - Part 2: Use a background task for QM shutdown cleanup r=janv,smaug

Differential Revision: https://phabricator.services.mozilla.com/D156331
This commit is contained in:
Kagami Sascha Rosylight 2023-02-06 11:32:48 +00:00
parent 425786bd75
commit bfa807408a
4 changed files with 56 additions and 3 deletions

View File

@ -3431,6 +3431,14 @@
value: 200
mirror: always
#ifdef MOZ_BACKGROUNDTASKS
# Use a Background Task to delete files at shutdown.
- name: dom.quotaManager.backgroundTask.enabled
type: bool
value: @IS_NIGHTLY_BUILD@
mirror: never
#endif
# Determines within what distance of a tick mark, in pixels, dragging an input
# range range will snap the range's value to that tick mark. By default, this is
# half the default width of the range thumb.

View File

@ -739,11 +739,29 @@ const QuotaCleaner = {
async cleanupAfterDeletionAtShutdown() {
const storageDir = PathUtils.join(
PathUtils.profileDir,
Services.prefs.getStringPref("dom.quotaManager.storageName"),
"to-be-removed"
Services.prefs.getStringPref("dom.quotaManager.storageName")
);
await IOUtils.remove(storageDir, { recursive: true });
if (
!AppConstants.MOZ_BACKGROUNDTASKS ||
!Services.prefs.getBoolPref("dom.quotaManager.backgroundTask.enabled")
) {
await IOUtils.remove(PathUtils.join(storageDir, "to-be-removed"), {
recursive: true,
});
return;
}
const runner = Cc["@mozilla.org/backgroundtasksrunner;1"].getService(
Ci.nsIBackgroundTasksRunner
);
runner.removeDirectoryInDetachedProcess(
storageDir,
"to-be-removed",
"0",
""
);
},
};

View File

@ -15,6 +15,7 @@ class MovedOriginDirectoryCleanupTestCase(MarionetteTestCase):
{
"privacy.sanitize.sanitizeOnShutdown": True,
"privacy.clearOnShutdown.offlineApps": True,
"dom.quotaManager.backgroundTask.enabled": False,
}
)
self.moved_origin_directory = (
@ -58,3 +59,19 @@ class MovedOriginDirectoryCleanupTestCase(MarionetteTestCase):
lambda _: not self.moved_origin_directory.exists(),
message="to-be-removed subdirectory must disappear",
)
def test_ensure_cleanup_by_quit_with_background_task(self):
self.assertTrue(
self.moved_origin_directory.exists(),
"to-be-removed subdirectory must exist",
)
self.marionette.set_pref("dom.quotaManager.backgroundTask.enabled", True)
# Cleanup happens via Sanitizer.sanitizeOnShutdown
self.marionette.quit()
Wait(self.marionette).until(
lambda _: not self.moved_origin_directory.exists(),
message="to-be-removed subdirectory must disappear",
)

View File

@ -18,6 +18,11 @@ const skipLocalStorageTests = Services.prefs.getBoolPref(
"dom.storage.enable_unsupported_legacy_implementation"
);
// XXX(krosylight): xpcshell does not support background tasks
const skipCleanupAfterDeletionAtShutdownTests = Services.prefs.getBoolPref(
"dom.quotaManager.backgroundTask.enabled"
);
/**
* Create an origin with partitionKey.
* @param {String} host - Host portion of origin to create.
@ -535,6 +540,11 @@ add_task(async function test_deleteAllAtShutdown() {
`storage/to-be-removed has ${TEST_ORIGINS.length} subdirectories`
);
if (skipCleanupAfterDeletionAtShutdownTests) {
// XXX(krosylight): xpcshell does not support background tasks
return;
}
info("Verifying cleanupAfterDeletionAtShutdown");
await new Promise(aResolve => {
Services.clearData.cleanupAfterDeletionAtShutdown(