Bug 826977 - Part 2/4: SystemWorkerManager & RadionInterfaceLayer changes. r=qDot
authorVicamo Yang <vyang@mozilla.com>
Thu, 24 Jan 2013 14:42:07 +0800
changeset 119722 8c0b0e94b597f56cd3892b18d73b79df61157e61
parent 119721 ef7b5b52ce92476ac5af1d5b789efe2ebab122e1
child 119723 82219f1a9fe647eb5a7ac1790e38f10c94213070
push id24219
push userryanvm@gmail.com
push dateThu, 24 Jan 2013 17:36:06 +0000
treeherdermozilla-central@fa969919b1bb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqDot
bugs826977
milestone21.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 826977 - Part 2/4: SystemWorkerManager & RadionInterfaceLayer changes. r=qDot
dom/system/gonk/Makefile.in
dom/system/gonk/RadioInterfaceLayer.js
dom/system/gonk/RadioInterfaceLayer.manifest
dom/system/gonk/SystemWorkerManager.cpp
dom/system/gonk/SystemWorkerManager.h
--- a/dom/system/gonk/Makefile.in
+++ b/dom/system/gonk/Makefile.in
@@ -40,16 +40,17 @@ XPIDLSRCS = \
   nsIRadioInterfaceLayer.idl \
   nsIVolume.idl \
   nsIVolumeMountLock.idl \
   nsIVolumeService.idl \
   nsIVolumeStat.idl \
   nsIWorkerHolder.idl \
   nsIAudioChannelManager.idl \
   nsINavigatorAudioChannelManager.idl \
+  nsISystemWorkerManager.idl \
   $(NULL)
 
 LOCAL_INCLUDES = \
   -I$(topsrcdir)/dom/base \
   -I$(topsrcdir)/dom/src/geolocation \
   -I$(topsrcdir)/dom/telephony \
   -I$(topsrcdir)/dom/wifi \
   -I$(topsrcdir)/dom/bluetooth \
