tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 2c59988c7e8ee9f4a2b30834aec69e015ce8919b
parent 13c5045d6b46456c4246d0ea76d9a5f4014435ac
Author: scottdowne <sdowne@mozilla.com>
Date:   Tue,  6 Jan 2026 21:09:56 +0000

Bug 2008469 - Newtab frecency ranking RS onsync and init/uninit. r=home-newtab-reviewers,nbarrett

Differential Revision: https://phabricator.services.mozilla.com/D277815

Diffstat:
Mbrowser/extensions/newtab/lib/FrecencyBoostProvider/FrecencyBoostProvider.mjs | 22+++++++++++++++++++---
Mbrowser/extensions/newtab/lib/TopSitesFeed.sys.mjs | 2++
2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/browser/extensions/newtab/lib/FrecencyBoostProvider/FrecencyBoostProvider.mjs b/browser/extensions/newtab/lib/FrecencyBoostProvider/FrecencyBoostProvider.mjs @@ -58,15 +58,28 @@ export class FrecencyBoostProvider { this._links = null; this._frecencyBoostedSponsors = new Map(); this._frecencyBoostRS = null; + this._onSync = this.onSync.bind(this); } - get _frecencyBoostRemoteSettings() { + init() { if (!this._frecencyBoostRS) { this._frecencyBoostRS = lazy.RemoteSettings( "newtab-frecency-boosted-sponsors" ); + this._frecencyBoostRS.on("sync", this._onSync); } - return this._frecencyBoostRS; + } + + uninit() { + if (this._frecencyBoostRS) { + this._frecencyBoostRS.off("sync", this._onSync); + this._frecencyBoostRS = null; + } + } + + async onSync() { + this._frecencyBoostedSponsors = new Map(); + await this._importFrecencyBoostedSponsors(); } /** @@ -75,7 +88,10 @@ export class FrecencyBoostProvider { * We fetch all favicons regardless of whether the user has visited these sites. */ async _importFrecencyBoostedSponsors() { - const records = await this._frecencyBoostRemoteSettings.get(); + const records = await this._frecencyBoostRS?.get(); + if (!records) { + return; + } const userRegion = lazy.Region.home || ""; const regionRecords = records.filter( diff --git a/browser/extensions/newtab/lib/TopSitesFeed.sys.mjs b/browser/extensions/newtab/lib/TopSitesFeed.sys.mjs @@ -933,6 +933,7 @@ export class TopSitesFeed { Services.prefs.addObserver(DEFAULT_SITES_OVERRIDE_PREF, this); Services.prefs.addObserver(DEFAULT_SITES_EXPERIMENTS_PREF_BRANCH, this); lazy.NimbusFeatures.newtab.onUpdate(this._nimbusChangeListener); + this.frecencyBoostProvider.init(); } uninit() { @@ -943,6 +944,7 @@ export class TopSitesFeed { Services.prefs.removeObserver(DEFAULT_SITES_OVERRIDE_PREF, this); Services.prefs.removeObserver(DEFAULT_SITES_EXPERIMENTS_PREF_BRANCH, this); lazy.NimbusFeatures.newtab.offUpdate(this._nimbusChangeListener); + this.frecencyBoostProvider.uninit(); } observe(subj, topic, data) {