Bug 821510 - Settings: remove debug statements. r=sicking, a=akeybl
authorGregor Wagner <anygregor@gmail.com>
Fri, 14 Dec 2012 10:20:16 -0800
changeset 122890 9eecd64f9b84278f5e4ab0b2d46cb7ed42a5406f
parent 122889 c94da132e7033190cdc4bd0169b64276076e41b8
child 122891 c28d377a35af4c042ce4fb904a4942bb5f7f45c9
push id273
push userlsblakk@mozilla.com
push dateThu, 14 Feb 2013 23:19:38 +0000
treeherdermozilla-release@c5e807a3f8b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking, akeybl
bugs821510
milestone19.0a2
Bug 821510 - Settings: remove debug statements. r=sicking, a=akeybl
dom/settings/SettingsChangeNotifier.jsm
dom/settings/SettingsDB.jsm
dom/settings/SettingsManager.js
--- a/dom/settings/SettingsChangeNotifier.jsm
+++ b/dom/settings/SettingsChangeNotifier.jsm
@@ -1,16 +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/. */
 
 "use strict"
 
+const DEBUG = false;
 function debug(s) {
-//  dump("-*- SettingsChangeNotifier: " + s + "\n");
+  if (DEBUG) dump("-*- SettingsChangeNotifier: " + s + "\n");
 }
 
 const Cu = Components.utils;
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 this.EXPORTED_SYMBOLS = ["SettingsChangeNotifier"];
 
@@ -22,29 +23,29 @@ const kMozSettingsChangedObserverTopic =
 const kFromSettingsChangeNotifier      = "fromSettingsChangeNotifier";
 
 XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
                                    "@mozilla.org/parentprocessmessagemanager;1",
                                    "nsIMessageBroadcaster");
 
 this.SettingsChangeNotifier = {
   init: function() {
-    debug("init");
+    if (DEBUG) debug("init");
     this.children = [];
     this._messages = ["Settings:Changed", "Settings:RegisterForMessages", "child-process-shutdown"];
     this._messages.forEach((function(msgName) {
       ppmm.addMessageListener(msgName, this);
     }).bind(this));
 
     Services.obs.addObserver(this, kXpcomShutdownObserverTopic, false);
     Services.obs.addObserver(this, kMozSettingsChangedObserverTopic, false);
   },
 
   observe: function(aSubject, aTopic, aData) {
-    debug("observe");
+    if (DEBUG) debug("observe");
     switch (aTopic) {
       case kXpcomShutdownObserverTopic:
         this._messages.forEach((function(msgName) {
           ppmm.removeMessageListener(msgName, this);
         }).bind(this));
         Services.obs.removeObserver(this, kXpcomShutdownObserverTopic);
         Services.obs.removeObserver(this, kMozSettingsChangedObserverTopic);
         ppmm = null;
@@ -57,30 +58,30 @@ this.SettingsChangeNotifier = {
         // messages that are notified from the internal SettingsChangeNotifier.
         if (setting.message && setting.message === kFromSettingsChangeNotifier)
           return;
         this.broadcastMessage("Settings:Change:Return:OK",
           { key: setting.key, value: setting.value });
         break;
       }
       default:
-        debug("Wrong observer topic: " + aTopic);
+        if (DEBUG) debug("Wrong observer topic: " + aTopic);
         break;
     }
   },
 
   broadcastMessage: function broadcastMessage(aMsgName, aContent) {
-    debug("Broadast");
+    if (DEBUG) debug("Broadast");
     this.children.forEach(function(msgMgr) {
       msgMgr.sendAsyncMessage(aMsgName, aContent);
     });
   },
 
   receiveMessage: function(aMessage) {
-    debug("receiveMessage");
+    if (DEBUG) debug("receiveMessage");
     let msg = aMessage.data;
     let mm = aMessage.target;
     switch (aMessage.name) {
       case "Settings:Changed":
         if (!aMessage.target.assertPermission("settings-write")) {
           Cu.reportError("Settings message " + msg.name +
                          " from a content process with no 'settings-write' privileges.");
           return null;
@@ -95,28 +96,28 @@ this.SettingsChangeNotifier = {
           }));
         break;
       case "Settings:RegisterForMessages":
         if (!aMessage.target.assertPermission("settings-read")) {
           Cu.reportError("Settings message " + msg.name +
                          " from a content process with no 'settings-read' privileges.");
           return null;
         }
-        debug("Register!");
+        if (DEBUG) debug("Register!");
         if (this.children.indexOf(mm) == -1) {
           this.children.push(mm);
         }
         break;
       case "child-process-shutdown":
-        debug("Unregister");
+        if (DEBUG) debug("Unregister");
         let index;
         if ((index = this.children.indexOf(mm)) != -1) {
-          debug("Unregister index: " + index);
+          if (DEBUG) debug("Unregister index: " + index);
           this.children.splice(index, 1);
         }
         break;
       default:
-        debug("Wrong message: " + aMessage.name);
+        if (DEBUG) debug("Wrong message: " + aMessage.name);
     }
   }
 }
 
 SettingsChangeNotifier.init();
