Bug 1085774 - Part 0: cleanup in tabs engine. r=trivial
authorRichard Newman <rnewman@mozilla.com>
Sun, 30 Nov 2014 19:34:58 -0800
changeset 218146 b0e899a4f71749531e8e4cf9f344d955bb043ccf
parent 218145 675e43d7ed076340c70f46736ea0aa00f3f16136
child 218147 9dffef3538c3c683e1804ce14a5713e334bcff90
push id27917
push usercbook@mozilla.com
push dateMon, 01 Dec 2014 11:03:31 +0000
treeherdermozilla-central@707a34b55e44 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstrivial
bugs1085774
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1085774 - Part 0: cleanup in tabs engine. r=trivial
services/sync/modules/engines/tabs.js
--- a/services/sync/modules/engines/tabs.js
+++ b/services/sync/modules/engines/tabs.js
@@ -1,19 +1,17 @@
 /* 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/. */
 
-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");
 Cu.import("resource://services-sync/engines.js");
 Cu.import("resource://services-sync/engines/clients.js");
 Cu.import("resource://services-sync/record.js");
 Cu.import("resource://services-sync/util.js");
 Cu.import("resource://services-sync/constants.js");
@@ -22,60 +20,60 @@ XPCOMUtils.defineLazyModuleGetter(this, 
   "resource://gre/modules/PrivateBrowsingUtils.jsm");
 
 this.TabSetRecord = function TabSetRecord(collection, id) {
   CryptoWrapper.call(this, collection, id);
 }
 TabSetRecord.prototype = {
   __proto__: CryptoWrapper.prototype,
   _logName: "Sync.Record.Tabs",
-  ttl: TABS_TTL
+  ttl: TABS_TTL,
 };
 
 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 = {
   __proto__: SyncEngine.prototype,
   _storeObj: TabStore,
   _trackerObj: TabTracker,
   _recordObj: TabSetRecord,
 
   syncPriority: 3,
 
-  getChangedIDs: function getChangedIDs() {
+  getChangedIDs: function () {
     // No need for a proper timestamp (no conflict resolution needed).
     let changedIDs = {};
     if (this._tracker.modified)
       changedIDs[this.service.clientsEngine.localID] = 0;
     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();
   },
 
   /**
    * Return a Set of open URLs.
    */
   getOpenURLs: function () {
@@ -89,17 +87,17 @@ TabEngine.prototype = {
 
 
 function TabStore(name, engine) {
   Store.call(this, name, engine);
 }
 TabStore.prototype = {
   __proto__: Store.prototype,
 
-  itemExists: function TabStore_itemExists(id) {
+  itemExists: function (id) {
     return id == this.engine.service.clientsEngine.localID;
   },
 
   getWindowEnumerator: function () {
     return Services.wm.getEnumerator("navigator:browser");
   },
 
   shouldSkipWindow: function (win) {
@@ -150,17 +148,17 @@ TabStore.prototype = {
           lastUsed: Math.floor((tabState.lastAccessed || 0) / 1000)
         });
       }
     }
 
     return allTabs;
   },
 
-  createRecord: function createRecord(id, collection) {
+  createRecord: function (id, collection) {
     let record = new TabSetRecord(collection, id);
     record.clientName = this.engine.service.clientsEngine.localName;
 
     // Sort tabs in descending-used order to grab the most recently used
     let tabs = this.getAllTabs(true).sort(function (a, b) {
       return b.lastUsed - a.lastUsed;
     });
 
@@ -183,17 +181,17 @@ TabStore.prototype = {
     tabs.forEach(function (tab) {
       this._log.trace("Wrapping tab: " + JSON.stringify(tab));
     }, this);
 
     record.tabs = tabs;
     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 = {};
     let allWindowsArePrivate = false;
     let wins = Services.wm.getEnumerator("navigator:browser");
     while (wins.hasMoreElements()) {
       if (PrivateBrowsingUtils.isWindowPrivate(wins.getNext())) {
         // Ensure that at least there is a private window.
@@ -209,80 +207,88 @@ TabStore.prototype = {
         !PrivateBrowsingUtils.permanentPrivateBrowsing) {
       return ids;
     }
 
     ids[this.engine.service.clientsEngine.localID] = true;
     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;
+    }
+
+    // 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
-    else if (notifyState != roundModify)
+    }
+
+    // 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");
-  }
+  },
 };
 
 
 function TabTracker(name, engine) {
   Tracker.call(this, 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);
 }
 TabTracker.prototype = {
   __proto__: Tracker.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);
     }
     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) {
       window.removeEventListener(topic, this.onTab, false);
     }
   },
 
   startTracking: function () {
@@ -313,28 +319,29 @@ TabTracker.prototype = {
         };
 
         // Add tab listeners now that a window has opened.
         subject.addEventListener("load", onLoad, false);
         break;
     }
   },
 
-  onTab: function onTab(event) {
+  onTab: function (event) {
     if (event.originalTarget.linkedBrowser) {
       let browser = event.originalTarget.linkedBrowser;
       if (PrivateBrowsingUtils.isBrowserPrivate(browser) &&
           !PrivateBrowsingUtils.permanentPrivateBrowsing) {
         this._log.trace("Ignoring tab event from private browsing.");
         return;
       }
     }
 
     this._log.trace("onTab event: " + event.type);
     this.modified = true;
 
     // 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;
+    }
   },
-}
+};