зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1038053 - Resolve stopDiscovery when adapter is not discovering, r=echou
This commit is contained in:
Родитель
884b5973eb
Коммит
99cf08ac11
|
@ -413,7 +413,7 @@ BluetoothAdapter::SetDiscoveryHandleInUse(
|
|||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
BluetoothAdapter::StartStopDiscovery(bool aStart, ErrorResult& aRv)
|
||||
BluetoothAdapter::StartDiscovery(ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
||||
if (!global) {
|
||||
|
@ -424,49 +424,60 @@ BluetoothAdapter::StartStopDiscovery(bool aStart, ErrorResult& aRv)
|
|||
|
||||
/**
|
||||
* Ensure
|
||||
* - adapter does not already start/stop discovering,
|
||||
* (note we reject here to ensure each resolved promise of startDiscovery
|
||||
* returns a BluetoothDiscoveryHandle)
|
||||
* - adapter is not discovering (note we reject here to ensure
|
||||
each resolved promise returns a new BluetoothDiscoveryHandle),
|
||||
* - adapter is already enabled, and
|
||||
* - BluetoothService is available
|
||||
*/
|
||||
BT_ENSURE_TRUE_REJECT(mDiscovering != aStart,
|
||||
NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
BT_ENSURE_TRUE_REJECT(!mDiscovering, NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
BT_ENSURE_TRUE_REJECT(mState == BluetoothAdapterState::Enabled,
|
||||
NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
BT_ENSURE_TRUE_REJECT(bs, NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
BT_API2_LOGR("aStart %d", aStart);
|
||||
nsresult rv;
|
||||
if (aStart) {
|
||||
// Start discovery: return BluetoothDiscoveryHandle in StartDiscoveryTask
|
||||
nsRefPtr<BluetoothReplyRunnable> result =
|
||||
new StartDiscoveryTask(this, promise);
|
||||
rv = bs->StartDiscoveryInternal(result);
|
||||
} else {
|
||||
// Stop discovery: void return
|
||||
nsRefPtr<BluetoothReplyRunnable> result =
|
||||
new BluetoothVoidReplyRunnable(nullptr /* DOMRequest */,
|
||||
promise,
|
||||
NS_LITERAL_STRING("StopDiscovery"));
|
||||
rv = bs->StopDiscoveryInternal(result);
|
||||
}
|
||||
BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(rv), NS_ERROR_DOM_OPERATION_ERR);
|
||||
BT_API2_LOGR();
|
||||
|
||||
// Return BluetoothDiscoveryHandle in StartDiscoveryTask
|
||||
nsRefPtr<BluetoothReplyRunnable> result =
|
||||
new StartDiscoveryTask(this, promise);
|
||||
BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(bs->StartDiscoveryInternal(result)),
|
||||
NS_ERROR_DOM_OPERATION_ERR);
|
||||
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
BluetoothAdapter::StartDiscovery(ErrorResult& aRv)
|
||||
{
|
||||
return StartStopDiscovery(true, aRv);
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
BluetoothAdapter::StopDiscovery(ErrorResult& aRv)
|
||||
{
|
||||
return StartStopDiscovery(false, aRv);
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
||||
if (!global) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsRefPtr<Promise> promise = new Promise(global);
|
||||
|
||||
/**
|
||||
* Ensure
|
||||
* - adapter is discovering,
|
||||
* - adapter is already enabled, and
|
||||
* - BluetoothService is available
|
||||
*/
|
||||
BT_ENSURE_TRUE_RESOLVE(mDiscovering, JS::UndefinedHandleValue);
|
||||
BT_ENSURE_TRUE_REJECT(mState == BluetoothAdapterState::Enabled,
|
||||
NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
BluetoothService* bs = BluetoothService::Get();
|
||||
BT_ENSURE_TRUE_REJECT(bs, NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
BT_API2_LOGR();
|
||||
|
||||
nsRefPtr<BluetoothReplyRunnable> result =
|
||||
new BluetoothVoidReplyRunnable(nullptr /* DOMRequest */,
|
||||
promise,
|
||||
NS_LITERAL_STRING("StopDiscovery"));
|
||||
BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(bs->StopDiscoveryInternal(result)),
|
||||
NS_ERROR_DOM_OPERATION_ERR);
|
||||
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -188,7 +188,6 @@ private:
|
|||
|
||||
void Root();
|
||||
|
||||
already_AddRefed<Promise> StartStopDiscovery(bool aStart, ErrorResult& aRv);
|
||||
already_AddRefed<mozilla::dom::DOMRequest>
|
||||
PairUnpair(bool aPair, const nsAString& aDeviceAddress, ErrorResult& aRv);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче