Bug 784746 - Contacts API: optimize debug statements. r=bent
authorGregor Wagner <anygregor@gmail.com>
Wed, 22 Aug 2012 14:34:57 -0700
changeset 103076 3f340329e85bdc81c60acf4ce926e23f93946597
parent 103075 9209d9af04d4053e67361eec953f2d1f33fc8c0c
child 103077 80c3029990c656f861a4cf8d990cb8f515b91870
push id23326
push useremorley@mozilla.com
push dateThu, 23 Aug 2012 10:36:26 +0000
treeherdermozilla-central@198ca6edd0ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs784746
milestone17.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 784746 - Contacts API: optimize debug statements. r=bent
dom/contacts/ContactManager.js
dom/contacts/fallback/ContactDB.jsm
dom/contacts/fallback/ContactService.jsm
--- a/dom/contacts/ContactManager.js
+++ b/dom/contacts/ContactManager.js
@@ -1,20 +1,16 @@
 /* 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";
 
-/* static functions */
-let DEBUG = 0;
-if (DEBUG)
-  debug = function (s) { dump("-*- ContactManager: " + s + "\n"); }
-else
-  debug = function (s) {}
+const DEBUG = false;
+function debug(s) { dump("-*- ContactManager: " + s + "\n"); }
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
@@ -32,17 +28,17 @@ XPCOMUtils.defineLazyGetter(this, "mRIL"
 });
 
 const nsIClassInfo            = Ci.nsIClassInfo;
 const CONTACTPROPERTIES_CID   = Components.ID("{f5181640-89e8-11e1-b0c4-0800200c9a66}");
 const nsIDOMContactProperties = Ci.nsIDOMContactProperties;
 
 // ContactProperties is not directly instantiated. It is used as interface.
 
