[tor-commits] [Git][tpo/applications/tor-browser][tor-browser-128.2.0esr-14.0-1] 2 commits: fixup! Bug 31740: Remove some unnecessary RemoteSettings instances

Pier Angelo Vendrame (@pierov) git at gitlab.torproject.org
Wed Aug 28 15:35:56 UTC 2024



Pier Angelo Vendrame pushed to branch tor-browser-128.2.0esr-14.0-1 at The Tor Project / Applications / Tor Browser


Commits:
196b0053 by cypherpunks1 at 2024-08-28T05:34:49-08:00
fixup! Bug 31740: Remove some unnecessary RemoteSettings instances

Bug 42730: Revert some changes

- - - - -
902c51f9 by cypherpunks1 at 2024-08-28T06:27:27-08:00
Bug 42730: Patch RemoteSettings to use only local dumps as a data source

- - - - -


8 changed files:

- browser/components/BrowserGlue.sys.mjs
- mobile/shared/chrome/geckoview/geckoview.js
- services/settings/Attachments.sys.mjs
- services/settings/RemoteSettingsClient.sys.mjs
- services/settings/dumps/gen_last_modified.py
- services/settings/remote-settings.sys.mjs
- toolkit/modules/AppConstants.sys.mjs
- toolkit/modules/IgnoreLists.sys.mjs


Changes:

=====================================
browser/components/BrowserGlue.sys.mjs
=====================================
@@ -3497,6 +3497,11 @@ BrowserGlue.prototype = {
         lazy.RemoteSecuritySettings.init();
       },
 
+      function RemoteSettingsPollChanges() {
+        // Support clients that use the "sync" event or "remote-settings:changes-poll-end".
+        lazy.RemoteSettings.pollChanges({ trigger: "timer" });
+      },
+
       function BrowserUsageTelemetryReportProfileCount() {
         lazy.BrowserUsageTelemetry.reportProfileCount();
       },


=====================================
mobile/shared/chrome/geckoview/geckoview.js
=====================================
@@ -21,6 +21,7 @@ ChromeUtils.defineESModuleGetters(this, {
   InitializationTracker: "resource://gre/modules/GeckoViewTelemetry.sys.mjs",
   RemoteSecuritySettings:
     "resource://gre/modules/psm/RemoteSecuritySettings.sys.mjs",
+  RemoteSettings: "resource://services-settings/remote-settings.sys.mjs",
   SafeBrowsing: "resource://gre/modules/SafeBrowsing.sys.mjs",
 });
 
@@ -922,6 +923,10 @@ function startup() {
       Blocklist.loadBlocklistAsync();
     });
 
+    InitLater(() => {
+      RemoteSettings.pollChanges({ trigger: "timer" });
+    });
+
     // This should always go last, since the idle tasks (except for the ones with
     // timeouts) should execute in order. Note that this observer notification is
     // not guaranteed to fire, since the window could close before we get here.


=====================================
services/settings/Attachments.sys.mjs
=====================================
@@ -223,6 +223,10 @@ export class Downloader {
       fallbackToDump = false;
     }
 
+    avoidDownload = true;
+    fallbackToCache = true;
+    fallbackToDump = true;
+
     const dumpInfo = new LazyRecordAndBuffer(() =>
       this._readAttachmentDump(attachmentId)
     );
@@ -444,6 +448,8 @@ export class Downloader {
       attachment: { location, hash, size },
     } = record;
 
+    return (await this.#fetchAttachment(record)).buffer;
+    // eslint-disable-next-line no-unreachable
     const remoteFileUrl = (await this._baseAttachmentsURL()) + location;
 
     const { retries = 3, checkHash = true } = options;


=====================================
services/settings/RemoteSettingsClient.sys.mjs
=====================================
@@ -424,11 +424,19 @@ export class RemoteSettingsClient extends EventEmitter {
       order = "", // not sorted by default.
       dumpFallback = true,
       emptyListFallback = true,
-      forceSync = false,
       loadDumpIfNewer = true,
-      syncIfEmpty = true,
     } = options;
-    let { verifySignature = false } = options;
+
+    const hasLocalDump = await lazy.Utils.hasLocalDump(
+      this.bucketName,
+      this.collectionName
+    );
+    if (!hasLocalDump) {
+      return [];
+    }
+    const forceSync = false;
+    const syncIfEmpty = true;
+    let verifySignature = false;
 
     const hasParallelCall = !!this._importingPromise;
     let data;
@@ -598,6 +606,10 @@ export class RemoteSettingsClient extends EventEmitter {
    * @param {Object} options See #maybeSync() options.
    */
   async sync(options) {
+    if (AppConstants.BASE_BROWSER_VERSION) {
+      return;
+    }
+
     if (lazy.Utils.shouldSkipRemoteActivityDueToTests) {
       return;
     }
@@ -664,7 +676,7 @@ export class RemoteSettingsClient extends EventEmitter {
     let thrownError = null;
     try {
       // If network is offline, we can't synchronize.
-      if (lazy.Utils.isOffline) {
+      if (!AppConstants.BASE_BROWSER_VERSION && lazy.Utils.isOffline) {
         throw new RemoteSettingsClient.NetworkOfflineError();
       }
 
@@ -1046,14 +1058,8 @@ export class RemoteSettingsClient extends EventEmitter {
     options = {}
   ) {
     const { retry = false } = options;
-    const since = retry || !localTimestamp ? undefined : `"${localTimestamp}"`;
 
-    // Fetch collection metadata and list of changes from server.
-    lazy.console.debug(
-      `${this.identifier} Fetch changes from server (expected=${expectedTimestamp}, since=${since})`
-    );
-    const { metadata, remoteTimestamp, remoteRecords } =
-      await this._fetchChangeset(expectedTimestamp, since);
+    let metadata, remoteTimestamp;
 
     // We build a sync result, based on remote changes.
     const syncResult = {
@@ -1062,24 +1068,20 @@ export class RemoteSettingsClient extends EventEmitter {
       updated: [],
       deleted: [],
     };
-    // If data wasn't changed, return empty sync result.
-    // This can happen when we update the signature but not the data.
-    lazy.console.debug(
-      `${this.identifier} local timestamp: ${localTimestamp}, remote: ${remoteTimestamp}`
-    );
-    if (localTimestamp && remoteTimestamp < localTimestamp) {
+
+    try {
+      await this._importJSONDump();
+    } catch (e) {
       return syncResult;
     }
 
-    await this.db.importChanges(metadata, remoteTimestamp, remoteRecords, {
-      clear: retry,
-    });
-
     // Read the new local data, after updating.
     const newLocal = await this.db.list();
     const newRecords = newLocal.map(r => this._cleanLocalFields(r));
     // And verify the signature on what is now stored.
-    if (this.verifySignature) {
+    if (metadata === undefined) {
+      // When working only with dumps, we do not have signatures.
+    } else if (this.verifySignature) {
       try {
         await this._validateCollectionSignature(
           newRecords,


=====================================
services/settings/dumps/gen_last_modified.py
=====================================
@@ -63,8 +63,10 @@ def main(output):
     dumps_locations = []
     if buildconfig.substs["MOZ_BUILD_APP"] == "browser":
         dumps_locations += ["services/settings/dumps/"]
+        dumps_locations += ["services/settings/static-dumps/"]
     elif buildconfig.substs["MOZ_BUILD_APP"] == "mobile/android":
         dumps_locations += ["services/settings/dumps/"]
+        dumps_locations += ["services/settings/static-dumps/"]
     elif buildconfig.substs["MOZ_BUILD_APP"] == "mobile/ios":
         dumps_locations += ["services/settings/dumps/"]
     elif buildconfig.substs["MOZ_BUILD_APP"] == "comm/mail":


=====================================
services/settings/remote-settings.sys.mjs
=====================================
@@ -91,6 +91,7 @@ export async function jexlFilterFunc(entry, environment) {
 function remoteSettingsFunction() {
   const _clients = new Map();
   let _invalidatePolling = false;
+  let _initialized = false;
 
   // If not explicitly specified, use the default signer.
   const defaultOptions = {
@@ -194,21 +195,49 @@ function remoteSettingsFunction() {
     trigger = "manual",
     full = false,
   } = {}) => {
+    if (AppConstants.BASE_BROWSER_VERSION) {
+      // Called multiple times on GeckoView due to bug 1730026
+      if (_initialized) {
+        return;
+      }
+      _initialized = true;
+      let importedFromDump = false;
+      for (const client of _clients.values()) {
+        const hasLocalDump = await lazy.Utils.hasLocalDump(
+          client.bucketName,
+          client.collectionName
+        );
+        if (hasLocalDump) {
+          const lastModified = await client.getLastModified();
+          const lastModifiedDump = await lazy.Utils.getLocalDumpLastModified(
+            client.bucketName,
+            client.collectionName
+          );
+          if (lastModified < lastModifiedDump) {
+            await client.maybeSync(lastModifiedDump, {
+              loadDump: true,
+              trigger,
+            });
+            importedFromDump = true;
+          }
+        }
+      }
+      if (importedFromDump) {
+        Services.obs.notifyObservers(null, "remote-settings:changes-poll-end");
+      }
+      return;
+    }
+
     if (lazy.Utils.shouldSkipRemoteActivityDueToTests) {
       return;
     }
     // When running in full mode, we ignore last polling status.
-    if (full || AppConstants.BASE_BROWSER_VERSION) {
+    if (full) {
       lazy.gPrefs.clearUserPref(PREF_SETTINGS_SERVER_BACKOFF);
       lazy.gPrefs.clearUserPref(PREF_SETTINGS_LAST_UPDATE);
       lazy.gPrefs.clearUserPref(PREF_SETTINGS_LAST_ETAG);
     }
 
-    if (AppConstants.BASE_BROWSER_VERSION) {
-      // tor-browser#41704: pollChanges is always online, so do not allow it.
-      return;
-    }
-
     let pollTelemetryArgs = {
       source: TELEMETRY_SOURCE_POLL,
       trigger,


=====================================
toolkit/modules/AppConstants.sys.mjs
=====================================
@@ -423,11 +423,11 @@ export var AppConstants = Object.freeze({
 #ifdef MOZ_THUNDERBIRD
     "https://thunderbird-settings.thunderbird.net/v1",
 #else
-    "https://firefox.settings.services.mozilla.com/v1",
+    "",
 #endif
 
   REMOTE_SETTINGS_VERIFY_SIGNATURE:
-#ifdef MOZ_THUNDERBIRD
+#if defined(MOZ_THUNDERBIRD) || defined(BASE_BROWSER_VERSION)
     false,
 #else
     true,


=====================================
toolkit/modules/IgnoreLists.sys.mjs
=====================================
@@ -5,16 +5,18 @@
 const lazy = {};
 
 ChromeUtils.defineESModuleGetters(lazy, {
+  RemoteSettings: "resource://services-settings/remote-settings.sys.mjs",
   RemoteSettingsClient:
     "resource://services-settings/RemoteSettingsClient.sys.mjs",
 });
 
-class IgnoreListsManager {
-  _ignoreListSettings = null;
+const SETTINGS_IGNORELIST_KEY = "hijack-blocklists";
 
+class IgnoreListsManager {
   async init() {
-    // TODO: Restore the initialization, once we use only the local dumps for
-    // the remote settings.
+    if (!this._ignoreListSettings) {
+      this._ignoreListSettings = lazy.RemoteSettings(SETTINGS_IGNORELIST_KEY);
+    }
   }
 
   async getAndSubscribe(listener) {
@@ -24,7 +26,7 @@ class IgnoreListsManager {
     const settings = await this._getIgnoreList();
 
     // Listen for future updates after we first get the values.
-    this._ignoreListSettings?.on("sync", listener);
+    this._ignoreListSettings.on("sync", listener);
 
     return settings;
   }
@@ -65,14 +67,6 @@ class IgnoreListsManager {
    *   could be obtained.
    */
   async _getIgnoreListSettings(firstTime = true) {
-    if (!this._ignoreListSettings) {
-      const dump = await fetch(
-        "resource:///defaults/settings/main/hijack-blocklists.json"
-      );
-      const { data } = await dump.json();
-      return data;
-    }
-
     let result = [];
     try {
       result = await this._ignoreListSettings.get({



View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/3a07659339921ec3911333abd6bd545bddf6ced0...902c51f97c45b7d35cb9013b6ace907963927555

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/3a07659339921ec3911333abd6bd545bddf6ced0...902c51f97c45b7d35cb9013b6ace907963927555
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tor-commits/attachments/20240828/23177968/attachment-0001.htm>


More information about the tor-commits mailing list