summaryrefslogtreecommitdiffstats
path: root/dom/notification/old/NotificationDB.sys.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'dom/notification/old/NotificationDB.sys.mjs')
-rw-r--r--dom/notification/old/NotificationDB.sys.mjs84
1 files changed, 28 insertions, 56 deletions
diff --git a/dom/notification/old/NotificationDB.sys.mjs b/dom/notification/old/NotificationDB.sys.mjs
index 7de9734450..8cd2bff8f6 100644
--- a/dom/notification/old/NotificationDB.sys.mjs
+++ b/dom/notification/old/NotificationDB.sys.mjs
@@ -2,17 +2,19 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
-const DEBUG = false;
-function debug(s) {
- dump("-*- NotificationDB component: " + s + "\n");
-}
-
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
AsyncShutdown: "resource://gre/modules/AsyncShutdown.sys.mjs",
});
+ChromeUtils.defineLazyGetter(lazy, "console", () => {
+ return console.createInstance({
+ prefix: "NotificationDB",
+ maxLogLevelPref: "dom.webnotifications.loglevel",
+ });
+});
+
const NOTIFICATION_STORE_DIR = PathUtils.profileDir;
const NOTIFICATION_STORE_PATH = PathUtils.join(
NOTIFICATION_STORE_DIR,
@@ -70,9 +72,7 @@ var NotificationDB = {
},
observe(aSubject, aTopic) {
- if (DEBUG) {
- debug("Topic: " + aTopic);
- }
+ lazy.console.debug(`Topic: ${aTopic}`);
if (aTopic == "xpcom-shutdown") {
this._shutdownInProgress = true;
Services.obs.removeObserver(this, "xpcom-shutdown");
@@ -92,11 +92,9 @@ var NotificationDB = {
}
}
if (persistentNotificationCount == 0) {
- if (DEBUG) {
- debug(
- "Origin " + origin + " is not linked to an app manifest, deleting."
- );
- }
+ lazy.console.debug(
+ `Origin ${origin} is not linked to an app manifest, deleting.`
+ );
delete result[origin];
}
}
@@ -171,9 +169,7 @@ var NotificationDB = {
},
receiveMessage(message) {
- if (DEBUG) {
- debug("Received message:" + message.name);
- }
+ lazy.console.debug(`Received message: ${message.name}`);
// sendAsyncMessage can fail if the child process exits during a
// notification storage operation, so always wrap it in a try/catch.
@@ -181,9 +177,7 @@ var NotificationDB = {
try {
message.target.sendAsyncMessage(name, data);
} catch (e) {
- if (DEBUG) {
- debug("Return message failed, " + name);
- }
+ lazy.console.debug(`Return message failed, ${name}`);
}
}
@@ -237,18 +231,14 @@ var NotificationDB = {
break;
default:
- if (DEBUG) {
- debug("Invalid message name" + message.name);
- }
+ lazy.console.debug(`Invalid message name ${message.name}`);
}
},
// We need to make sure any read/write operations are atomic,
// so use a queue to run each operation sequentially.
queueTask(operation, data) {
- if (DEBUG) {
- debug("Queueing task: " + operation);
- }
+ lazy.console.debug(`Queueing task: ${operation}`);
var defer = {};
@@ -265,9 +255,7 @@ var NotificationDB = {
// Only run immediately if we aren't currently running another task.
if (!this.runningTask) {
- if (DEBUG) {
- debug("Task queue was not running, starting now...");
- }
+ lazy.console.debug("Task queue was not running, starting now...");
this.runNextTask();
this._queueDrainedPromise = new Promise(resolve => {
this._queueDrainedPromiseResolve = resolve;
@@ -279,14 +267,12 @@ var NotificationDB = {
runNextTask() {
if (this.tasks.length === 0) {
- if (DEBUG) {
- debug("No more tasks to run, queue depleted");
- }
+ lazy.console.debug("No more tasks to run, queue depleted");
this.runningTask = null;
if (this._queueDrainedPromiseResolve) {
this._queueDrainedPromiseResolve();
- } else if (DEBUG) {
- debug(
+ } else {
+ lazy.console.debug(
"_queueDrainedPromiseResolve was null somehow, no promise to resolve"
);
}
@@ -316,17 +302,13 @@ var NotificationDB = {
}
})
.then(payload => {
- if (DEBUG) {
- debug("Finishing task: " + this.runningTask.operation);
- }
+ lazy.console.debug(`Finishing task: ${this.runningTask.operation}`);
this.runningTask.defer.resolve(payload);
})
.catch(err => {
- if (DEBUG) {
- debug(
- "Error while running " + this.runningTask.operation + ": " + err
- );
- }
+ lazy.console.debug(
+ `Error while running ${this.runningTask.operation}: ${err}`
+ );
this.runningTask.defer.reject(err);
})
.then(() => {
@@ -335,9 +317,7 @@ var NotificationDB = {
},
taskGetAll(data) {
- if (DEBUG) {
- debug("Task, getting all");
- }
+ lazy.console.debug("Task, getting all");
var origin = data.origin;
var notifications = [];
// Grab only the notifications for specified origin.
@@ -357,9 +337,7 @@ var NotificationDB = {
},
taskSave(data) {
- if (DEBUG) {
- debug("Task, saving");
- }
+ lazy.console.debug("Task, saving");
var origin = data.origin;
var notification = data.notification;
if (!this.notifications[origin]) {
@@ -382,24 +360,18 @@ var NotificationDB = {
},
taskDelete(data) {
- if (DEBUG) {
- debug("Task, deleting");
- }
+ lazy.console.debug("Task, deleting");
var origin = data.origin;
var id = data.id;
if (!this.notifications[origin]) {
- if (DEBUG) {
- debug("No notifications found for origin: " + origin);
- }
+ lazy.console.debug(`No notifications found for origin: ${origin}`);
return Promise.resolve();
}
// Make sure we can find the notification to delete.
var oldNotification = this.notifications[origin][id];
if (!oldNotification) {
- if (DEBUG) {
- debug("No notification found with id: " + id);
- }
+ lazy.console.debug(`No notification found with id: ${id}`);
return Promise.resolve();
}