Bug 979370: Split |BluetoothService::StartStopBluetooth|, r=echou
authorThomas Zimmermann <tdz@users.sourceforge.net>
Fri, 14 Mar 2014 10:50:02 +0100
changeset 191820 55032b8c9281d08245d5ca6e1d851aaa776dfdf0
parent 191819 a77f6548e510e46c6b2c9e6d23c9d2714aa7cc6d
child 191821 30f9202e4f92bb85fa24b720af6ae9d3dad43ca7
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechou
bugs979370
milestone30.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 979370: Split |BluetoothService::StartStopBluetooth|, r=echou This patch splits |BluetoothService::StartStopBluetooth| into two separate functions. Both have mostly different code paths.
dom/bluetooth/BluetoothService.cpp
dom/bluetooth/BluetoothService.h
--- a/dom/bluetooth/BluetoothService.cpp
+++ b/dom/bluetooth/BluetoothService.cpp
@@ -442,71 +442,92 @@ BluetoothService::DistributeSignal(const
 #endif
     return;
   }
   MOZ_ASSERT(ol->Length());
   ol->Broadcast(aSignal);
 }
 
 nsresult
-BluetoothService::StartStopBluetooth(bool aStart, bool aIsStartup)
+BluetoothService::StartBluetooth(bool aIsStartup)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (sInShutdown) {
-    if (aStart) {
-      // Don't try to start if we're already shutting down.
-      MOZ_ASSERT(false, "Start called while in shutdown!");
-      return NS_ERROR_FAILURE;
-    }
-  }
-
-  if (!aStart) {
-    BluetoothProfileManagerBase* profile;
-    profile = BluetoothHfpManager::Get();
-    NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE);
-    if (profile->IsConnected()) {
-      profile->Disconnect(nullptr);
-    } else {
-      profile->Reset();
-    }
-
-    profile = BluetoothOppManager::Get();
-    NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE);
-    if (profile->IsConnected()) {
-      profile->Disconnect(nullptr);
-    }
-
-    profile = BluetoothA2dpManager::Get();
-    NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE);
-    if (profile->IsConnected()) {
-      profile->Disconnect(nullptr);
-    } else {
-      profile->Reset();
-    }
-
-    profile = BluetoothHidManager::Get();
-    NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE);
-    if (profile->IsConnected()) {
-      profile->Disconnect(nullptr);
-    } else {
-      profile->Reset();
-    }
-
+    // Don't try to start if we're already shutting down.
+    MOZ_ASSERT(false, "Start called while in shutdown!");
+    return NS_ERROR_FAILURE;
   }
 
   mAdapterAddedReceived = false;
 
-  nsCOMPtr<nsIRunnable> runnable = new ToggleBtTask(aStart, aIsStartup);
+  nsCOMPtr<nsIRunnable> runnable = new ToggleBtTask(true, aIsStartup);
   nsresult rv = NS_DispatchToMainThread(runnable);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
+nsresult
+BluetoothService::StopBluetooth(bool aIsStartup)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  BluetoothProfileManagerBase* profile;
+  profile = BluetoothHfpManager::Get();
+  NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE);
+  if (profile->IsConnected()) {
+    profile->Disconnect(nullptr);
+  } else {
+    profile->Reset();
+  }
+
+  profile = BluetoothOppManager::Get();
+  NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE);
+  if (profile->IsConnected()) {
+    profile->Disconnect(nullptr);
+  }
+
+  profile = BluetoothA2dpManager::Get();
+  NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE);
+  if (profile->IsConnected()) {
+    profile->Disconnect(nullptr);
+  } else {
+    profile->Reset();
+  }
+
+  profile = BluetoothHidManager::Get();
+  NS_ENSURE_TRUE(profile, NS_ERROR_FAILURE);
+  if (profile->IsConnected()) {
+    profile->Disconnect(nullptr);
+  } else {
+    profile->Reset();
+  }
+
+  mAdapterAddedReceived = false;
+
+  nsCOMPtr<nsIRunnable> runnable = new ToggleBtTask(false, aIsStartup);
+  nsresult rv = NS_DispatchToMainThread(runnable);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  return NS_OK;
+}
+
+nsresult
+BluetoothService::StartStopBluetooth(bool aStart, bool aIsStartup)
+{
+  nsresult rv;
+  if (aStart) {
+    rv = StartBluetooth(aIsStartup);
+  } else {
+    rv = StopBluetooth(aIsStartup);
+  }
+  return rv;
+}
+
 void
 BluetoothService::SetEnabled(bool aEnabled)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   AutoInfallibleTArray<BluetoothParent*, 10> childActors;
   GetAllBluetoothActors(childActors);
 
@@ -709,17 +730,17 @@ BluetoothService::HandleShutdown()
         }
       }
       else {
         MOZ_ASSERT(false, "Failed to initialize shutdown timer!");
       }
     }
   }
 
-  if (IsEnabled() && NS_FAILED(StartStopBluetooth(false, false))) {
+  if (IsEnabled() && NS_FAILED(StopBluetooth(false))) {
     MOZ_ASSERT(false, "Failed to deliver stop message!");
   }
 
   return NS_OK;
 }
 
 // static
 BluetoothService*
--- a/dom/bluetooth/BluetoothService.h
+++ b/dom/bluetooth/BluetoothService.h
@@ -328,16 +328,22 @@ protected:
 
   bool
   Init();
 
   void
   Cleanup();
 
   nsresult
+  StartBluetooth(bool aIsStartup);
+
+  nsresult
+  StopBluetooth(bool aIsStartup);
+
+  nsresult
   StartStopBluetooth(bool aStart, bool aIsStartup);
 
   /**
    * Platform specific startup functions go here. Usually deals with member
    * variables, so not static. Guaranteed to be called outside of main thread.
    *
    * @return NS_OK on correct startup, NS_ERROR_FAILURE otherwise
    */