Bug 1817196: Record preference value that affects the number of results showing in the urlbar r=mak

Differential Revision: https://phabricator.services.mozilla.com/D170317
This commit is contained in:
Daisuke Akatsuka
2023-02-28 00:51:46 +00:00
parent 3016d82071
commit b4d694fef0
6 changed files with 326 additions and 15 deletions

View File

@@ -741,6 +741,7 @@ class TelemetryEvent {
this._controller = controller;
this._category = category;
this._isPrivate = controller.input.isPrivate;
this.#beginObservingPingPrefs();
}
/**
@@ -1327,5 +1328,39 @@ class TelemetryEvent {
this.#previousSearchWordsSet = null;
}
#PING_PREFS = {
maxRichResults: Glean.urlbar.prefMaxResults,
"suggest.topsites": Glean.urlbar.prefSuggestTopsites,
};
#beginObservingPingPrefs() {
this.onPrefChanged("searchEngagementTelemetry.enabled");
lazy.UrlbarPrefs.addObserver(this);
}
onPrefChanged(pref) {
if (pref === "searchEngagementTelemetry.enabled") {
for (const p of Object.keys(this.#PING_PREFS)) {
this.onPrefChanged(p);
}
return;
}
if (!lazy.UrlbarPrefs.get("searchEngagementTelemetryEnabled")) {
return;
}
const metric = this.#PING_PREFS[pref];
if (metric) {
metric.set(lazy.UrlbarPrefs.get(pref));
}
}
onNimbusChanged(variable) {
if (variable === "searchEngagementTelemetryEnabled") {
this.onPrefChanged("searchEngagementTelemetry.enabled");
}
}
#previousSearchWordsSet = null;
}