Index: trunk/src/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc |
=================================================================== |
--- trunk/src/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc (revision 255369) |
+++ trunk/src/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc (working copy) |
@@ -636,19 +636,25 @@ |
void BluetoothStartDiscoveryFunction::OnErrorCallback() { |
SetError(kStartDiscoveryFailed); |
+ GetEventRouter(browser_context())->SetResponsibleForDiscovery(false); |
SendResponse(false); |
GetEventRouter(browser_context())->OnListenerRemoved(); |
} |
bool BluetoothStartDiscoveryFunction::DoWork( |
scoped_refptr<BluetoothAdapter> adapter) { |
- GetEventRouter(browser_context())->OnListenerAdded(); |
- GetEventRouter(browser_context())->StartDiscoverySession( |
- adapter, |
- extension_id(), |
- base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this), |
- base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this)); |
+ GetEventRouter(browser_context())->SetSendDiscoveryEvents(true); |
+ // If this profile is already discovering devices, there should be nothing |
+ // else to do. |
+ if (!GetEventRouter(browser_context())->IsResponsibleForDiscovery()) { |
+ GetEventRouter(browser_context())->SetResponsibleForDiscovery(true); |
+ GetEventRouter(browser_context())->OnListenerAdded(); |
+ adapter->StartDiscovering( |
+ base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this), |
+ base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this)); |
+ } |
+ |
return true; |
} |
@@ -659,17 +665,19 @@ |
void BluetoothStopDiscoveryFunction::OnErrorCallback() { |
SetError(kStopDiscoveryFailed); |
+ GetEventRouter(browser_context())->SetResponsibleForDiscovery(true); |
SendResponse(false); |
GetEventRouter(browser_context())->OnListenerRemoved(); |
} |
bool BluetoothStopDiscoveryFunction::DoWork( |
scoped_refptr<BluetoothAdapter> adapter) { |
- GetEventRouter(browser_context())->StopDiscoverySession( |
- adapter, |
- extension_id(), |
- base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
- base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
+ GetEventRouter(browser_context())->SetSendDiscoveryEvents(false); |
+ if (GetEventRouter(browser_context())->IsResponsibleForDiscovery()) { |
+ adapter->StopDiscovering( |
+ base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
+ base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
+ } |
return true; |
} |