-function ContactProperties(aProp) { debug("ContactProperties Constructor"); }
+function ContactProperties(aProp) { if (DEBUG) debug("ContactProperties Constructor"); }
 
 ContactProperties.prototype = {
 
   classID : CONTACTPROPERTIES_CID,
   classInfo : XPCOMUtils.generateCI({classID: CONTACTPROPERTIES_CID,
                                      contractID:"@mozilla.org/contactProperties;1",
                                      classDescription: "ContactProperties",
                                      interfaces: [nsIDOMContactProperties],
@@ -163,20 +159,19 @@ ContactFindOptions.prototype = {
 }
 
 //Contact
 
 const CONTACT_CONTRACTID = "@mozilla.org/contact;1";
 const CONTACT_CID        = Components.ID("{da0f7040-388b-11e1-b86c-0800200c9a66}");
 const nsIDOMContact      = Components.interfaces.nsIDOMContact;
 
-// The wrappedJSObject magic here allows callers to get at the underlying JS object
-// of the XPCOM component. We use this below to modify properties that are read-only
-// per-idl. See https://developer.mozilla.org/en-US/docs/wrappedJSObject.
-function Contact() { debug("Contact constr: "); this.wrappedJSObject = this; };
+function Contact() {
+  if (DEBUG) debug("Contact constr: ");
+};
 
 Contact.prototype = {
   __exposedProps__: {
                       id: 'rw',
                       updated: 'rw',
                       published:  'rw',
                       name: 'rw',
                       honorificPrefix: 'rw',
@@ -328,25 +323,25 @@ Contact.prototype = {
 // ContactManager
 
 const CONTACTMANAGER_CONTRACTID = "@mozilla.org/contactManager;1";
 const CONTACTMANAGER_CID        = Components.ID("{d88af7e0-a45f-11e1-b3dd-0800200c9a66}");
 const nsIDOMContactManager      = Components.interfaces.nsIDOMContactManager;
 
 function ContactManager()
 {
-  debug("Constructor");
+  if (DEBUG) debug("Constructor");
 }
 
 ContactManager.prototype = {
   __proto__: DOMRequestIpcHelper.prototype,
   _oncontactchange: null,
 
   set oncontactchange(aCallback) {
-    debug("set oncontactchange");
+    if (DEBUG) debug("set oncontactchange");
     let allowCallback = function() {
       this._oncontactchange = aCallback;
     }.bind(this);
     let cancelCallback = function() {
       throw Components.results.NS_ERROR_FAILURE;
     }
     this.askPermission("listen", null, allowCallback, cancelCallback);
   },
@@ -368,28 +363,28 @@ ContactManager.prototype = {
       newContact.init(aContacts[i].properties);
       this._setMetaData(newContact, aContacts[i]);
       contacts.push(newContact);
     }
     return contacts;
   },
 
   receiveMessage: function(aMessage) {
-    debug("Contactmanager::receiveMessage: " + aMessage.name);
+    if (DEBUG) debug("Contactmanager::receiveMessage: " + aMessage.name);
     let msg = aMessage.json;
     let contacts = msg.contacts;
 
     switch (aMessage.name) {
       case "Contacts:Find:Return:OK":
         let req = this.getRequest(msg.requestID);
         if (req) {
           let result = this._convertContactsArray(contacts);
           Services.DOMRequest.fireSuccess(req.request, result);
         } else {
-          debug("no request stored!" + msg.requestID);
+          if (DEBUG) debug("no request stored!" + msg.requestID);
         }
         break;
       case "Contact:Save:Return:OK":
       case "Contacts:Clear:Return:OK":
       case "Contact:Remove:Return:OK":
         req = this.getRequest(msg.requestID);
         if (req)
           Services.DOMRequest.fireSuccess(req.request, null);
@@ -407,36 +402,36 @@ ContactManager.prototype = {
       case "Contact:Save:Return:KO":
       case "Contact:Remove:Return:KO":
       case "Contacts:Clear:Return:KO":
         req = this.getRequest(msg.requestID);
         if (req)
           Services.DOMRequest.fireError(req.request, msg.errorMsg);
         break;
       case "PermissionPromptHelper:AskPermission:OK":
-        debug("id: " + msg.requestID);
+        if (DEBUG) debug("id: " + msg.requestID);
         req = this.getRequest(msg.requestID);
         if (!req) {
           break;
         }
 
         if (msg.result == Ci.nsIPermissionManager.ALLOW_ACTION) {
           req.allow();
         } else {
           req.cancel();
         }
         break;
       default: 
-        debug("Wrong message: " + aMessage.name);
+        if (DEBUG) debug("Wrong message: " + aMessage.name);
     }
     this.removeRequest(msg.requestID);
   },
 
   askPermission: function (aAccess, aReqeust, aAllowCallback, aCancelCallback) {
-    debug("askPermission for contacts");
+    if (DEBUG) debug("askPermission for contacts");
     let requestID = this.getRequestId({
       request: aReqeust,
       allow: function() {
         aAllowCallback();
       }.bind(this),
       cancel : function() {
         if (aCancelCallback) {
           aCancelCallback()
@@ -454,17 +449,17 @@ ContactManager.prototype = {
       origin: principal.origin,
       appID: principal.appId,
       browserFlag: principal.isInBrowserElement
     });
   },
 
   save: function save(aContact) {
     let request;
-    debug("save: " + JSON.stringify(aContact) + " :" + aContact.id);
+    if (DEBUG) debug("save: " + JSON.stringify(aContact) + " :" + aContact.id);
     let newContact = {};
     newContact.properties = {
       name:            [],
       honorificPrefix: [],
       givenName:       [],
       additionalName:  [],
       familyName:      [],
       honorificSuffix: [],
@@ -494,28 +489,28 @@ ContactManager.prototype = {
       // 25c00f0190e5c545b4d421E2ddbab9e0
       aContact.id = this._getRandomId().replace('-', '', 'g').replace('{', '').replace('}', '');
       reason = "create";
     } else {
       reason = "update";
     }
 
     this._setMetaData(newContact, aContact);
-    debug("send: " + JSON.stringify(newContact));
+    if (DEBUG) debug("send: " + JSON.stringify(newContact));
     request = this.createRequest();
     let options = { contact: newContact };
     let allowCallback = function() {
       cpmm.sendAsyncMessage("Contact:Save", {requestID: this.getRequestId({request: request, reason: reason}), options: options});
     }.bind(this)
     this.askPermission(reason, request, allowCallback);
     return request;
   },
 
   find: function(aOptions) {
-    debug("find! " + JSON.stringify(aOptions));
+    if (DEBUG) debug("find! " + JSON.stringify(aOptions));
     let request;
     request = this.createRequest();
     let options = { findOptions: aOptions };
     let allowCallback = function() {
       cpmm.sendAsyncMessage("Contacts:Find", {requestID: this.getRequestId({request: request, reason: "find"}), options: options});
     }.bind(this)
     this.askPermission("find", request, allowCallback);
     return request;
@@ -528,43 +523,43 @@ ContactManager.prototype = {
     let allowCallback = function() {
       cpmm.sendAsyncMessage("Contact:Remove", {requestID: this.getRequestId({request: request, reason: "remove"}), options: options});
     }.bind(this)
     this.askPermission("remove", request, allowCallback);
     return request;
   },
 
   clear: function() {
-    debug("clear");
+    if (DEBUG) debug("clear");
     let request;
     request = this.createRequest();
     let options = {};
     let allowCallback = function() {
       cpmm.sendAsyncMessage("Contacts:Clear", {requestID: this.getRequestId({request: request, reason: "remove"}), options: options});
     }.bind(this)
     this.askPermission("remove", request, allowCallback);
     return request;
   },
 
   getSimContacts: function(aType) {
     let request;
     request = this.createRequest();
 
     let allowCallback = function() {
       let callback = function(aType, aContacts) {
-        debug("got SIM contacts: " + aType + " " + JSON.stringify(aContacts));
+        if (DEBUG) debug("got SIM contacts: " + aType + " " + JSON.stringify(aContacts));
         let result = aContacts.map(function(c) {
           var contact = new Contact();
           contact.init( { name: [c.alphaId], tel: [ { number: c.number } ] } );
           return contact;
         });
-        debug("result: " + JSON.stringify(result));
+        if (DEBUG) debug("result: " + JSON.stringify(result));
         Services.DOMRequest.fireSuccess(request, result);
       };
-      debug("getSimContacts " + aType);
+      if (DEBUG) debug("getSimContacts " + aType);
 
       mRIL.getICCContacts(aType, callback);
     }.bind(this);
 
     let cancelCallback = function() {
       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
     }
     this.askPermission("getSimContacts", request, allowCallback, cancelCallback);
@@ -580,17 +575,17 @@ ContactManager.prototype = {
                               "Contacts:Clear:Return:OK", "Contacts:Clear:Return:KO",
                               "Contact:Save:Return:OK", "Contact:Save:Return:KO",
                               "Contact:Remove:Return:OK", "Contact:Remove:Return:KO",
                               "PermissionPromptHelper:AskPermission:OK"]);
   },
 
   // Called from DOMRequestIpcHelper
   uninit: function uninit() {
-    debug("uninit call");
+    if (DEBUG) debug("uninit call");
     if (this._oncontactchange)
       this._oncontactchange = null;
   },
 
   classID : CONTACTMANAGER_CID,
   QueryInterface : XPCOMUtils.generateQI([nsIDOMContactManager, Ci.nsIDOMGlobalPropertyInitializer]),
 
   classInfo : XPCOMUtils.generateCI({classID: CONTACTMANAGER_CID,
--- a/dom/contacts/fallback/ContactDB.jsm
+++ b/dom/contacts/fallback/ContactDB.jsm
@@ -1,61 +1,56 @@
 /* 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 EXPORTED_SYMBOLS = ['ContactDB'];
 
-let DEBUG = 0;
-/* static functions */
-if (DEBUG) {
-  debug = function (s) { dump("-*- ContactDB component: " + s + "\n"); }
-} else {
-  debug = function (s) {}
-}
+const DEBUG = false;
+function debug(s) { dump("-*- ContactDB component: " + s + "\n"); }
 
 const Cu = Components.utils;
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/IndexedDBHelper.jsm");
 
 const DB_NAME = "contacts";
 const DB_VERSION = 4;
 const STORE_NAME = "contacts";
 
 function ContactDB(aGlobal) {
-  debug("Constructor");
+  if (DEBUG) debug("Constructor");
   this._global = aGlobal;
 }
 
 ContactDB.prototype = {
   __proto__: IndexedDBHelper.prototype,
 
   upgradeSchema: function upgradeSchema(aTransaction, aDb, aOldVersion, aNewVersion) {
-    debug("upgrade schema from: " + aOldVersion + " to " + aNewVersion + " called!");
+    if (DEBUG) debug("upgrade schema from: " + aOldVersion + " to " + aNewVersion + " called!");
     let db = aDb;
     let objectStore;
     for (let currVersion = aOldVersion; currVersion < aNewVersion; currVersion++) {
       if (currVersion == 0) {
         /**
          * Create the initial database schema.
          *
          * The schema of records stored is as follows:
          *
          * {id:            "...",       // UUID
          *  published:     Date(...),   // First published date.
          *  updated:       Date(...),   // Last updated date.
          *  properties:    {...}        // Object holding the ContactProperties
          * }
          */
-        debug("create schema");
+        if (DEBUG) debug("create schema");
         objectStore = db.createObjectStore(this.dbStoreName, {keyPath: "id"});
 
         // Metadata indexes
         objectStore.createIndex("published", "published", { unique: false });
         objectStore.createIndex("updated",   "updated",   { unique: false });
 
         // Properties indexes
         objectStore.createIndex("nickname",   "properties.nickname",   { unique: false, multiEntry: true });
@@ -69,96 +64,96 @@ ContactDB.prototype = {
         objectStore.createIndex("nicknameLowerCase",   "search.nickname",   { unique: false, multiEntry: true });
         objectStore.createIndex("nameLowerCase",       "search.name",       { unique: false, multiEntry: true });
         objectStore.createIndex("familyNameLowerCase", "search.familyName", { unique: false, multiEntry: true });
         objectStore.createIndex("givenNameLowerCase",  "search.givenName",  { unique: false, multiEntry: true });
         objectStore.createIndex("telLowerCase",        "search.tel",        { unique: false, multiEntry: true });
         objectStore.createIndex("emailLowerCase",      "search.email",      { unique: false, multiEntry: true });
         objectStore.createIndex("noteLowerCase",       "search.note",       { unique: false, multiEntry: true });
       } else if (currVersion == 1) {
-        debug("upgrade 1");
+        if (DEBUG) debug("upgrade 1");
 
         // Create a new scheme for the tel field. We move from an array of tel-numbers to an array of
         // ContactTelephone.
         if (!objectStore) {
           objectStore = aTransaction.objectStore(STORE_NAME);
         }
         // Delete old tel index.
         objectStore.deleteIndex("tel");
 
         // Upgrade existing tel field in the DB.
         objectStore.openCursor().onsuccess = function(event) {
           let cursor = event.target.result;
           if (cursor) {
-            debug("upgrade tel1: " + JSON.stringify(cursor.value));
+            if (DEBUG) debug("upgrade tel1: " + JSON.stringify(cursor.value));
             for (let number in cursor.value.properties.tel) {
               cursor.value.properties.tel[number] = {number: number};
             }
             cursor.update(cursor.value);
-            debug("upgrade tel2: " + JSON.stringify(cursor.value));
+            if (DEBUG) debug("upgrade tel2: " + JSON.stringify(cursor.value));
             cursor.continue();
           }
         };
 
         // Create new searchable indexes.
         objectStore.createIndex("tel", "search.tel", { unique: false, multiEntry: true });
         objectStore.createIndex("category", "properties.category", { unique: false, multiEntry: true });
       } else if (currVersion == 2) {
-        debug("upgrade 2");
+        if (DEBUG) debug("upgrade 2");
         // Create a new scheme for the email field. We move from an array of emailaddresses to an array of 
         // ContactEmail.
         if (!objectStore) {
           objectStore = aTransaction.objectStore(STORE_NAME);
         }
         // Delete old email index.
         objectStore.deleteIndex("email");
 
         // Upgrade existing email field in the DB.
         objectStore.openCursor().onsuccess = function(event) {
           let cursor = event.target.result;
           if (cursor) {
-            debug("upgrade email1: " + JSON.stringify(cursor.value));
+            if (DEBUG) debug("upgrade email1: " + JSON.stringify(cursor.value));
             cursor.value.properties.email =
               cursor.value.properties.email.map(function(address) { return { address: address }; });
             cursor.update(cursor.value);
-            debug("upgrade email2: " + JSON.stringify(cursor.value));
+            if (DEBUG) debug("upgrade email2: " + JSON.stringify(cursor.value));
             cursor.continue();
           }
         };
 
         // Create new searchable indexes.
         objectStore.createIndex("email", "search.email", { unique: false, multiEntry: true });
       } else if (currVersion == 3) {
-        debug("upgrade 3");
+        if (DEBUG) debug("upgrade 3");
 
         if (!objectStore) {
           objectStore = aTransaction.objectStore(STORE_NAME);
         }
 
         // Upgrade existing impp field in the DB.
         objectStore.openCursor().onsuccess = function(event) {
           let cursor = event.target.result;
           if (cursor) {
-            debug("upgrade impp1: " + JSON.stringify(cursor.value));
+            if (DEBUG) debug("upgrade impp1: " + JSON.stringify(cursor.value));
             cursor.value.properties.impp =
               cursor.value.properties.impp.map(function(value) { return { value: value }; });
             cursor.update(cursor.value);
-            debug("upgrade impp2: " + JSON.stringify(cursor.value));
+            if (DEBUG) debug("upgrade impp2: " + JSON.stringify(cursor.value));
             cursor.continue();
           }
         };
         // Upgrade existing url field in the DB.
         objectStore.openCursor().onsuccess = function(event) {
           let cursor = event.target.result;
           if (cursor) {
-            debug("upgrade url1: " + JSON.stringify(cursor.value));
+            if (DEBUG) debug("upgrade url1: " + JSON.stringify(cursor.value));
             cursor.value.properties.url =
               cursor.value.properties.url.map(function(value) { return { value: value }; });
             cursor.update(cursor.value);
-            debug("upgrade impp2: " + JSON.stringify(cursor.value));
+            if (DEBUG) debug("upgrade impp2: " + JSON.stringify(cursor.value));
             cursor.continue();
           }
         };
       }
     }
   },
 
   makeImport: function makeImport(aContact) {
@@ -223,17 +218,17 @@ ContactDB.prototype = {
                 // Store +1-234-567 as ["1234567", "234567"...]
                 let digits = number.match(/\d/g);
                 if (digits && number.length != digits.length) {
                   digits = digits.join('');
                   for(let i = 0; i < digits.length; i++) {
                     contact.search[field].push(digits.substring(i, digits.length));
                   }
                 }
-              debug("lookup: " + JSON.stringify(contact.search[field]));
+              if (DEBUG) debug("lookup: " + JSON.stringify(contact.search[field]));
               }
             } else if (field == "email") {
               let address = aContact.properties[field][i].value;
               if (address && typeof address == "string") {
                 contact.search[field].push(address.toLowerCase());
               }
             } else if (field == "impp") {
               let value = aContact.properties[field][i].value;
@@ -245,17 +240,17 @@ ContactDB.prototype = {
               if (typeof val == "string") {
                 contact.search[field].push(val.toLowerCase());
               }
             }
           }
         }
       }
     }
-    debug("contact:" + JSON.stringify(contact));
+    if (DEBUG) debug("contact:" + JSON.stringify(contact));
 
     contact.updated = aContact.updated;
     contact.published = aContact.published;
     contact.id = aContact.id;
 
     return contact;
   },
 
@@ -280,53 +275,53 @@ ContactDB.prototype = {
       record.published = new Date();
     }
     record.updated = new Date();
   },
 
   saveContact: function saveContact(aContact, successCb, errorCb) {
     let contact = this.makeImport(aContact);
     this.newTxn("readwrite", function (txn, store) {
-      debug("Going to update" + JSON.stringify(contact));
+      if (DEBUG) debug("Going to update" + JSON.stringify(contact));
 
       // Look up the existing record and compare the update timestamp.
       // If no record exists, just add the new entry.
       let newRequest = store.get(contact.id);
       newRequest.onsuccess = function (event) {
         if (!event.target.result) {
-          debug("new record!")
+          if (DEBUG) debug("new record!")
           this.updateRecordMetadata(contact);
           store.put(contact);
         } else {
-          debug("old record!")
+          if (DEBUG) debug("old record!")
           if (new Date(typeof contact.updated === "undefined" ? 0 : contact.updated) < new Date(event.target.result.updated)) {
-            debug("rev check fail!");
+            if (DEBUG) debug("rev check fail!");
             txn.abort();
             return;
           } else {
-            debug("rev check OK");
+            if (DEBUG) debug("rev check OK");
             contact.published = event.target.result.published;
             contact.updated = new Date();
             store.put(contact);
           }
         }
       }.bind(this);
     }.bind(this), successCb, errorCb);
   },
 
   removeContact: function removeContact(aId, aSuccessCb, aErrorCb) {
     this.newTxn("readwrite", function (txn, store) {
-      debug("Going to delete" + aId);
+      if (DEBUG) debug("Going to delete" + aId);
       store.delete(aId);
     }, aSuccessCb, aErrorCb);
   },
 
   clear: function clear(aSuccessCb, aErrorCb) {
     this.newTxn("readwrite", function (txn, store) {
-      debug("Going to clear all!");
+      if (DEBUG) debug("Going to clear all!");
       store.clear();
     }, aSuccessCb, aErrorCb);
   },
 
   /**
    * @param successCb
    *        Callback function to invoke with result array.
    * @param failureCb [optional]
@@ -334,42 +329,42 @@ ContactDB.prototype = {
    * @param options [optional]
    *        Object specifying search options. Possible attributes:
    *        - filterBy
    *        - filterOp
    *        - filterValue
    *        - count
    */
   find: function find(aSuccessCb, aFailureCb, aOptions) {
-    debug("ContactDB:find val:" + aOptions.filterValue + " by: " + aOptions.filterBy + " op: " + aOptions.filterOp + "\n");
+    if (DEBUG) debug("ContactDB:find val:" + aOptions.filterValue + " by: " + aOptions.filterBy + " op: " + aOptions.filterOp + "\n");
     let self = this;
     this.newTxn("readonly", function (txn, store) {
       if (aOptions && (aOptions.filterOp == "equals" || aOptions.filterOp == "contains")) {
         self._findWithIndex(txn, store, aOptions);
       } else {
         self._findAll(txn, store, aOptions);
       }
     }, aSuccessCb, aFailureCb);
   },
 
   _findWithIndex: function _findWithIndex(txn, store, options) {
-    debug("_findWithIndex: " + options.filterValue +" " + options.filterOp + " " + options.filterBy + " ");
+    if (DEBUG) debug("_findWithIndex: " + options.filterValue +" " + options.filterOp + " " + options.filterBy + " ");
     let fields = options.filterBy;
     for (let key in fields) {
-      debug("key: " + fields[key]);
+      if (DEBUG) debug("key: " + fields[key]);
       if (!store.indexNames.contains(fields[key]) && !fields[key] == "id") {
-        debug("Key not valid!" + fields[key] + ", " + store.indexNames);
+        if (DEBUG) debug("Key not valid!" + fields[key] + ", " + store.indexNames);
         txn.abort();
         return;
       }
     }
 
     // lookup for all keys
     if (options.filterBy.length == 0) {
-      debug("search in all fields!" + JSON.stringify(store.indexNames));
+      if (DEBUG) debug("search in all fields!" + JSON.stringify(store.indexNames));
       for(let myIndex = 0; myIndex < store.indexNames.length; myIndex++) {
         fields = Array.concat(fields, store.indexNames[myIndex])
       }
     }
 
     // Sorting functions takes care of limit if set.
     let limit = options.sortBy === 'undefined' ? options.filterLimit : null;
 
@@ -378,48 +373,48 @@ ContactDB.prototype = {
       let request;
       if (key == "id") {
         // store.get would return an object and not an array
         request = store.mozGetAll(options.filterValue);
       } else if (key == "category") {
         let index = store.index(key);
         request = index.mozGetAll(options.filterValue, limit);
       } else if (options.filterOp == "equals") {
-        debug("Getting index: " + key);
+        if (DEBUG) debug("Getting index: " + key);
         // case sensitive
         let index = store.index(key);
         request = index.mozGetAll(options.filterValue, limit);
       } else {
         // not case sensitive
         let tmp = typeof options.filterValue == "string"
                   ? options.filterValue.toLowerCase()
                   : options.filterValue.toString().toLowerCase();
         let range = this._global.IDBKeyRange.bound(tmp, tmp + "\uFFFF");
         let index = store.index(key + "LowerCase");
         request = index.mozGetAll(range, limit);
       }
       if (!txn.result)
         txn.result = {};
 
       request.onsuccess = function (event) {
-        debug("Request successful. Record count:" + event.target.result.length);
+        if (DEBUG) debug("Request successful. Record count:" + event.target.result.length);
         for (let i in event.target.result)
           txn.result[event.target.result[i].id] = this.makeExport(event.target.result[i]);
       }.bind(this);
     }
   },
 
   _findAll: function _findAll(txn, store, options) {
-    debug("ContactDB:_findAll:  " + JSON.stringify(options));
+    if (DEBUG) debug("ContactDB:_findAll:  " + JSON.stringify(options));
     if (!txn.result)
       txn.result = {};
     // Sorting functions takes care of limit if set.
     let limit = options.sortBy === 'undefined' ? options.filterLimit : null;
     store.mozGetAll(null, limit).onsuccess = function (event) {
-      debug("Request successful. Record count:", event.target.result.length);
+      if (DEBUG) debug("Request successful. Record count:", event.target.result.length);
       for (let i in event.target.result)
         txn.result[event.target.result[i].id] = this.makeExport(event.target.result[i]);
     }.bind(this);
   },
 
   init: function init(aGlobal) {
       this.initDBHelper(DB_NAME, DB_VERSION, STORE_NAME, aGlobal);
   }
--- a/dom/contacts/fallback/ContactService.jsm
+++ b/dom/contacts/fallback/ContactService.jsm
@@ -1,19 +1,16 @@
 /* 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";
 
-let DEBUG = 0;
-if (DEBUG)
-  debug = function (s) { dump("-*- Fallback ContactService component: " + s + "\n"); }
-else
-  debug = function (s) {}
+const DEBUG = false;
+function debug(s) { dump("-*- Fallback ContactService component: " + s + "\n"); }
 
 const Cu = Components.utils; 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 let EXPORTED_SYMBOLS = ["DOMContactManager"];
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
@@ -23,17 +20,17 @@ Cu.import("resource://gre/modules/Contac
 XPCOMUtils.defineLazyGetter(this, "ppmm", function() {
   return Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(Ci.nsIFrameMessageManager);
 });
 
 let myGlobal = this;
 
 let DOMContactManager = {
   init: function() {
-    debug("Init");
+    if (DEBUG) debug("Init");
     this._messages = ["Contacts:Find", "Contacts:Clear", "Contact:Save", "Contact:Remove"];
     this._messages.forEach((function(msgName) {
       ppmm.addMessageListener(msgName, this);
     }).bind(this));
 
     var idbManager = Components.classes["@mozilla.org/dom/indexeddb/manager;1"].getService(Ci.nsIIndexedDatabaseManager);
     idbManager.initWindowless(myGlobal);
     this._db = new ContactDB(myGlobal);
@@ -51,17 +48,17 @@ let DOMContactManager = {
     ppmm = null;
     this._messages = null;
     if (this._db)
       this._db.close();
     this._db = null;
   },
 
   receiveMessage: function(aMessage) {
-    debug("Fallback DOMContactManager::receiveMessage " + aMessage.name);
+    if (DEBUG) debug("Fallback DOMContactManager::receiveMessage " + aMessage.name);
     let mm = aMessage.target.QueryInterface(Ci.nsIFrameMessageManager);
     let msg = aMessage.data;
 
     /*
      * Sorting the contacts by sortBy field. sortBy can either be familyName or givenName.
      * If 2 entries have the same sortyBy field or no sortBy field is present, we continue 
      * sorting with the other sortyBy field.
      */
@@ -107,24 +104,24 @@ let DOMContactManager = {
         let result = new Array();
         this._db.find(
           function(contacts) {
             for (let i in contacts)
               result.push(contacts[i]);
             if (msg.options && msg.options.findOptions) {
               let findOptions = msg.options.findOptions;
               if (findOptions.sortOrder !== 'undefined' && findOptions.sortBy !== 'undefined') {
-                debug('sortBy: ' + findOptions.sortBy + ', sortOrder: ' + findOptions.sortOrder );
+                if (DEBUG) debug('sortBy: ' + findOptions.sortBy + ', sortOrder: ' + findOptions.sortOrder );
                 result.sort(sortfunction);
                 if (findOptions.filterLimit)
                   result = result.slice(0, findOptions.filterLimit);
               }
             }
 
-            debug("result:" + JSON.stringify(result));
+            if (DEBUG) debug("result:" + JSON.stringify(result));
             mm.sendAsyncMessage("Contacts:Find:Return:OK", {requestID: msg.requestID, contacts: result});
           }.bind(this),
           function(aErrorMsg) { mm.sendAsyncMessage("Contacts:Find:Return:KO", { requestID: msg.requestID, errorMsg: aErrorMsg }) }.bind(this),
           msg.options.findOptions);
         break;
       case "Contact:Save":
         this._db.saveContact(
           msg.options.contact,
@@ -140,14 +137,14 @@ let DOMContactManager = {
         );
         break;
       case "Contacts:Clear":
         this._db.clear(
           function() { mm.sendAsyncMessage("Contacts:Clear:Return:OK", { requestID: msg.requestID }); }.bind(this),
           function(aErrorMsg) { mm.sendAsyncMessage("Contacts:Clear:Return:KO", { requestID: msg.requestID, errorMsg: aErrorMsg }); }.bind(this)
         );
       default:
-        debug("WRONG MESSAGE NAME: " + aMessage.name);
+        if (DEBUG) debug("WRONG MESSAGE NAME: " + aMessage.name);
     }
   }
 }
 
 DOMContactManager.init();