Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2227)

Unified Diff: chrome/browser/extensions/api/bluetooth/bluetooth_api.cc

Issue 10815072: Bluetooth API: improve discovery (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix licenses Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 b80497e461cdc0f296acd1743847e9e4ca98e146..461aaa58412d4c4637681c86ed808c63a6b12d9c 100644
--- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
+++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
@@ -54,8 +54,7 @@ const char kInvalidDevice[] = "Invalid device";
const char kInvalidUuid[] = "Invalid UUID";
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
@@ -459,6 +458,7 @@ bool BluetoothGetLocalOutOfBandPairingDataFunction::RunImpl() {
}
void BluetoothStartDiscoveryFunction::OnSuccessCallback() {
+ GetEventRouter(profile())->SetResponsibleForDiscovery(true);
SendResponse(true);
}
@@ -470,8 +470,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;
@@ -494,9 +493,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;
}

Powered by Google App Engine
This is Rietveld 408576698