Bug 1440022: hook up remote-settings to broadcast messages r=lina

MozReview-Commit-ID: 3TYBqH94rSD

--HG--
extra : rebase_source : a529993dd94eca2f66566892839c64a4a9bcfb8f
This commit is contained in:
Ethan Glasser-Camp 2018-05-08 11:53:06 -04:00
parent bad5e0b59e
commit 5c4b4a744b

View File

@ -2,11 +2,14 @@
* 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");
@ -26,6 +29,8 @@ 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";
@ -735,7 +740,28 @@ function remoteSettingsFunction() {
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();
}
};