mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 976943 - Replace OnConnect/OnDisconnect with one function, f=btian, r=gyeh
In BluetoothProfileController, it's meaningless to separate OnConnect and OnDisconnect since the following steps would be the same for both cases. Therefore I introduced a function called NotifyCompletion() for each profile manager to report the completion of connecting/disconnecting operations.
This commit is contained in:
parent
54e43ece14
commit
73b0511a00
@ -119,12 +119,12 @@ BluetoothHidManager::Connect(const nsAString& aDeviceAddress,
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs || sInShutdown) {
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
|
||||
if (mConnected) {
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ BluetoothHidManager::Connect(const nsAString& aDeviceAddress,
|
||||
|
||||
if (NS_FAILED(bs->SendInputMessage(aDeviceAddress,
|
||||
NS_LITERAL_STRING("Connect")))) {
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -146,14 +146,14 @@ BluetoothHidManager::Disconnect(BluetoothProfileController* aController)
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
if (aController) {
|
||||
aController->OnDisconnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mConnected) {
|
||||
if (aController) {
|
||||
aController->OnDisconnect(NS_LITERAL_STRING(ERR_ALREADY_DISCONNECTED));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_DISCONNECTED));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -165,7 +165,7 @@ BluetoothHidManager::Disconnect(BluetoothProfileController* aController)
|
||||
|
||||
if (NS_FAILED(bs->SendInputMessage(mDeviceAddress,
|
||||
NS_LITERAL_STRING("Disconnect")))) {
|
||||
aController->OnDisconnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -182,7 +182,7 @@ BluetoothHidManager::OnConnect(const nsAString& aErrorStr)
|
||||
NS_ENSURE_TRUE_VOID(mController);
|
||||
|
||||
nsRefPtr<BluetoothProfileController> controller = mController.forget();
|
||||
controller->OnConnect(aErrorStr);
|
||||
controller->NotifyCompletion(aErrorStr);
|
||||
}
|
||||
|
||||
void
|
||||
@ -197,7 +197,7 @@ BluetoothHidManager::OnDisconnect(const nsAString& aErrorStr)
|
||||
NS_ENSURE_TRUE_VOID(mController);
|
||||
|
||||
nsRefPtr<BluetoothProfileController> controller = mController.forget();
|
||||
controller->OnDisconnect(aErrorStr);
|
||||
controller->NotifyCompletion(aErrorStr);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -281,27 +281,7 @@ BluetoothProfileController::Next()
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothProfileController::OnConnect(const nsAString& aErrorStr)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mTimer);
|
||||
|
||||
BT_LOGR_PROFILE(mProfiles[mProfilesIndex], "<%s>",
|
||||
NS_ConvertUTF16toUTF8(aErrorStr).get());
|
||||
|
||||
mCurrentProfileFinished = true;
|
||||
|
||||
if (mTimer) {
|
||||
mTimer->Cancel();
|
||||
}
|
||||
|
||||
mSuccess |= aErrorStr.IsEmpty();
|
||||
|
||||
Next();
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothProfileController::OnDisconnect(const nsAString& aErrorStr)
|
||||
BluetoothProfileController::NotifyCompletion(const nsAString& aErrorStr)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mTimer);
|
||||
|
@ -97,16 +97,10 @@ public:
|
||||
void EndSession();
|
||||
|
||||
/**
|
||||
* It is invoked after a profile has tried to establish the connection.
|
||||
* An error string is returned when it fails.
|
||||
* It would be invoked after connect/disconnect operation is completed.
|
||||
* An error string would be returned when it fails.
|
||||
*/
|
||||
void OnConnect(const nsAString& aErrorStr);
|
||||
|
||||
/**
|
||||
* It is invoked after a profile has tried to drop the connection.
|
||||
* An error string is returned when it fails.
|
||||
*/
|
||||
void OnDisconnect(const nsAString& aErrorStr);
|
||||
void NotifyCompletion(const nsAString& aErrorStr);
|
||||
|
||||
/**
|
||||
* It is invoked after a profile has reached timeout, reset mProfiles.
|
||||
|
@ -576,12 +576,12 @@ BluetoothA2dpManager::Connect(const nsAString& aDeviceAddress,
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs || sInShutdown) {
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
|
||||
if (mA2dpConnected) {
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -590,7 +590,7 @@ BluetoothA2dpManager::Connect(const nsAString& aDeviceAddress,
|
||||
|
||||
if (!sBtA2dpInterface) {
|
||||
BT_LOGR("sBluetoothA2dpInterface is null");
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -600,7 +600,7 @@ BluetoothA2dpManager::Connect(const nsAString& aDeviceAddress,
|
||||
bt_status_t result = sBtA2dpInterface->connect(&remoteAddress);
|
||||
if (BT_STATUS_SUCCESS != result) {
|
||||
BT_LOGR("Failed to connect: %x", result);
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -614,14 +614,14 @@ BluetoothA2dpManager::Disconnect(BluetoothProfileController* aController)
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
if (aController) {
|
||||
aController->OnDisconnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mA2dpConnected) {
|
||||
if (aController) {
|
||||
aController->OnDisconnect(NS_LITERAL_STRING(ERR_ALREADY_DISCONNECTED));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_DISCONNECTED));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -632,7 +632,7 @@ BluetoothA2dpManager::Disconnect(BluetoothProfileController* aController)
|
||||
|
||||
if (!sBtA2dpInterface) {
|
||||
BT_LOGR("sBluetoothA2dpInterface is null");
|
||||
aController->OnDisconnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -642,7 +642,7 @@ BluetoothA2dpManager::Disconnect(BluetoothProfileController* aController)
|
||||
bt_status_t result = sBtA2dpInterface->disconnect(&remoteAddress);
|
||||
if (BT_STATUS_SUCCESS != result) {
|
||||
BT_LOGR("Failed to disconnect: %x", result);
|
||||
aController->OnDisconnect(NS_LITERAL_STRING(ERR_DISCONNECTION_FAILED));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_DISCONNECTION_FAILED));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -659,7 +659,7 @@ BluetoothA2dpManager::OnConnect(const nsAString& aErrorStr)
|
||||
NS_ENSURE_TRUE_VOID(mController);
|
||||
|
||||
nsRefPtr<BluetoothProfileController> controller = mController.forget();
|
||||
controller->OnConnect(aErrorStr);
|
||||
controller->NotifyCompletion(aErrorStr);
|
||||
}
|
||||
|
||||
void
|
||||
@ -674,7 +674,8 @@ BluetoothA2dpManager::OnDisconnect(const nsAString& aErrorStr)
|
||||
NS_ENSURE_TRUE_VOID(mController);
|
||||
|
||||
nsRefPtr<BluetoothProfileController> controller = mController.forget();
|
||||
controller->OnDisconnect(aErrorStr);
|
||||
controller->NotifyCompletion(aErrorStr);
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ BluetoothHfpManager::Connect(const nsAString& aDeviceAddress,
|
||||
{
|
||||
MOZ_ASSERT(aController);
|
||||
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
}
|
||||
|
||||
void
|
||||
@ -55,7 +55,7 @@ BluetoothHfpManager::Disconnect(BluetoothProfileController* aController)
|
||||
{
|
||||
MOZ_ASSERT(aController);
|
||||
|
||||
aController->OnDisconnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -1227,13 +1227,13 @@ BluetoothHfpManager::Connect(const nsAString& aDeviceAddress,
|
||||
MOZ_ASSERT(aController && !mController);
|
||||
|
||||
if (sInShutdown) {
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sBluetoothHfpInterface) {
|
||||
BT_LOGR("sBluetoothHfpInterface is null");
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1243,7 +1243,7 @@ BluetoothHfpManager::Connect(const nsAString& aDeviceAddress,
|
||||
bt_status_t result = sBluetoothHfpInterface->connect(&deviceBdAddress);
|
||||
if (BT_STATUS_SUCCESS != result) {
|
||||
BT_LOGR("Failed to connect: %x", result);
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_CONNECTION_FAILED));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1259,7 +1259,7 @@ BluetoothHfpManager::Disconnect(BluetoothProfileController* aController)
|
||||
|
||||
if (!sBluetoothHfpInterface) {
|
||||
BT_LOGR("sBluetoothHfpInterface is null");
|
||||
aController->OnDisconnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1269,7 +1269,7 @@ BluetoothHfpManager::Disconnect(BluetoothProfileController* aController)
|
||||
bt_status_t result = sBluetoothHfpInterface->disconnect(&deviceBdAddress);
|
||||
if (BT_STATUS_SUCCESS != result) {
|
||||
BT_LOGR("Failed to disconnect: %x", result);
|
||||
aController->OnDisconnect(NS_LITERAL_STRING(ERR_DISCONNECTION_FAILED));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_DISCONNECTION_FAILED));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1287,7 +1287,7 @@ BluetoothHfpManager::OnConnect(const nsAString& aErrorStr)
|
||||
*/
|
||||
NS_ENSURE_TRUE_VOID(mController);
|
||||
|
||||
mController->OnConnect(aErrorStr);
|
||||
mController->NotifyCompletion(aErrorStr);
|
||||
mController = nullptr;
|
||||
}
|
||||
|
||||
@ -1302,7 +1302,7 @@ BluetoothHfpManager::OnDisconnect(const nsAString& aErrorStr)
|
||||
*/
|
||||
NS_ENSURE_TRUE_VOID(mController);
|
||||
|
||||
mController->OnDisconnect(aErrorStr);
|
||||
mController->NotifyCompletion(aErrorStr);
|
||||
mController = nullptr;
|
||||
}
|
||||
|
||||
|
@ -159,12 +159,12 @@ BluetoothA2dpManager::Connect(const nsAString& aDeviceAddress,
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs || sInShutdown) {
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
|
||||
if (mA2dpConnected) {
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ BluetoothA2dpManager::Connect(const nsAString& aDeviceAddress,
|
||||
|
||||
if (NS_FAILED(bs->SendSinkMessage(aDeviceAddress,
|
||||
NS_LITERAL_STRING("Connect")))) {
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -184,14 +184,14 @@ BluetoothA2dpManager::Disconnect(BluetoothProfileController* aController)
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs) {
|
||||
if (aController) {
|
||||
aController->OnDisconnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mA2dpConnected) {
|
||||
if (aController) {
|
||||
aController->OnDisconnect(NS_LITERAL_STRING(ERR_ALREADY_DISCONNECTED));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_DISCONNECTED));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -203,7 +203,7 @@ BluetoothA2dpManager::Disconnect(BluetoothProfileController* aController)
|
||||
|
||||
if (NS_FAILED(bs->SendSinkMessage(mDeviceAddress,
|
||||
NS_LITERAL_STRING("Disconnect")))) {
|
||||
aController->OnDisconnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -220,7 +220,7 @@ BluetoothA2dpManager::OnConnect(const nsAString& aErrorStr)
|
||||
NS_ENSURE_TRUE_VOID(mController);
|
||||
|
||||
nsRefPtr<BluetoothProfileController> controller = mController.forget();
|
||||
controller->OnConnect(aErrorStr);
|
||||
controller->NotifyCompletion(aErrorStr);
|
||||
}
|
||||
|
||||
void
|
||||
@ -235,7 +235,8 @@ BluetoothA2dpManager::OnDisconnect(const nsAString& aErrorStr)
|
||||
NS_ENSURE_TRUE_VOID(mController);
|
||||
|
||||
nsRefPtr<BluetoothProfileController> controller = mController.forget();
|
||||
controller->OnDisconnect(aErrorStr);
|
||||
controller->NotifyCompletion(aErrorStr);
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@ -311,7 +312,7 @@ BluetoothA2dpManager::HandleSinkPropertyChanged(const BluetoothSignal& aSignal)
|
||||
if (prevState == SinkState::SINK_PLAYING) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// case 3: Successfully connected
|
||||
MOZ_ASSERT(prevState == SinkState::SINK_CONNECTING);
|
||||
|
||||
|
@ -1070,15 +1070,15 @@ BluetoothHfpManager::Connect(const nsAString& aDeviceAddress,
|
||||
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
if (!bs || sInShutdown) {
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
|
||||
if (mSocket) {
|
||||
if (mDeviceAddress == aDeviceAddress) {
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
|
||||
} else {
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_REACHED_CONNECTION_LIMIT));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_REACHED_CONNECTION_LIMIT));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -1087,7 +1087,7 @@ BluetoothHfpManager::Connect(const nsAString& aDeviceAddress,
|
||||
BluetoothUuidHelper::GetString(BluetoothServiceClass::HANDSFREE, uuid);
|
||||
|
||||
if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress, uuid, this))) {
|
||||
aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1158,7 +1158,7 @@ BluetoothHfpManager::Disconnect(BluetoothProfileController* aController)
|
||||
|
||||
if (!mSocket) {
|
||||
if (aController) {
|
||||
aController->OnDisconnect(NS_LITERAL_STRING(ERR_ALREADY_DISCONNECTED));
|
||||
aController->NotifyCompletion(NS_LITERAL_STRING(ERR_ALREADY_DISCONNECTED));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -1912,7 +1912,7 @@ BluetoothHfpManager::OnConnect(const nsAString& aErrorStr)
|
||||
NS_ENSURE_TRUE_VOID(mController);
|
||||
|
||||
nsRefPtr<BluetoothProfileController> controller = mController.forget();
|
||||
controller->OnConnect(aErrorStr);
|
||||
controller->NotifyCompletion(aErrorStr);
|
||||
}
|
||||
|
||||
void
|
||||
@ -1931,7 +1931,7 @@ BluetoothHfpManager::OnDisconnect(const nsAString& aErrorStr)
|
||||
NS_ENSURE_TRUE_VOID(mController);
|
||||
|
||||
nsRefPtr<BluetoothProfileController> controller = mController.forget();
|
||||
controller->OnDisconnect(aErrorStr);
|
||||
controller->NotifyCompletion(aErrorStr);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(BluetoothHfpManager, nsIObserver)
|
||||
|
Loading…
Reference in New Issue
Block a user