tor-browser

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

commit b2af3a310ae175656f65dac464d017d508d69860
parent 97fb70153d00ad3c4d5b4b9b15083638331dbdd8
Author: Mark Striemer <mstriemer@mozilla.com>
Date:   Sat, 29 Nov 2025 05:53:03 +0000

Bug 2002380 - AsyncSetting callback hook before caching setting values r=mconley,mtigley

Provide a way for AsyncSettings to start work to be used in this
callback refresh cycle.

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

Diffstat:
Mbrowser/components/preferences/main.js | 13++++++++++++-
Mtoolkit/content/preferences/AsyncSetting.mjs | 20++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/browser/components/preferences/main.js b/browser/components/preferences/main.js @@ -1317,6 +1317,13 @@ Preferences.addSetting( class extends Preferences.AsyncSetting { static id = "payments-list"; + /** @type {Promise<any[]>} */ + paymentMethods; + + beforeRefresh() { + this.paymentMethods = this.getPaymentMethods(); + } + async getPaymentMethods() { await FormAutofillPreferences.prototype.initializePaymentsStorage(); return FormAutofillPreferences.prototype.makePaymentsListItems(); @@ -1324,10 +1331,14 @@ Preferences.addSetting( async getControlConfig() { return { - items: await this.getPaymentMethods(), + items: await this.paymentMethods, }; } + async visible() { + return Boolean((await this.paymentMethods).length); + } + setup() { Services.obs.addObserver(this.emitChange, "formautofill-storage-changed"); return () => diff --git a/toolkit/content/preferences/AsyncSetting.mjs b/toolkit/content/preferences/AsyncSetting.mjs @@ -44,6 +44,25 @@ export class AsyncSetting extends EventEmitter { setup() {} /** + * Called before the setting values will be cached. You can start any shared + * work here if you need the same value in multiple callbacks. + * + * @example + * class Attendees extends AsyncSetting { + * beforeRefresh() { + * this.attendees = MeetingDb.getAttendees(); + * } + * get() { + * return this.attendees; + * } + * async visible() { + * return (await this.attendees).length; + * } + * } + */ + beforeRefresh() {} + + /** * Get the value of this setting. * * @abstract @@ -171,6 +190,7 @@ export class AsyncSettingHandler { * Called to trigger async tasks and re-cache values. */ async refresh() { + this.asyncSetting.beforeRefresh(); [ this.cachedValue, this.cachedDisabled,