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

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: review comments 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 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;
}

Powered by Google App Engine
This is Rietveld 408576698