| 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 7b80b96d7a4aa25bd28e63df964dc610e60d156d..731b9502cc939a724b22c51530ef43501b5688f1 100644
|
| --- a/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
|
| +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_api.cc
|
| @@ -46,6 +46,9 @@ namespace {
|
| const char kFailedToConnect[] = "Connection failed";
|
| const char kInvalidDevice[] = "Invalid device";
|
| const char kSocketNotFoundError[] = "Socket not found: invalid socket id";
|
| +const char kStartDiscoveryFailed[] =
|
| + "Starting discovery failed, or already discovering";
|
| +const char kStopDiscoveryFailed[] = "Failed to stop discovery";
|
|
|
| } // namespace
|
|
|
| @@ -302,6 +305,54 @@ bool BluetoothWriteFunction::Respond() {
|
| return success_;
|
| }
|
|
|
| +void BluetoothStartDiscoveryFunction::OnSuccessCallback() {
|
| + SendResponse(true);
|
| + Release(); // Added in RunImpl
|
| +}
|
| +
|
| +void BluetoothStartDiscoveryFunction::OnErrorCallback() {
|
| + SetError(kStartDiscoveryFailed);
|
| + SendResponse(false);
|
| + Release(); // Added in RunImpl
|
| +}
|
| +
|
| +bool BluetoothStartDiscoveryFunction::RunImpl() {
|
| + GetEventRouter(profile())->SetSendDiscoveryEvents(true);
|
| +
|
| + // BluetoothAdapter will throw an error if we SetDiscovering(true) when
|
| + // discovery is already in progress
|
| + if (GetMutableAdapter(profile())->IsDiscovering()) {
|
| + SendResponse(true);
|
| + return true;
|
| + }
|
| +
|
| + GetMutableAdapter(profile())->SetDiscovering(true,
|
| + base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this),
|
| + base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this));
|
| + AddRef(); // Removed in whichever callback is called.
|
| + return true;
|
| +}
|
| +
|
| +void BluetoothStopDiscoveryFunction::OnSuccessCallback() {
|
| + SendResponse(true);
|
| + Release(); // Added in RunImpl
|
| +}
|
| +
|
| +void BluetoothStopDiscoveryFunction::OnErrorCallback() {
|
| + SetError(kStopDiscoveryFailed);
|
| + SendResponse(false);
|
| + Release(); // Added in RunImpl
|
| +}
|
| +
|
| +bool BluetoothStopDiscoveryFunction::RunImpl() {
|
| + GetEventRouter(profile())->SetSendDiscoveryEvents(false);
|
| + GetMutableAdapter(profile())->SetDiscovering(false,
|
| + base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this),
|
| + base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this));
|
| + AddRef(); // Removed in whichever callback is called.
|
| + return true;
|
| +}
|
| +
|
| #else
|
|
|
| // -----------------------------------------------------------------------------
|
| @@ -366,6 +417,16 @@ bool BluetoothWriteFunction::Respond() {
|
| return false;
|
| }
|
|
|
| +bool BluetoothStartDiscoveryFunction::RunImpl() {
|
| + NOTREACHED() << "Not implemented yet";
|
| + return false;
|
| +}
|
| +
|
| +bool BluetoothStopDiscoveryFunction::RunImpl() {
|
| + NOTREACHED() << "Not implemented yet";
|
| + return false;
|
| +}
|
| +
|
| #endif
|
|
|
| BluetoothReadFunction::BluetoothReadFunction() {}
|
|
|