Bug 1440022: hook up remote-settings to broadcast messages r?lina
MozReview-Commit-ID: 3TYBqH94rSD
--- 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", {});
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch", "indexedDB"]);
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";
@@ -730,12 +735,33 @@ 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";
+ // When we start on a new profile there will be no ETag stored.
+ // Use an arbitrary ETag that is guaranteed not to occur.
+ // This will trigger a broadcast message but that's fine because we
+ // will check the changes on each collection and retrieve only the
+ // changes (e.g. nothing if we have a dump with the same data).
+ const currentVersion = Services.prefs.getStringPref(PREF_SETTINGS_LAST_ETAG, "\"0\"");
+ 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();
+ }
+};