--- a/dom/settings/SettingsDB.jsm
+++ b/dom/settings/SettingsDB.jsm
@@ -3,18 +3,19 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 let Cc = Components.classes;
 let Ci = Components.interfaces;
 let Cu = Components.utils;
 
 this.EXPORTED_SYMBOLS = ["SettingsDB", "SETTINGSDB_NAME", "SETTINGSSTORE_NAME"];
 
+const DEBUG = false;
 function debug(s) {
-  //dump("-*- SettingsDB: " + s + "\n");
+  if (DEBUG) dump("-*- SettingsDB: " + s + "\n");
 }
 
 this.SETTINGSDB_NAME = "settings";
 this.SETTINGSDB_VERSION = 1;
 this.SETTINGSSTORE_NAME = "settings";
 
 Cu.import("resource://gre/modules/IndexedDBHelper.jsm");
 Cu.import("resource://gre/modules/FileUtils.jsm");
@@ -25,17 +26,17 @@ this.SettingsDB = function SettingsDB() 
 SettingsDB.prototype = {
 
   __proto__: IndexedDBHelper.prototype,
 
   upgradeSchema: function upgradeSchema(aTransaction, aDb, aOldVersion, aNewVersion) {
     let objectStore = aDb.createObjectStore(SETTINGSSTORE_NAME,
                                             { keyPath: "settingName" });
     objectStore.createIndex("settingValue", "settingValue", { unique: false });
-    debug("Created object stores and indexes");
+    if (DEBUG) debug("Created object stores and indexes");
 
     if (aOldVersion != 0) {
       return;
     }
 
     // Loading resource://app/defaults/settings.json doesn't work because
     // settings.json is not in the omnijar.
     // So we look for the app dir instead and go from here...
@@ -57,22 +58,22 @@ SettingsDB.prototype = {
     converter.charset = "UTF-8";
     let rawstr = converter.ConvertToUnicode(NetUtil.readInputStreamToString(
                                             stream,
                                             stream.available()) || "");
     let settings;
     try {
       settings = JSON.parse(rawstr);
     } catch(e) {
-      debug("Error parsing " + settingsFile.path + " : " + e);
+      if (DEBUG) debug("Error parsing " + settingsFile.path + " : " + e);
       return;
     }
 
     for (let setting in settings) {
-      debug("Adding setting " + setting);
+      if (DEBUG) debug("Adding setting " + setting);
       objectStore.put({ settingName: setting,
                         settingValue: settings[setting] });
     }
   },
 
   init: function init(aGlobal) {
     this.initDBHelper(SETTINGSDB_NAME, SETTINGSDB_VERSION,
                       SETTINGSSTORE_NAME, aGlobal);
--- a/dom/settings/SettingsManager.js
+++ b/dom/settings/SettingsManager.js
@@ -1,16 +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/. */
 
 "use strict";
 
+const DEBUG = false;
 function debug(s) {
-//  dump("-*- SettingsManager: " + s + "\n");
+  if (DEBUG) dump("-*- SettingsManager: " + s + "\n");
 }
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/SettingsQueue.jsm");
 Cu.import("resource://gre/modules/SettingsDB.jsm");
@@ -38,34 +39,34 @@ SettingsLock.prototype = {
 
   process: function process() {
     let lock = this;
     lock._open = false;
     let store = lock._transaction.objectStore(SETTINGSSTORE_NAME);
 
     while (!lock._requests.isEmpty()) {
       let info = lock._requests.dequeue();
-      debug("info: " + info.intent);
+      if (DEBUG) debug("info: " + info.intent);
       let request = info.request;
       switch (info.intent) {
         case "clear":
           let req = store.clear();
           req.onsuccess = function() { this._open = true;
                                        Services.DOMRequest.fireSuccess(request, 0);
                                        this._open = false; }.bind(lock);
           req.onerror = function() { Services.DOMRequest.fireError(request, 0) };
           break;
         case "set":
           for (let key in info.settings) {
-            debug("key: " + key + ", val: " + JSON.stringify(info.settings[key]) + ", type: " + typeof(info.settings[key]));
+            if (DEBUG) debug("key: " + key + ", val: " + JSON.stringify(info.settings[key]) + ", type: " + typeof(info.settings[key]));
 
             let checkKeyRequest = store.get(key);
             checkKeyRequest.onsuccess = function (event) {
               if (!event.target.result) {
-                debug("MOZSETTINGS-SET-WARNING: " + key + " is not in the database. Please add it to build/settings.js\n");
+                if (DEBUG) debug("MOZSETTINGS-SET-WARNING: " + key + " is not in the database. Please add it to build/settings.js\n");
               }
             }
 
             if(typeof(info.settings[key]) != 'object') {
               req = store.put({settingName: key, settingValue: info.settings[key]});
             } else {
               //Workaround for cloning issues
               let obj = JSON.parse(JSON.stringify(info.settings[key]));
@@ -84,22 +85,22 @@ SettingsLock.prototype = {
             };
           }
           break;
         case "get":
           req = (info.name === "*") ? store.mozGetAll()
                                     : store.mozGetAll(info.name);
 
           req.onsuccess = function(event) {
-            debug("Request for '" + info.name + "' successful. " + 
+            if (DEBUG) debug("Request for '" + info.name + "' successful. " + 
                   "Record count: " + event.target.result.length);
-            debug("result: " + JSON.stringify(event.target.result));
+            if (DEBUG) debug("result: " + JSON.stringify(event.target.result));
 
             if (event.target.result.length == 0) {
-              debug("MOZSETTINGS-GET-WARNING: " + info.name + " is not in the database. Please add it to build/settings.js\n");
+              if (DEBUG) debug("MOZSETTINGS-GET-WARNING: " + info.name + " is not in the database. Please add it to build/settings.js\n");
             }
 
             let results = {
               __exposedProps__: {
               }
             };
 
             for (var i in event.target.result) {
@@ -154,52 +155,52 @@ SettingsLock.prototype = {
     }
 
     if (this._settingsManager.hasReadPrivileges) {
       let req = Services.DOMRequest.createRequest(this._settingsManager._window);
       this._requests.enqueue({ request: req, intent:"get", name: aName });
       this.createTransactionAndProcess();
       return req;
     } else {
-      debug("get not allowed");
+      if (DEBUG) debug("get not allowed");
       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
     }
   },
 
   set: function set(aSettings) {
     if (!this._open) {
       dump("Settings lock not open!\n");
       throw Components.results.NS_ERROR_ABORT;
     }
 
     if (this._settingsManager.hasWritePrivileges) {
       let req = Services.DOMRequest.createRequest(this._settingsManager._window);
-      debug("send: " + JSON.stringify(aSettings));
+      if (DEBUG) debug("send: " + JSON.stringify(aSettings));
       this._requests.enqueue({request: req, intent: "set", settings: aSettings});
       this.createTransactionAndProcess();
       return req;
     } else {
-      debug("set not allowed");
+      if (DEBUG) debug("set not allowed");
       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
     }
   },
 
   clear: function clear() {
     if (!this._open) {
       dump("Settings lock not open!\n");
       throw Components.results.NS_ERROR_ABORT;
     }
 
     if (this._settingsManager.hasWritePrivileges) {
       let req = Services.DOMRequest.createRequest(this._settingsManager._window);
       this._requests.enqueue({ request: req, intent: "clear"});
       this.createTransactionAndProcess();
       return req;
     } else {
-      debug("clear not allowed");
+      if (DEBUG) debug("clear not allowed");
       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
     }
   },
 
   classID : SETTINGSLOCK_CID,
   QueryInterface : XPCOMUtils.generateQI([nsIDOMSettingsLock]),
 
   classInfo : XPCOMUtils.generateCI({classID: SETTINGSLOCK_CID,
@@ -248,84 +249,84 @@ SettingsManager.prototype = {
     }
   },
 
   get onsettingchange() {
     return this._onsettingchange;
   },
 
   createLock: function() {
-    debug("get lock!");
+    if (DEBUG) debug("get lock!");
     var lock = new SettingsLock(this);
     this._locks.enqueue(lock);
     this._settingsDB.ensureDB(
       function() { lock.createTransactionAndProcess(); },
       function() { dump("ensureDB error cb!\n"); },
       myGlobal );
     this.nextTick(function() { this._open = false; }, lock);
     return lock;
   },
 
   receiveMessage: function(aMessage) {
-    debug("Settings::receiveMessage: " + aMessage.name);
+    if (DEBUG) debug("Settings::receiveMessage: " + aMessage.name);
     let msg = aMessage.json;
 
     switch (aMessage.name) {
       case "Settings:Change:Return:OK":
-        debug("Settings:Change:Return:OK");
+        if (DEBUG) debug("Settings:Change:Return:OK");
         if (this._onsettingchange || this._callbacks) {
-          debug('data:' + msg.key + ':' + msg.value + '\n');
+          if (DEBUG) debug('data:' + msg.key + ':' + msg.value + '\n');
 
           if (this._onsettingchange) {
             let event = new this._window.MozSettingsEvent("settingchanged", {
               settingName: msg.key,
               settingValue: msg.value
             });
             this._onsettingchange.handleEvent(event);
           }
           if (this._callbacks && this._callbacks[msg.key]) {
-            debug("observe callback called! " + msg.key + " " + this._callbacks[msg.key].length);
+            if (DEBUG) debug("observe callback called! " + msg.key + " " + this._callbacks[msg.key].length);
             this._callbacks[msg.key].forEach(function(cb) {
               cb({settingName: msg.key, settingValue: msg.value,
                   __exposedProps__: {settingName: 'r', settingValue: 'r'}});
             });
           }
         } else {
-          debug("no observers stored!");
+          if (DEBUG) debug("no observers stored!");
         }
         break;
       default: 
-        debug("Wrong message: " + aMessage.name);
+        if (DEBUG) debug("Wrong message: " + aMessage.name);
     }
   },
 
   addObserver: function addObserver(aName, aCallback) {
-    debug("addObserver " + aName);
+    if (DEBUG) debug("addObserver " + aName);
     if (!this._callbacks) {
       cpmm.sendAsyncMessage("Settings:RegisterForMessages");
       this._callbacks = {};
     }
     if (!this._callbacks[aName]) {
       this._callbacks[aName] = [aCallback];
     } else {
       this._callbacks[aName].push(aCallback);
     }
   },
 
   removeObserver: function removeObserver(aName, aCallback) {
-    debug("deleteObserver " + aName);
+    if (DEBUG) debug("deleteObserver " + aName);
     if (this._callbacks && this._callbacks[aName]) {
       let index = this._callbacks[aName].indexOf(aCallback)
       if (index != -1) {
         this._callbacks[aName].splice(index, 1)
       } else {
-        debug("Callback not found for: " + aName);
+        if (DEBUG) debug("Callback not found for: " + aName);
       }
     } else {
-      debug("No observers stored for " + aName);
+      if (DEBUG) debug("No observers stored for " + aName);
     }
   },
 
   init: function(aWindow) {
     // Set navigator.mozSettings to null.
     if (!Services.prefs.getBoolPref("dom.mozSettings.enabled"))
       return null;
 
@@ -342,17 +343,17 @@ SettingsManager.prototype = {
 
     if (!this.hasReadPrivileges && !this.hasWritePrivileges) {
       Cu.reportError("NO SETTINGS PERMISSION FOR: " + aWindow.document.nodePrincipal.origin + "\n");
       return null;
     }
   },
 
   observe: function(aSubject, aTopic, aData) {
-    debug("Topic: " + aTopic);
+    if (DEBUG) debug("Topic: " + aTopic);
     if (aTopic == "inner-window-destroyed") {
       let wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
       if (wId == this.innerWindowID) {
         Services.obs.removeObserver(this, "inner-window-destroyed");
         cpmm.removeMessageListener("Settings:Change:Return:OK", this);
         this._requests = null;
         this._window = null;
         this._innerWindowID = null;