Bug 1472238: compare old and new versions and prefer what we had r?lina
When a component registers after having already registered once, there
are two sources of truth for the version ID: one implicit in the
connection to Megaphone, and one coming from the component call to
addListener. Try to handle this more thoroughly.
MozReview-Commit-ID: EsYgO0mzQ9w
--- a/dom/push/PushBroadcastService.jsm
+++ b/dom/push/PushBroadcastService.jsm
@@ -114,21 +114,32 @@ var BroadcastService = class {
if (typeof version !== "string") {
throw new TypeError("version should be a string");
}
if (!version) {
throw new TypeError("version should not be an empty string");
}
const isNew = !this.jsonFile.data.listeners.hasOwnProperty(broadcastId);
+ const oldVersion = !isNew && this.jsonFile.data.listeners[broadcastId].version;
+ if (!isNew && oldVersion != version) {
+ console.warn("Versions differ while adding listener for", broadcastId,
+ ". Got", version, "but JSON file says", oldVersion, ".");
+ }
// Update listeners before telling the pushService to subscribe,
// in case it would disregard the update in the small window
// between getting listeners and setting state to RUNNING.
- this.jsonFile.data.listeners[broadcastId] = {version, sourceInfo};
+ //
+ // Keep the old version (if we have it) because Megaphone is
+ // really the source of truth for the current version of this
+ // broadcaster, and the old version is whatever we've either
+ // gotten from Megaphone or what we've told to Megaphone and
+ // haven't been corrected.
+ this.jsonFile.data.listeners[broadcastId] = {version: oldVersion || version, sourceInfo};
this.jsonFile.saveSoon();
if (isNew) {
await this.pushService.subscribeBroadcast(broadcastId, version);
}
}
async receivedBroadcastMessage(broadcasts) {