From 25ad9ae82e028a6c07534e45f4c346c28f9c3ac3 Mon Sep 17 00:00:00 2001 From: Blake Kaplan Date: Mon, 29 Oct 2012 12:26:55 -0700 Subject: [PATCH] Bug 806611 - Control wifi debug output based on a setting. r=vchang --HG-- extra : rebase_source : 972a0956b02c7e6312ba0325d8fde1a4ee9a971d --- dom/wifi/WifiWorker.js | 45 +++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/dom/wifi/WifiWorker.js b/dom/wifi/WifiWorker.js index 79390ce84ace..5cda67c34f0e 100644 --- a/dom/wifi/WifiWorker.js +++ b/dom/wifi/WifiWorker.js @@ -11,7 +11,7 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); -const DEBUG = false; // set to true to show debug messages +var DEBUG = false; // set to true to show debug messages const WIFIWORKER_CONTRACTID = "@mozilla.org/wifi/worker;1"; const WIFIWORKER_CID = Components.ID("{a14e8977-d259-433a-a88d-58dd44657e5b}"); @@ -1835,9 +1835,28 @@ function WifiWorker() { handleError: function handleError(aErrorMessage) { debug("Error reading the 'wifi.enabled' setting. Default to wifi on."); self.setWifiEnabled({enabled: true}); - }, + } }; - gSettingsService.createLock().get("wifi.enabled", initWifiEnabledCb); + + var initWifiDebuggingEnabledCb = { + handle: function handle(aName, aResult) { + if (aName !== "wifi.debugging.enabled") + return; + if (aResult === null) + aResult = false; + DEBUG = aResult; + updateDebug(); + }, + handleError: function handleError(aErrorMessage) { + debug("Error reading the 'wifi.debugging.enabled' setting. Default to debugging off."); + DEBUG = false; + updateDebug(); + } + }; + + let lock = gSettingsService.createLock(); + lock.get("wifi.enabled", initWifiEnabledCb); + lock.get("wifi.debugging.enabled", initWifiDebuggingEnabledCb); } function translateState(state) { @@ -2572,6 +2591,11 @@ WifiWorker.prototype = { } let setting = JSON.parse(data); + if (setting.key === "wifi.debugging.enabled") { + DEBUG = setting.value; + updateDebug(); + return; + } if (setting.key !== "wifi.enabled" && setting.key !== "tethering.wifi.enabled") { return; @@ -2596,10 +2620,13 @@ WifiWorker.prototype = { this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WifiWorker]); let debug; -if (DEBUG) { - debug = function (s) { - dump("-*- WifiWorker component: " + s + "\n"); - }; -} else { - debug = function (s) {}; +function updateDebug() { + if (DEBUG) { + debug = function (s) { + dump("-*- WifiWorker component: " + s + "\n"); + }; + } else { + debug = function (s) {}; + } } +updateDebug();