diff --git a/services/sync/modules/engines/tabs.js b/services/sync/modules/engines/tabs.js index a202ded491f..dce102d8775 100644 --- a/services/sync/modules/engines/tabs.js +++ b/services/sync/modules/engines/tabs.js @@ -2,13 +2,11 @@ * 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/. */ -this.EXPORTED_SYMBOLS = ['TabEngine', 'TabSetRecord']; +this.EXPORTED_SYMBOLS = ["TabEngine", "TabSetRecord"]; -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cu = Components.utils; +const {classes: Cc, interfaces: Ci, utils: Cu} = Components; -const TABS_TTL = 604800; // 7 days +const TABS_TTL = 604800; // 7 days. Cu.import("resource://gre/modules/Preferences.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); @@ -27,7 +25,7 @@ this.TabSetRecord = function TabSetRecord(collection, id) { TabSetRecord.prototype = { __proto__: CryptoWrapper.prototype, _logName: "Sync.Record.Tabs", - ttl: TABS_TTL + ttl: TABS_TTL, }; Utils.deferGetSet(TabSetRecord, "cleartext", ["clientName", "tabs"]); @@ -36,7 +34,7 @@ Utils.deferGetSet(TabSetRecord, "cleartext", ["clientName", "tabs"]); this.TabEngine = function TabEngine(service) { SyncEngine.call(this, "Tabs", service); - // Reset the client on every startup so that we fetch recent tabs + // Reset the client on every startup so that we fetch recent tabs. this._resetClient(); } TabEngine.prototype = { @@ -47,7 +45,7 @@ TabEngine.prototype = { syncPriority: 3, - getChangedIDs: function getChangedIDs() { + getChangedIDs: function () { // No need for a proper timestamp (no conflict resolution needed). let changedIDs = {}; if (this._tracker.modified) @@ -55,22 +53,22 @@ TabEngine.prototype = { return changedIDs; }, - // API for use by Weave UI code to give user choices of tabs to open: - getAllClients: function TabEngine_getAllClients() { + // API for use by Sync UI code to give user choices of tabs to open. + getAllClients: function () { return this._store._remoteClients; }, - getClientById: function TabEngine_getClientById(id) { + getClientById: function (id) { return this._store._remoteClients[id]; }, - _resetClient: function TabEngine__resetClient() { + _resetClient: function () { SyncEngine.prototype._resetClient.call(this); this._store.wipe(); this._tracker.modified = true; }, - removeClientData: function removeClientData() { + removeClientData: function () { let url = this.engineURL + "/" + this.service.clientsEngine.localID; this.service.resource(url).delete(); }, @@ -94,7 +92,7 @@ function TabStore(name, engine) { TabStore.prototype = { __proto__: Store.prototype, - itemExists: function TabStore_itemExists(id) { + itemExists: function (id) { return id == this.engine.service.clientsEngine.localID; }, @@ -155,7 +153,7 @@ TabStore.prototype = { return allTabs; }, - createRecord: function createRecord(id, collection) { + createRecord: function (id, collection) { let record = new TabSetRecord(collection, id); record.clientName = this.engine.service.clientsEngine.localName; @@ -188,7 +186,7 @@ TabStore.prototype = { return record; }, - getAllIDs: function TabStore_getAllIds() { + getAllIDs: function () { // Don't report any tabs if all windows are in private browsing for // first syncs. let ids = {}; @@ -214,31 +212,38 @@ TabStore.prototype = { return ids; }, - wipe: function TabStore_wipe() { + wipe: function () { this._remoteClients = {}; }, - create: function TabStore_create(record) { + create: function (record) { this._log.debug("Adding remote tabs from " + record.clientName); this._remoteClients[record.id] = record.cleartext; - // Lose some precision, but that's good enough (seconds) + // Lose some precision, but that's good enough (seconds). let roundModify = Math.floor(record.modified / 1000); let notifyState = Svc.Prefs.get("notifyTabState"); - // If there's no existing pref, save this first modified time - if (notifyState == null) + + // If there's no existing pref, save this first modified time. + if (notifyState == null) { Svc.Prefs.set("notifyTabState", roundModify); - // Don't change notifyState if it's already 0 (don't notify) - else if (notifyState == 0) return; - // We must have gotten a new tab that isn't the same as last time - else if (notifyState != roundModify) + } + + // Don't change notifyState if it's already 0 (don't notify). + if (notifyState == 0) { + return; + } + + // We must have gotten a new tab that isn't the same as last time. + if (notifyState != roundModify) { Svc.Prefs.set("notifyTabState", 0); + } }, - update: function update(record) { + update: function (record) { this._log.trace("Ignoring tab updates as local ones win"); - } + }, }; @@ -247,7 +252,7 @@ function TabTracker(name, engine) { Svc.Obs.add("weave:engine:start-tracking", this); Svc.Obs.add("weave:engine:stop-tracking", this); - // Make sure "this" pointer is always set correctly for event listeners + // Make sure "this" pointer is always set correctly for event listeners. this.onTab = Utils.bind2(this, this.onTab); this._unregisterListeners = Utils.bind2(this, this._unregisterListeners); } @@ -256,16 +261,17 @@ TabTracker.prototype = { QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]), - loadChangedIDs: function loadChangedIDs() { + loadChangedIDs: function () { // Don't read changed IDs from disk at start up. }, - clearChangedIDs: function clearChangedIDs() { + clearChangedIDs: function () { this.modified = false; }, _topics: ["pageshow", "TabOpen", "TabClose", "TabSelect"], - _registerListenersForWindow: function registerListenersFW(window) { + + _registerListenersForWindow: function (window) { this._log.trace("Registering tab listeners in window"); for each (let topic in this._topics) { window.addEventListener(topic, this.onTab, false); @@ -273,11 +279,11 @@ TabTracker.prototype = { window.addEventListener("unload", this._unregisterListeners, false); }, - _unregisterListeners: function unregisterListeners(event) { + _unregisterListeners: function (event) { this._unregisterListenersForWindow(event.target); }, - _unregisterListenersForWindow: function unregisterListenersFW(window) { + _unregisterListenersForWindow: function (window) { this._log.trace("Removing tab listeners in window"); window.removeEventListener("unload", this._unregisterListeners, false); for each (let topic in this._topics) { @@ -318,7 +324,7 @@ TabTracker.prototype = { } }, - onTab: function onTab(event) { + onTab: function (event) { if (event.originalTarget.linkedBrowser) { let browser = event.originalTarget.linkedBrowser; if (PrivateBrowsingUtils.isBrowserPrivate(browser) && @@ -334,7 +340,8 @@ TabTracker.prototype = { // For page shows, bump the score 10% of the time, emulating a partial // score. We don't want to sync too frequently. For all other page // events, always bump the score. - if (event.type != "pageshow" || Math.random() < .1) + if (event.type != "pageshow" || Math.random() < .1) { this.score += SCORE_INCREMENT_SMALL; + } }, -} +};