--- a/dom/system/gonk/RadioInterfaceLayer.js
+++ b/dom/system/gonk/RadioInterfaceLayer.js
@@ -130,16 +130,20 @@ XPCOMUtils.defineLazyServiceGetter(this,
 XPCOMUtils.defineLazyServiceGetter(this, "gNetworkManager",
                                    "@mozilla.org/network/manager;1",
                                    "nsINetworkManager");
 
 XPCOMUtils.defineLazyServiceGetter(this, "gTimeService",
                                    "@mozilla.org/time/timeservice;1",
                                    "nsITimeService");
 
+XPCOMUtils.defineLazyServiceGetter(this, "gSystemWorkerManager",
+                                   "@mozilla.org/telephony/system-worker-manager;1",
+                                   "nsISystemWorkerManager");
+
 XPCOMUtils.defineLazyGetter(this, "WAP", function () {
   let WAP = {};
   Cu.import("resource://gre/modules/WapPushManager.js", WAP);
   return WAP;
 });
 
 function convertRILCallState(state) {
   switch (state) {
@@ -311,27 +315,27 @@ function RadioInterfaceLayer() {
   this.portAddressedSmsApps = {};
   this.portAddressedSmsApps[WAP.WDP_PORT_PUSH] = this.handleSmsWdpPortPush.bind(this);
 
   this._targetMessageQueue = [];
 
   // pass debug pref to ril_worker
   this.worker.postMessage({rilMessageType: "setDebugEnabled",
                            enabled: debugPref});
+
+  gSystemWorkerManager.registerRilWorker(this.worker);
 }
 RadioInterfaceLayer.prototype = {
 
   classID:   RADIOINTERFACELAYER_CID,
   classInfo: XPCOMUtils.generateCI({classID: RADIOINTERFACELAYER_CID,
                                     classDescription: "RadioInterfaceLayer",
-                                    interfaces: [Ci.nsIWorkerHolder,
-                                                 Ci.nsIRadioInterfaceLayer]}),
-
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIWorkerHolder,
-                                         Ci.nsIRadioInterfaceLayer,
+                                    interfaces: [Ci.nsIRadioInterfaceLayer]}),
+
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIRadioInterfaceLayer,
                                          Ci.nsIObserver,
                                          Ci.nsISettingsServiceCallback]),
 
   /**
    * Process a message from the content process.
    */
   receiveMessage: function receiveMessage(msg) {
     debug("Received '" + msg.name + "' message from content process");
--- a/dom/system/gonk/RadioInterfaceLayer.manifest
+++ b/dom/system/gonk/RadioInterfaceLayer.manifest
@@ -8,25 +8,16 @@
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
 # RadioInterfaceLayer.js
-#
-# IMPORTANT:
-# Users of nsIRadioInterfaceLayer should invoke
-# nsIInterfaceRequestor::GetInterface() as implemented by
-# "@mozilla.org/telephony/system-worker-manager;1" to
-# obtain the instance.
-#
-# DO NOT use do_CreateInstance()/do_GetService() to directly
-# instantiate "@mozilla.org/ril;1".
-#
 component {2d831c8d-6017-435b-a80c-e5d422810cea} RadioInterfaceLayer.js
 contract @mozilla.org/ril;1 {2d831c8d-6017-435b-a80c-e5d422810cea}
+category profile-after-change RadioInterfaceLayer @mozilla.org/ril;1
 
 # RILContentHelper.js
 component {472816e1-1fd6-4405-996c-806f9ea68174} RILContentHelper.js
 contract @mozilla.org/ril/content-helper;1 {472816e1-1fd6-4405-996c-806f9ea68174}
 category profile-after-change RILContentHelper @mozilla.org/ril/content-helper;1
--- a/dom/system/gonk/SystemWorkerManager.cpp
+++ b/dom/system/gonk/SystemWorkerManager.cpp
@@ -361,23 +361,17 @@ SystemWorkerManager::Init()
   JSContext* cx = nsContentUtils::ThreadJSContextStack()->GetSafeJSContext();
   NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
 
   nsCxPusher pusher;
   if (!pusher.Push(cx, false)) {
     return NS_ERROR_FAILURE;
   }
 
-  nsresult rv = InitRIL(cx);
-  if (NS_FAILED(rv)) {
-    NS_WARNING("Failed to initialize RIL/Telephony!");
-    return rv;
-  }
-
-  rv = InitWifi(cx);
+  nsresult rv = InitWifi(cx);
   if (NS_FAILED(rv)) {
     NS_WARNING("Failed to initialize WiFi Networking!");
     return rv;
   }
 
 #ifdef MOZ_WIDGET_GONK
   InitAutoMounter();
   InitializeTimeZoneSettingObserver();
@@ -409,18 +403,16 @@ SystemWorkerManager::Shutdown()
   mShutdown = true;
 
 #ifdef MOZ_WIDGET_GONK
   ShutdownAutoMounter();
 #endif
 
   StopRil();
 
-  mRIL = nullptr;
-
 #ifdef MOZ_WIDGET_GONK
   StopNetd();
   mNetdWorker = nullptr;
 #endif
 
   nsCOMPtr<nsIWifi> wifi(do_QueryInterface(mWifiWorker));
   if (wifi) {
     wifi->Shutdown();
@@ -463,21 +455,16 @@ SystemWorkerManager::GetInterfaceRequest
   return gInstance;
 }
 
 NS_IMETHODIMP
 SystemWorkerManager::GetInterface(const nsIID &aIID, void **aResult)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
-  if (aIID.Equals(NS_GET_IID(nsIRadioInterfaceLayer))) {
-    NS_IF_ADDREF(*reinterpret_cast<nsIRadioInterfaceLayer**>(aResult) = mRIL);
-    return NS_OK;
-  }
-
   if (aIID.Equals(NS_GET_IID(nsIWifi))) {
     return CallQueryInterface(mWifiWorker,
                               reinterpret_cast<nsIWifi**>(aResult));
   }
 
 #ifdef MOZ_WIDGET_GONK
   if (aIID.Equals(NS_GET_IID(nsINetworkManager))) {
     return CallQueryInterface(mNetdWorker,
@@ -485,52 +472,38 @@ SystemWorkerManager::GetInterface(const 
   }
 #endif
 
   NS_WARNING("Got nothing for the requested IID!");
   return NS_ERROR_NO_INTERFACE;
 }
 
 nsresult
-SystemWorkerManager::InitRIL(JSContext *cx)
+SystemWorkerManager::RegisterRilWorker(const JS::Value& aWorker,
+                                       JSContext *aCx)
 {
-  // We're keeping as much of this implementation as possible in JS, so the real
-  // worker lives in RadioInterfaceLayer.js. All we do here is hold it alive and
-  // hook it up to the RIL thread.
-  nsCOMPtr<nsIRadioInterfaceLayer> ril = do_CreateInstance("@mozilla.org/ril;1");
-  NS_ENSURE_TRUE(ril, NS_ERROR_FAILURE);
-
-  nsCOMPtr<nsIWorkerHolder> worker = do_QueryInterface(ril);
-  if (worker) {
-    jsval workerval;
-    nsresult rv = worker->GetWorker(&workerval);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    NS_ENSURE_TRUE(!JSVAL_IS_PRIMITIVE(workerval), NS_ERROR_UNEXPECTED);
+  NS_ENSURE_TRUE(!JSVAL_IS_PRIMITIVE(aWorker), NS_ERROR_UNEXPECTED);
 
-    JSAutoRequest ar(cx);
-    JSAutoCompartment ac(cx, JSVAL_TO_OBJECT(workerval));
-
-    WorkerCrossThreadDispatcher *wctd =
-      GetWorkerCrossThreadDispatcher(cx, workerval);
-    if (!wctd) {
-      return NS_ERROR_FAILURE;
-    }
+  JSAutoRequest ar(aCx);
+  JSAutoCompartment ac(aCx, JSVAL_TO_OBJECT(aWorker));
 
-    nsRefPtr<ConnectWorkerToRIL> connection = new ConnectWorkerToRIL();
-    if (!wctd->PostTask(connection)) {
-      return NS_ERROR_UNEXPECTED;
-    }
-
-    // Now that we're set up, connect ourselves to the RIL thread.
-    mozilla::RefPtr<RILReceiver> receiver = new RILReceiver(wctd);
-    StartRil(receiver);
+  WorkerCrossThreadDispatcher *wctd =
+    GetWorkerCrossThreadDispatcher(aCx, aWorker);
+  if (!wctd) {
+    return NS_ERROR_FAILURE;
   }
 
-  mRIL = ril;
+  nsRefPtr<ConnectWorkerToRIL> connection = new ConnectWorkerToRIL();
+  if (!wctd->PostTask(connection)) {
+    return NS_ERROR_UNEXPECTED;
+  }
+
+  // Now that we're set up, connect ourselves to the RIL thread.
+  mozilla::RefPtr<RILReceiver> receiver = new RILReceiver(wctd);
+  StartRil(receiver);
   return NS_OK;
 }
 
 #ifdef MOZ_WIDGET_GONK
 nsresult
 SystemWorkerManager::InitNetd(JSContext *cx)
 {
   nsCOMPtr<nsIWorkerHolder> worker = do_GetService(kNetworkManagerCID);
@@ -570,17 +543,20 @@ SystemWorkerManager::InitWifi(JSContext 
 {
   nsCOMPtr<nsIWorkerHolder> worker = do_CreateInstance(kWifiWorkerCID);
   NS_ENSURE_TRUE(worker, NS_ERROR_FAILURE);
 
   mWifiWorker = worker;
   return NS_OK;
 }
 
-NS_IMPL_ISUPPORTS2(SystemWorkerManager, nsIObserver, nsIInterfaceRequestor)
+NS_IMPL_ISUPPORTS3(SystemWorkerManager,
+                   nsIObserver,
+                   nsIInterfaceRequestor,
+                   nsISystemWorkerManager)
 
 NS_IMETHODIMP
 SystemWorkerManager::Observe(nsISupports *aSubject, const char *aTopic,
                              const PRUnichar *aData)
 {
   if (!strcmp(aTopic, WORKERS_SHUTDOWN_TOPIC)) {
     Shutdown();
   }
--- a/dom/system/gonk/SystemWorkerManager.h
+++ b/dom/system/gonk/SystemWorkerManager.h
@@ -14,59 +14,59 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 #ifndef mozilla_dom_system_b2g_systemworkermanager_h__
 #define mozilla_dom_system_b2g_systemworkermanager_h__
 
 #include "nsIInterfaceRequestor.h"
-#include "nsIRadioInterfaceLayer.h"
+#include "nsISystemWorkerManager.h"
 #include "nsIObserver.h"
 #include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsDebug.h"
 #include "nsDOMEventTargetHelper.h"
 #include "nsStringGlue.h"
 #include "nsTArray.h"
 
 class nsIWorkerHolder;
 
 namespace mozilla {
 namespace dom {
 namespace gonk {
 
 class SystemWorkerManager : public nsIObserver,
-                            public nsIInterfaceRequestor
+                            public nsIInterfaceRequestor,
+                            public nsISystemWorkerManager
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
   NS_DECL_NSIINTERFACEREQUESTOR
+  NS_DECL_NSISYSTEMWORKERMANAGER
 
   nsresult Init();
   void Shutdown();
 
   static already_AddRefed<SystemWorkerManager>
   FactoryCreate();
 
   static nsIInterfaceRequestor*
   GetInterfaceRequestor();
 
 private:
   SystemWorkerManager();
   ~SystemWorkerManager();
 
-  nsresult InitRIL(JSContext *cx);
 #ifdef MOZ_WIDGET_GONK
   nsresult InitNetd(JSContext *cx);
 #endif
   nsresult InitWifi(JSContext *cx);
 
-  nsCOMPtr<nsIRadioInterfaceLayer> mRIL;
 #ifdef MOZ_WIDGET_GONK
   nsCOMPtr<nsIWorkerHolder> mNetdWorker;
 #endif
   nsCOMPtr<nsIWorkerHolder> mWifiWorker;
 
   bool mShutdown;
 };