Bug 792819 - Final version: BluetoothService::Notify() won't be called after receiving agent events, r=qdot
authorGina Yeh <gyeh@mozilla.com>
Wed, 26 Sep 2012 14:29:19 +0800
changeset 108206 f85da9a728de373426c1ea5158974671f4e34ff9
parent 108205 6777e8ca792b3cf50c2bec85e463f22e7eddeddc
child 108207 295fcca29ff407a3b5acbbe436929db5a94c0049
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersqdot
bugs792819
milestone18.0a1
Bug 792819 - Final version: BluetoothService::Notify() won't be called after receiving agent events, r=qdot
dom/bluetooth/BluetoothService.cpp
--- a/dom/bluetooth/BluetoothService.cpp
+++ b/dom/bluetooth/BluetoothService.cpp
@@ -264,18 +264,16 @@ BluetoothService::Init()
 
   // Only the main process should observe bluetooth settings changes.
   if (IsMainProcess() &&
       NS_FAILED(obs->AddObserver(this, MOZSETTINGS_CHANGED_ID, false))) {
     NS_WARNING("Failed to add settings change observer!");
     return false;
   }
 
-  RegisterBluetoothSignalHandler(NS_LITERAL_STRING(LOCAL_AGENT_PATH), this);
-  RegisterBluetoothSignalHandler(NS_LITERAL_STRING(REMOTE_AGENT_PATH), this);
   mRegisteredForLocalAgent = true;
 
   return true;
 }
 
 void
 BluetoothService::Cleanup()
 {
@@ -379,16 +377,26 @@ BluetoothService::StartStopBluetooth(boo
   if (!mBluetoothCommandThread) {
     MOZ_ASSERT(!gInShutdown);
 
     rv = NS_NewNamedThread("BluetoothCmd",
                            getter_AddRefs(mBluetoothCommandThread));
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
+  if (aStart) {
+    RegisterBluetoothSignalHandler(NS_LITERAL_STRING(LOCAL_AGENT_PATH), this);
+    RegisterBluetoothSignalHandler(NS_LITERAL_STRING(REMOTE_AGENT_PATH), this);
+
+    BluetoothManagerList::ForwardIterator iter(mLiveManagers);
+    while (iter.HasMore()) {
+      RegisterBluetoothSignalHandler(NS_LITERAL_STRING("/"), (BluetoothSignalObserver*)iter.GetNext());
+    }
+  }
+
   nsCOMPtr<nsIRunnable> runnable = new ToggleBtTask(aStart);
   rv = mBluetoothCommandThread->Dispatch(runnable, NS_DISPATCH_NORMAL);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 void