From ef77922ac8b5501b4e0e7078719460429c7dede7 Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Wed, 30 Jul 2014 19:31:18 -0700 Subject: [PATCH] Bug 1046000: Shut down the wifi services. r=vchang --HG-- extra : rebase_source : 121fb986ff42e414713f4ff8bab151289e9746f4 --- dom/wifi/WifiCertService.cpp | 3 +++ dom/wifi/WifiProxyService.cpp | 5 +++++ dom/wifi/WifiWorker.js | 36 +++++++++++++++++++++-------------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/dom/wifi/WifiCertService.cpp b/dom/wifi/WifiCertService.cpp index 685f2d105d9..cfc0910dc2a 100644 --- a/dom/wifi/WifiCertService.cpp +++ b/dom/wifi/WifiCertService.cpp @@ -248,6 +248,9 @@ WifiCertService::Shutdown() mRequestThread->Shutdown(); mRequestThread = nullptr; } + + mListener = nullptr; + return NS_OK; } diff --git a/dom/wifi/WifiProxyService.cpp b/dom/wifi/WifiProxyService.cpp index bc5b97bc253..78bc7076a20 100644 --- a/dom/wifi/WifiProxyService.cpp +++ b/dom/wifi/WifiProxyService.cpp @@ -239,11 +239,16 @@ WifiProxyService::Shutdown() mEventThreadList[i].mThread = nullptr; } } + mEventThreadList.Clear(); + if (mControlThread) { mControlThread->Shutdown(); mControlThread = nullptr; } + + mListener = nullptr; + return NS_OK; } diff --git a/dom/wifi/WifiWorker.js b/dom/wifi/WifiWorker.js index 887eb519439..fa0b4328553 100644 --- a/dom/wifi/WifiWorker.js +++ b/dom/wifi/WifiWorker.js @@ -1780,6 +1780,7 @@ function WifiWorker() { }).bind(this)); Services.obs.addObserver(this, kMozSettingsChangedObserverTopic, false); + Services.obs.addObserver(this, "xpcom-shutdown", false); this.wantScanResults = []; @@ -2433,6 +2434,7 @@ WifiWorker.prototype = { QueryInterface: XPCOMUtils.generateQI([Ci.nsIWorkerHolder, Ci.nsIWifi, + Ci.nsIObserver, Ci.nsISettingsServiceCallback]), disconnectedByWifi: false, @@ -3504,22 +3506,28 @@ WifiWorker.prototype = { // nsIObserver implementation observe: function observe(subject, topic, data) { - // Note that this function gets called for any and all settings changes, - // so we need to carefully check if we have the one we're interested in. - // The string we're interested in will be a JSON string that looks like: - // {"key":"wifi.enabled","value":"true"}. - if (topic !== kMozSettingsChangedObserverTopic) { - return; - } + switch (topic) { + case kMozSettingsChangedObserverTopic: + // The string we're interested in will be a JSON string that looks like: + // {"key":"wifi.enabled","value":"true"}. - let setting = JSON.parse(data); - // To avoid WifiWorker setting the wifi again, don't need to deal with - // the "mozsettings-changed" event fired from internal setting. - if (setting.message && setting.message === "fromInternalSetting") { - return; - } + let setting = JSON.parse(data); + // To avoid WifiWorker setting the wifi again, don't need to deal with + // the "mozsettings-changed" event fired from internal setting. + if (setting.message && setting.message === "fromInternalSetting") { + return; + } - this.handle(setting.key, setting.value); + this.handle(setting.key, setting.value); + break; + + case "xpcom-shutdown": + let wifiService = Cc["@mozilla.org/wifi/service;1"].getService(Ci.nsIWifiProxyService); + wifiService.shutdown(); + let wifiCertService = Cc["@mozilla.org/wifi/certservice;1"].getService(Ci.nsIWifiCertService); + wifiCertService.shutdown(); + break; + } }, handle: function handle(aName, aResult) {