Bug 1440022: hook up remote-settings to broadcast messages r?kitcambridge draft
authorEthan Glasser-Camp <ethan@betacantrips.com>
Tue, 08 May 2018 11:53:06 -0400
changeset 805400 8cc3217d6d7dae3250c25b27d0e2d964d2b6e5a3
parent 805399 21b62d8aa97f842267adad74cc103f20629a424b
push id112647
push userbmo:eglassercamp@mozilla.com
push dateThu, 07 Jun 2018 19:43:14 +0000
reviewerskitcambridge
bugs1440022
milestone62.0a1
Bug 1440022: hook up remote-settings to broadcast messages r?kitcambridge MozReview-Commit-ID: 3TYBqH94rSD
services/settings/remote-settings.js
--- a/services/settings/remote-settings.js
+++ b/services/settings/remote-settings.js
@@ -1,17 +1,20 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+/* global __URI__ */
+
 "use strict";
 
 var EXPORTED_SYMBOLS = [
   "RemoteSettings",
-  "jexlFilterFunc"
+  "jexlFilterFunc",
+  "remoteSettingsBroadcastHandler",
 ];
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm", {});
 Cu.importGlobalProperties(["fetch"]);
 
 ChromeUtils.defineModuleGetter(this, "Kinto",
@@ -21,16 +24,18 @@ ChromeUtils.defineModuleGetter(this, "Ki
 ChromeUtils.defineModuleGetter(this, "CanonicalJSON",
                                "resource://gre/modules/CanonicalJSON.jsm");
 ChromeUtils.defineModuleGetter(this, "UptakeTelemetry",
                                "resource://services-common/uptake-telemetry.js");
 ChromeUtils.defineModuleGetter(this, "ClientEnvironmentBase",
                                "resource://gre/modules/components-utils/ClientEnvironment.jsm");
 ChromeUtils.defineModuleGetter(this, "FilterExpressions",
                                "resource://gre/modules/components-utils/FilterExpressions.jsm");
+ChromeUtils.defineModuleGetter(this, "pushBroadcastService",
+                               "resource://gre/modules/PushBroadcastService.jsm");
 
 const PREF_SETTINGS_SERVER             = "services.settings.server";
 const PREF_SETTINGS_DEFAULT_BUCKET     = "services.settings.default_bucket";
 const PREF_SETTINGS_DEFAULT_SIGNER     = "services.settings.default_signer";
 const PREF_SETTINGS_VERIFY_SIGNATURE   = "services.settings.verify_signature";
 const PREF_SETTINGS_SERVER_BACKOFF     = "services.settings.server.backoff";
 const PREF_SETTINGS_CHANGES_PATH       = "services.settings.changes.path";
 const PREF_SETTINGS_LAST_UPDATE        = "services.settings.last_update_seconds";
@@ -657,12 +662,31 @@ function remoteSettingsFunction() {
     // Save current Etag for next poll.
     if (currentEtag) {
       Services.prefs.setCharPref(PREF_SETTINGS_LAST_ETAG, currentEtag);
     }
 
     Services.obs.notifyObservers(null, "remote-settings-changes-polled");
   };
 
+
+  const broadcastID = "remote-settings/monitor_changes";
+  let currentVersion = "";
+  if (Services.prefs.prefHasUserValue(PREF_SETTINGS_LAST_ETAG)) {
+    currentVersion = Services.prefs.getCharPref(PREF_SETTINGS_LAST_ETAG);
+  }
+  const moduleInfo = {
+    moduleURI: __URI__,
+    symbolName: "remoteSettingsBroadcastHandler",
+  };
+  pushBroadcastService.addListener(broadcastID, currentVersion,
+                                   moduleInfo);
+
   return remoteSettings;
 }
 
 var RemoteSettings = remoteSettingsFunction();
+
+var remoteSettingsBroadcastHandler = {
+  async receivedBroadcastMessage(data, broadcastID) {
+    return RemoteSettings.pollChanges();
+  }
+};