Bug 1963014 - Add jsdoc for IgnoreLists.sys.mjs. r=search-reviewers,frontend-codestyle-reviewers,daleharvey,mossop
Differential Revision: https://phabricator.services.mozilla.com/D246909
This commit is contained in:
@@ -391,7 +391,7 @@ const rollouts = [
|
|||||||
"toolkit/components/workerloader/require.js",
|
"toolkit/components/workerloader/require.js",
|
||||||
"toolkit/content/**",
|
"toolkit/content/**",
|
||||||
"toolkit/crashreporter/**",
|
"toolkit/crashreporter/**",
|
||||||
"toolkit/modules/{C,Da,E10SUtils,F,G,I,J,Ke,L,N,O,P,R,S,Up,W}*.sys.mjs",
|
"toolkit/modules/{C,Da,E10SUtils,F,G,In,J,Ke,L,N,O,P,R,S,Up,W}*.sys.mjs",
|
||||||
"toolkit/modules/sessionstore/**",
|
"toolkit/modules/sessionstore/**",
|
||||||
"toolkit/modules/subprocess/**",
|
"toolkit/modules/subprocess/**",
|
||||||
"toolkit/modules/tests/**",
|
"toolkit/modules/tests/**",
|
||||||
@@ -555,7 +555,7 @@ const rollouts = [
|
|||||||
"toolkit/components/workerloader/require.js",
|
"toolkit/components/workerloader/require.js",
|
||||||
"toolkit/content/**",
|
"toolkit/content/**",
|
||||||
"toolkit/crashreporter/**",
|
"toolkit/crashreporter/**",
|
||||||
"toolkit/modules/{Asy,B,C,Da,E10SUtils,F,G,I,JS,Ke,L,Ne,Ob,P,R,S,Up,W}*.sys.mjs",
|
"toolkit/modules/{Asy,B,C,Da,E10SUtils,F,G,In,JS,Ke,L,Ne,Ob,P,R,S,Up,W}*.sys.mjs",
|
||||||
"toolkit/modules/sessionstore/**",
|
"toolkit/modules/sessionstore/**",
|
||||||
"toolkit/modules/subprocess/**",
|
"toolkit/modules/subprocess/**",
|
||||||
"toolkit/modules/tests/**",
|
"toolkit/modules/tests/**",
|
||||||
|
|||||||
@@ -10,43 +10,75 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
|||||||
"resource://services-settings/RemoteSettingsClient.sys.mjs",
|
"resource://services-settings/RemoteSettingsClient.sys.mjs",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {import("../../services/settings/RemoteSettingsClient.sys.mjs").RemoteSettingsClient} RemoteSettingsClient
|
||||||
|
*/
|
||||||
|
|
||||||
const SETTINGS_IGNORELIST_KEY = "hijack-blocklists";
|
const SETTINGS_IGNORELIST_KEY = "hijack-blocklists";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A remote settings wrapper for the ignore lists from the hijack-blocklists
|
||||||
|
* collection.
|
||||||
|
*/
|
||||||
class IgnoreListsManager {
|
class IgnoreListsManager {
|
||||||
async init() {
|
/**
|
||||||
if (!this._ignoreListSettings) {
|
* @type {RemoteSettingsClient}
|
||||||
this._ignoreListSettings = lazy.RemoteSettings(SETTINGS_IGNORELIST_KEY);
|
*/
|
||||||
|
#ignoreListSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the manager, if it is not already initialised.
|
||||||
|
*/
|
||||||
|
#init() {
|
||||||
|
if (!this.#ignoreListSettings) {
|
||||||
|
this.#ignoreListSettings = lazy.RemoteSettings(SETTINGS_IGNORELIST_KEY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current collection, subscribing to the collection after the
|
||||||
|
* get has been completed.
|
||||||
|
*
|
||||||
|
* @param {Function} listener
|
||||||
|
*/
|
||||||
async getAndSubscribe(listener) {
|
async getAndSubscribe(listener) {
|
||||||
await this.init();
|
this.#init();
|
||||||
|
|
||||||
// Trigger a get of the initial value.
|
// Trigger a get of the initial value.
|
||||||
const settings = await this._getIgnoreList();
|
const settings = await this.#getIgnoreList();
|
||||||
|
|
||||||
// Listen for future updates after we first get the values.
|
// Listen for future updates after we first get the values.
|
||||||
this._ignoreListSettings.on("sync", listener);
|
this.#ignoreListSettings.on("sync", listener);
|
||||||
|
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unsubscribes from updates to the collection.
|
||||||
|
*
|
||||||
|
* @param {Function} listener
|
||||||
|
*/
|
||||||
unsubscribe(listener) {
|
unsubscribe(listener) {
|
||||||
if (!this._ignoreListSettings) {
|
if (!this.#ignoreListSettings) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._ignoreListSettings.off("sync", listener);
|
this.#ignoreListSettings.off("sync", listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _getIgnoreList() {
|
/**
|
||||||
if (this._getSettingsPromise) {
|
* @type {Promise<object[]>}
|
||||||
return this._getSettingsPromise;
|
*/
|
||||||
|
#getSettingsPromise;
|
||||||
|
|
||||||
|
async #getIgnoreList() {
|
||||||
|
if (this.#getSettingsPromise) {
|
||||||
|
return this.#getSettingsPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
const settings = await (this._getSettingsPromise =
|
const settings = await (this.#getSettingsPromise =
|
||||||
this._getIgnoreListSettings());
|
this.#getIgnoreListSettings());
|
||||||
delete this._getSettingsPromise;
|
this.#getSettingsPromise = undefined;
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,14 +94,14 @@ class IgnoreListsManager {
|
|||||||
*
|
*
|
||||||
* @param {boolean} [firstTime]
|
* @param {boolean} [firstTime]
|
||||||
* Internal boolean to indicate if this is the first time check or not.
|
* Internal boolean to indicate if this is the first time check or not.
|
||||||
* @returns {array}
|
* @returns {Promise<object[]>}
|
||||||
* An array of objects in the database, or an empty array if none
|
* An array of objects in the database, or an empty array if none
|
||||||
* could be obtained.
|
* could be obtained.
|
||||||
*/
|
*/
|
||||||
async _getIgnoreListSettings(firstTime = true) {
|
async #getIgnoreListSettings(firstTime = true) {
|
||||||
let result = [];
|
let result = [];
|
||||||
try {
|
try {
|
||||||
result = await this._ignoreListSettings.get({
|
result = await this.#ignoreListSettings.get({
|
||||||
verifySignature: true,
|
verifySignature: true,
|
||||||
});
|
});
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@@ -78,9 +110,9 @@ class IgnoreListsManager {
|
|||||||
firstTime
|
firstTime
|
||||||
) {
|
) {
|
||||||
// The local database is invalid, try and reset it.
|
// The local database is invalid, try and reset it.
|
||||||
await this._ignoreListSettings.db.clear();
|
await this.#ignoreListSettings.db.clear();
|
||||||
// Now call this again.
|
// Now call this again.
|
||||||
return this._getIgnoreListSettings(false);
|
return this.#getIgnoreListSettings(false);
|
||||||
}
|
}
|
||||||
// Don't throw an error just log it, just continue with no data, and hopefully
|
// Don't throw an error just log it, just continue with no data, and hopefully
|
||||||
// a sync will fix things later on.
|
// a sync will fix things later on.
|
||||||
@@ -90,4 +122,8 @@ class IgnoreListsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A remote settings wrapper for the ignore lists from the hijack-blocklists
|
||||||
|
* collection.
|
||||||
|
*/
|
||||||
export const IgnoreLists = new IgnoreListsManager();
|
export const IgnoreLists = new IgnoreListsManager();
|
||||||
|
|||||||
Reference in New Issue
Block a user