Bug 979370: Split |BluetoothService::StartStopBluetooth|, r=echou

This patch splits |BluetoothService::StartStopBluetooth| into two
separate functions. Both have mostly different code paths.
This commit is contained in:
Thomas Zimmermann 2014-03-14 10:50:02 +01:00
parent d5c4098cf9
commit 37bbe5d22a
2 changed files with 69 additions and 42 deletions

View File

@ -447,61 +447,82 @@ BluetoothService::DistributeSignal(const BluetoothSignal& 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)
{
@ -714,7 +735,7 @@ BluetoothService::HandleShutdown()
}
}
if (IsEnabled() && NS_FAILED(StartStopBluetooth(false, false))) {
if (IsEnabled() && NS_FAILED(StopBluetooth(false))) {
MOZ_ASSERT(false, "Failed to deliver stop message!");
}

View File

@ -332,6 +332,12 @@ protected:
void
Cleanup();
nsresult
StartBluetooth(bool aIsStartup);
nsresult
StopBluetooth(bool aIsStartup);
nsresult
StartStopBluetooth(bool aStart, bool aIsStartup);