From 40a355a42d4a9444dc753c04c6608dade2f06a23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:27 +0200 Subject: Adding upstream version 125.0.1. Signed-off-by: Daniel Baumann --- dom/notification/old/NotificationDB.sys.mjs | 32 +++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'dom/notification/old/NotificationDB.sys.mjs') diff --git a/dom/notification/old/NotificationDB.sys.mjs b/dom/notification/old/NotificationDB.sys.mjs index 79a9965628..7de9734450 100644 --- a/dom/notification/old/NotificationDB.sys.mjs +++ b/dom/notification/old/NotificationDB.sys.mjs @@ -7,6 +7,12 @@ function debug(s) { dump("-*- NotificationDB component: " + s + "\n"); } +const lazy = {}; + +ChromeUtils.defineESModuleGetters(lazy, { + AsyncShutdown: "resource://gre/modules/AsyncShutdown.sys.mjs", +}); + const NOTIFICATION_STORE_DIR = PathUtils.profileDir; const NOTIFICATION_STORE_PATH = PathUtils.join( NOTIFICATION_STORE_DIR, @@ -23,6 +29,11 @@ var NotificationDB = { // Ensure we won't call init() while xpcom-shutdown is performed _shutdownInProgress: false, + // A promise that resolves once the ongoing task queue has been drained. + // The value will be reset when the queue starts again. + _queueDrainedPromise: null, + _queueDrainedPromiseResolve: null, + init() { if (this._shutdownInProgress) { return; @@ -37,6 +48,13 @@ var NotificationDB = { Services.obs.addObserver(this, "xpcom-shutdown"); this.registerListeners(); + + // This assumes that nothing will queue a new task at profile-change-teardown phase, + // potentially replacing the _queueDrainedPromise if there was no existing task run. + lazy.AsyncShutdown.profileChangeTeardown.addBlocker( + "NotificationDB: Need to make sure that all notification messages are processed", + () => this._queueDrainedPromise + ); }, registerListeners() { @@ -51,7 +69,7 @@ var NotificationDB = { } }, - observe(aSubject, aTopic, aData) { + observe(aSubject, aTopic) { if (DEBUG) { debug("Topic: " + aTopic); } @@ -114,7 +132,7 @@ var NotificationDB = { }, // If read failed, we assume we have no notifications to load. - reason => { + () => { this.loaded = true; return this.createStore(); } @@ -251,6 +269,9 @@ var NotificationDB = { debug("Task queue was not running, starting now..."); } this.runNextTask(); + this._queueDrainedPromise = new Promise(resolve => { + this._queueDrainedPromiseResolve = resolve; + }); } return promise; @@ -262,6 +283,13 @@ var NotificationDB = { debug("No more tasks to run, queue depleted"); } this.runningTask = null; + if (this._queueDrainedPromiseResolve) { + this._queueDrainedPromiseResolve(); + } else if (DEBUG) { + debug( + "_queueDrainedPromiseResolve was null somehow, no promise to resolve" + ); + } return; } this.runningTask = this.tasks.shift(); -- cgit v1.2.3