Bug 978809: Send ToggleBtAck after finishing BlueZ connection setup, r=echou
authorThomas Zimmermann <tdz@users.sourceforge.net>
Thu, 06 Mar 2014 12:45:16 +0100
changeset 172174 f7444f0ee3b95a408657afc074cb9421805f63fe
parent 172173 8eb485a8503e2b9a6bb7b3f66ce458a13353998f
child 172175 d8bfd66396468259db2ee5a3fe63b966f935fc3b
push id5262
push usertdz@users.sourceforge.net
push dateThu, 06 Mar 2014 11:46:14 +0000
treeherderb2g-inbound@f7444f0ee3b9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechou
bugs978809
milestone30.0a1
Bug 978809: Send ToggleBtAck after finishing BlueZ connection setup, r=echou With this patch, ToggleBtAck is sent by the BlueZ backend of Bluetooth after the connection has been set up completely.
dom/bluetooth/bluez/BluetoothDBusService.cpp
--- a/dom/bluetooth/bluez/BluetoothDBusService.cpp
+++ b/dom/bluetooth/bluez/BluetoothDBusService.cpp
@@ -1855,20 +1855,30 @@ public:
   : mConnection(aConnection)
   , mQueryDefaultAdapter(aQueryDefaultAdapter)
   {
     MOZ_ASSERT(mConnection);
   }
 
   void Run()
   {
+    MOZ_ASSERT(!sDBusConnection);
+
+    sDBusConnection = mConnection;
+
     mConnection->Watch();
 
-    /**
-     * Normally we'll receive the signal 'AdapterAdded' with the adapter object
+    nsRefPtr<nsRunnable> runnable =
+      new BluetoothService::ToggleBtAck(true);
+    if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
+      BT_WARNING("Failed to dispatch to main thread!");
+      return;
+    }
+
+    /* Normally we'll receive the signal 'AdapterAdded' with the adapter object
      * path from the DBus daemon during start up. So, there's no need to query
      * the object path of default adapter here. However, if we restart from a
      * crash, the default adapter might already be available, so we ask the daemon
      * explicitly here.
      */
     if (mQueryDefaultAdapter) {
       bool success = mConnection->SendWithReply(OnDefaultAdapterReply, nullptr,
                                                 1000, "/",
@@ -1887,26 +1897,16 @@ private:
 };
 
 nsresult
 BluetoothDBusService::StartInternal()
 {
   // This could block. It should never be run on the main thread.
   MOZ_ASSERT(!NS_IsMainThread()); // BT thread
 
-  if (sDBusConnection) {
-    // This should actually not happen.
-    BT_WARNING("Bluetooth is already running");
-    nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(true);
-    if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
-      BT_WARNING("Failed to dispatch to main thread!");
-    }
-    return NS_OK;
-  }
-
 #ifdef MOZ_WIDGET_GONK
   if (!sBluedroid.Enable()) {
     BT_WARNING("Bluetooth not available.");
     nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(false);
     if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
       BT_WARNING("Failed to dispatch to main thread!");
     }
     return NS_ERROR_FAILURE;
@@ -1950,26 +1950,19 @@ BluetoothDBusService::StartInternal()
     }
     return NS_ERROR_FAILURE;
   }
 
   if (!sPairingReqTable) {
     sPairingReqTable = new nsDataHashtable<nsStringHashKey, DBusMessage* >;
   }
 
-  sDBusConnection = connection;
-
   Task* task = new StartDBusConnectionTask(connection, sAdapterPath.IsEmpty());
   DispatchToDBusThread(task);
 
-  nsCOMPtr<nsIRunnable> ackTask = new BluetoothService::ToggleBtAck(true);
-  if (NS_FAILED(NS_DispatchToMainThread(ackTask))) {
-    BT_WARNING("Failed to dispatch to main thread!");
-  }
-
   return NS_OK;
 }
 
 PLDHashOperator
 UnrefDBusMessages(const nsAString& key, DBusMessage* value, void* arg)
 {
   dbus_message_unref(value);