Index: chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
index 90528caa1701bac0f631a6ede8a33793493c129b..ae7cb9ae63c8e66e52d2ffcad35c812e8027c74c 100644 |
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
@@ -52,8 +52,7 @@ const char kFailedToConnect[] = "Connection failed"; |
const char kInvalidDevice[] = "Invalid device"; |
const char kServiceDiscoveryFailed[] = "Service discovery failed"; |
const char kSocketNotFoundError[] = "Socket not found: invalid socket id"; |
-const char kStartDiscoveryFailed[] = |
- "Starting discovery failed, or already discovering"; |
+const char kStartDiscoveryFailed[] = "Starting discovery failed"; |
const char kStopDiscoveryFailed[] = "Failed to stop discovery"; |
} // namespace |
@@ -445,6 +444,7 @@ bool BluetoothGetLocalOutOfBandPairingDataFunction::RunImpl() { |
} |
void BluetoothStartDiscoveryFunction::OnSuccessCallback() { |
+ GetEventRouter(profile())->SetResponsibleForDiscovery(true); |
SendResponse(true); |
} |
@@ -456,8 +456,7 @@ void BluetoothStartDiscoveryFunction::OnErrorCallback() { |
bool BluetoothStartDiscoveryFunction::RunImpl() { |
GetEventRouter(profile())->SetSendDiscoveryEvents(true); |
- // BluetoothAdapter will throw an error if we SetDiscovering(true) when |
- // discovery is already in progress |
+ // If the adapter is already discovering, there is nothing else to do. |
if (GetMutableAdapter(profile())->IsDiscovering()) { |
SendResponse(true); |
return true; |
@@ -480,9 +479,11 @@ void BluetoothStopDiscoveryFunction::OnErrorCallback() { |
bool BluetoothStopDiscoveryFunction::RunImpl() { |
GetEventRouter(profile())->SetSendDiscoveryEvents(false); |
- GetMutableAdapter(profile())->SetDiscovering(false, |
- base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
- base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
+ if (GetEventRouter(profile())->IsResponsibleForDiscovery()) { |
+ GetMutableAdapter(profile())->SetDiscovering(false, |
+ base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
+ base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
+ } |
return true; |
} |