Commit 9d589516 authored by cypherpunks1's avatar cypherpunks1 Committed by Pier Angelo Vendrame
Browse files

BB 42730: Patch RemoteSettings to use only local dumps as a data source

parent 11b7375b
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1385,6 +1385,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 searchBackgroundChecks() {
        Services.search.runBackgroundChecks();
      },
+5 −0
Original line number Diff line number Diff line
@@ -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",
  CaptchaDetectionPingUtils:
    "resource://gre/modules/CaptchaDetectionPingUtils.sys.mjs",
@@ -930,6 +931,10 @@ function startup() {
      CaptchaDetectionPingUtils.init();
    });

    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.
+6 −0
Original line number Diff line number Diff line
@@ -359,6 +359,10 @@ export class Downloader {
      fallbackToDump = false;
    }

    avoidDownload = true;
    fallbackToCache = true;
    fallbackToDump = true;

    const dumpInfo = new LazyRecordAndBuffer(() =>
      this._readAttachmentDump(attachmentId)
    );
@@ -521,6 +525,8 @@ export class Downloader {
      attachment: { location, hash, size },
    } = record;

    return (await this.#fetchAttachment(record)).buffer;
    // eslint-disable-next-line no-unreachable
    let baseURL;
    try {
      baseURL = await lazy.Utils.baseAttachmentsURL();
+24 −26
Original line number Diff line number Diff line
@@ -450,11 +450,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;
@@ -649,6 +657,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) {
      lazy.console.debug(`${this.identifier} Skip sync() due to tests.`);
      return;
@@ -732,7 +744,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();
      }

@@ -1121,15 +1133,8 @@ export class RemoteSettingsClient extends EventEmitter {
  ) {
    const hasLocalData = localTimestamp !== null;
    const { retry = false } = options;
    // On retry, we fully re-fetch the collection (no `?_since`).
    const since = retry || !hasLocalData ? 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 = {
@@ -1138,27 +1143,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 (hasLocalData && remoteTimestamp < localTimestamp) {
      lazy.console.debug(
        `${this.identifier} No records to sync, local data is up-to-date`
      );

    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,
+2 −0
Original line number Diff line number Diff line
@@ -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":
Loading