forked from mirrors/gecko-dev
Bug 1897242 - Make it easy to run and log a single relevancy classification. r=nanj
Differential Revision: https://phabricator.services.mozilla.com/D210710
This commit is contained in:
parent
b32dbe8a2c
commit
8e020b00cf
2 changed files with 46 additions and 10 deletions
|
|
@ -3075,3 +3075,5 @@ pref("startup.homepage_override_nimbus_maxVersion", "");
|
||||||
pref("toolkit.contentRelevancy.enabled", false);
|
pref("toolkit.contentRelevancy.enabled", false);
|
||||||
// Pref to enable the ingestion through the Rust component.
|
// Pref to enable the ingestion through the Rust component.
|
||||||
pref("toolkit.contentRelevancy.ingestEnabled", false);
|
pref("toolkit.contentRelevancy.ingestEnabled", false);
|
||||||
|
// Pref to enable extra logging for the content relevancy feature
|
||||||
|
pref("toolkit.contentRelevancy.log", false);
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ XPCOMUtils.defineLazyServiceGetter(
|
||||||
const TIMER_ID = "content-relevancy-timer";
|
const TIMER_ID = "content-relevancy-timer";
|
||||||
const PREF_TIMER_LAST_UPDATE = `app.update.lastUpdateTime.${TIMER_ID}`;
|
const PREF_TIMER_LAST_UPDATE = `app.update.lastUpdateTime.${TIMER_ID}`;
|
||||||
const PREF_TIMER_INTERVAL = "toolkit.contentRelevancy.timerInterval";
|
const PREF_TIMER_INTERVAL = "toolkit.contentRelevancy.timerInterval";
|
||||||
|
const PREF_LOG_ENABLED = "toolkit.contentRelevancy.log";
|
||||||
// Set the timer interval to 1 day for validation.
|
// Set the timer interval to 1 day for validation.
|
||||||
const DEFAULT_TIMER_INTERVAL_SECONDS = 1 * 24 * 60 * 60;
|
const DEFAULT_TIMER_INTERVAL_SECONDS = 1 * 24 * 60 * 60;
|
||||||
|
|
||||||
|
|
@ -43,17 +44,20 @@ const NIMBUS_VARIABLE_MIN_INPUT_URLS = "minInputUrls";
|
||||||
const NIMBUS_VARIABLE_TIMER_INTERVAL = "timerInterval";
|
const NIMBUS_VARIABLE_TIMER_INTERVAL = "timerInterval";
|
||||||
const NIMBUS_VARIABLE_INGEST_ENABLED = "ingestEnabled";
|
const NIMBUS_VARIABLE_INGEST_ENABLED = "ingestEnabled";
|
||||||
|
|
||||||
ChromeUtils.defineLazyGetter(lazy, "log", () => {
|
// Setup the `lazy.log` object. This is called on startup and also whenever `PREF_LOG_ENABLED`
|
||||||
return console.createInstance({
|
// changes.
|
||||||
prefix: "ContentRelevancyManager",
|
function setupLogging() {
|
||||||
maxLogLevel: Services.prefs.getBoolPref(
|
ChromeUtils.defineLazyGetter(lazy, "log", () => {
|
||||||
"toolkit.contentRelevancy.log",
|
return console.createInstance({
|
||||||
false
|
prefix: "ContentRelevancyManager",
|
||||||
)
|
maxLogLevel: Services.prefs.getBoolPref(PREF_LOG_ENABLED, false)
|
||||||
? "Debug"
|
? "Debug"
|
||||||
: "Error",
|
: "Error",
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
setupLogging();
|
||||||
|
|
||||||
class RelevancyManager {
|
class RelevancyManager {
|
||||||
get initialized() {
|
get initialized() {
|
||||||
|
|
@ -79,6 +83,7 @@ class RelevancyManager {
|
||||||
this.#enable();
|
this.#enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Services.prefs.addObserver(PREF_LOG_ENABLED, this);
|
||||||
this._nimbusUpdateCallback = this.#onNimbusUpdate.bind(this);
|
this._nimbusUpdateCallback = this.#onNimbusUpdate.bind(this);
|
||||||
// This will handle both Nimbus updates and pref changes.
|
// This will handle both Nimbus updates and pref changes.
|
||||||
lazy.NimbusFeatures.contentRelevancy.onUpdate(this._nimbusUpdateCallback);
|
lazy.NimbusFeatures.contentRelevancy.onUpdate(this._nimbusUpdateCallback);
|
||||||
|
|
@ -93,6 +98,7 @@ class RelevancyManager {
|
||||||
lazy.log.info("Uninitializing the manager");
|
lazy.log.info("Uninitializing the manager");
|
||||||
|
|
||||||
lazy.NimbusFeatures.contentRelevancy.offUpdate(this._nimbusUpdateCallback);
|
lazy.NimbusFeatures.contentRelevancy.offUpdate(this._nimbusUpdateCallback);
|
||||||
|
Services.prefs.removeObserver(PREF_LOG_ENABLED, this);
|
||||||
this.#disable();
|
this.#disable();
|
||||||
|
|
||||||
this.#initialized = false;
|
this.#initialized = false;
|
||||||
|
|
@ -365,6 +371,20 @@ class RelevancyManager {
|
||||||
this.#toggleFeature();
|
this.#toggleFeature();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preference observer
|
||||||
|
*/
|
||||||
|
observe(_subj, topic, data) {
|
||||||
|
switch (topic) {
|
||||||
|
case "nsPref:changed":
|
||||||
|
if (data === PREF_LOG_ENABLED) {
|
||||||
|
// Call setupLogging again so that the logger will be re-created with the updated pref
|
||||||
|
setupLogging();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// The `RustRelevancy` store.
|
// The `RustRelevancy` store.
|
||||||
#_store;
|
#_store;
|
||||||
|
|
||||||
|
|
@ -387,3 +407,17 @@ class StoreNotAvailableError extends Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
export var ContentRelevancyManager = new RelevancyManager();
|
export var ContentRelevancyManager = new RelevancyManager();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exposed to provide an easy way for users to run a single classification
|
||||||
|
*
|
||||||
|
* This allows users to test out the relevancy component without too much hassle:
|
||||||
|
*
|
||||||
|
* - Enable the `toolkit.contentRelevancy.log` pref
|
||||||
|
* - Enable the `devtools.chrome.enabled` pref if it wasn't already
|
||||||
|
* - Open the browser console and enter:
|
||||||
|
* `ChromeUtils.importESModule("resource://gre/modules/ContentRelevancyManager.sys.mjs").classifyOnce()`
|
||||||
|
*/
|
||||||
|
export function classifyOnce() {
|
||||||
|
ContentRelevancyManager._test_doClassification();
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue