Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" | 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
| 6 | 6 |
| 7 #if defined(OS_CHROMEOS) | 7 #if defined(OS_CHROMEOS) |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 #endif | 43 #endif |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 const char kCouldNotGetLocalOutOfBandPairingData[] = | 47 const char kCouldNotGetLocalOutOfBandPairingData[] = |
| 48 "Could not get local Out Of Band Pairing Data"; | 48 "Could not get local Out Of Band Pairing Data"; |
| 49 const char kCouldNotSetOutOfBandPairingData[] = | 49 const char kCouldNotSetOutOfBandPairingData[] = |
| 50 "Could not set Out Of Band Pairing Data"; | 50 "Could not set Out Of Band Pairing Data"; |
| 51 const char kDiscoveryInProgress[] = "Discovery already in progress"; | |
| 51 const char kFailedToConnect[] = "Connection failed"; | 52 const char kFailedToConnect[] = "Connection failed"; |
| 52 const char kInvalidDevice[] = "Invalid device"; | 53 const char kInvalidDevice[] = "Invalid device"; |
| 53 const char kServiceDiscoveryFailed[] = "Service discovery failed"; | 54 const char kServiceDiscoveryFailed[] = "Service discovery failed"; |
| 54 const char kSocketNotFoundError[] = "Socket not found: invalid socket id"; | 55 const char kSocketNotFoundError[] = "Socket not found: invalid socket id"; |
| 55 const char kStartDiscoveryFailed[] = | 56 const char kStartDiscoveryFailed[] = "Starting discovery failed"; |
| 56 "Starting discovery failed, or already discovering"; | |
| 57 const char kStopDiscoveryFailed[] = "Failed to stop discovery"; | 57 const char kStopDiscoveryFailed[] = "Failed to stop discovery"; |
| 58 | 58 |
| 59 } // namespace | 59 } // namespace |
| 60 | 60 |
| 61 namespace Connect = extensions::api::experimental_bluetooth::Connect; | 61 namespace Connect = extensions::api::experimental_bluetooth::Connect; |
| 62 namespace Disconnect = extensions::api::experimental_bluetooth::Disconnect; | 62 namespace Disconnect = extensions::api::experimental_bluetooth::Disconnect; |
| 63 namespace GetDevices = extensions::api::experimental_bluetooth::GetDevices; | 63 namespace GetDevices = extensions::api::experimental_bluetooth::GetDevices; |
| 64 namespace GetServices = extensions::api::experimental_bluetooth::GetServices; | 64 namespace GetServices = extensions::api::experimental_bluetooth::GetServices; |
| 65 namespace Read = extensions::api::experimental_bluetooth::Read; | 65 namespace Read = extensions::api::experimental_bluetooth::Read; |
| 66 namespace SetOutOfBandPairingData = | 66 namespace SetOutOfBandPairingData = |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 } | 449 } |
| 450 | 450 |
| 451 void BluetoothStartDiscoveryFunction::OnErrorCallback() { | 451 void BluetoothStartDiscoveryFunction::OnErrorCallback() { |
| 452 SetError(kStartDiscoveryFailed); | 452 SetError(kStartDiscoveryFailed); |
| 453 SendResponse(false); | 453 SendResponse(false); |
| 454 } | 454 } |
| 455 | 455 |
| 456 bool BluetoothStartDiscoveryFunction::RunImpl() { | 456 bool BluetoothStartDiscoveryFunction::RunImpl() { |
| 457 GetEventRouter(profile())->SetSendDiscoveryEvents(true); | 457 GetEventRouter(profile())->SetSendDiscoveryEvents(true); |
| 458 | 458 |
| 459 // BluetoothAdapter will throw an error if we SetDiscovering(true) when | 459 // Fail if discovery is already in progress: this extension has missed all |
| 460 // discovery is already in progress | 460 // discovered devices so far. It should re-try discovery after discovery has |
| 461 // finished. | |
|
asargent_no_longer_on_chrome
2012/07/24 20:29:45
Random thought- this can happen because *another*
bryeung
2012/08/03 20:08:37
I had originally decided against this, but your co
| |
| 461 if (GetMutableAdapter(profile())->IsDiscovering()) { | 462 if (GetMutableAdapter(profile())->IsDiscovering()) { |
| 462 SendResponse(true); | 463 SetError(kDiscoveryInProgress); |
| 463 return true; | 464 return false; |
| 464 } | 465 } |
| 465 | 466 |
| 466 GetMutableAdapter(profile())->SetDiscovering(true, | 467 GetMutableAdapter(profile())->SetDiscovering(true, |
| 467 base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this), | 468 base::Bind(&BluetoothStartDiscoveryFunction::OnSuccessCallback, this), |
| 468 base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this)); | 469 base::Bind(&BluetoothStartDiscoveryFunction::OnErrorCallback, this)); |
| 469 return true; | 470 return true; |
| 470 } | 471 } |
| 471 | 472 |
| 472 void BluetoothStopDiscoveryFunction::OnSuccessCallback() { | 473 void BluetoothStopDiscoveryFunction::OnSuccessCallback() { |
| 473 SendResponse(true); | 474 SendResponse(true); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 #endif | 574 #endif |
| 574 | 575 |
| 575 BluetoothReadFunction::BluetoothReadFunction() {} | 576 BluetoothReadFunction::BluetoothReadFunction() {} |
| 576 BluetoothReadFunction::~BluetoothReadFunction() {} | 577 BluetoothReadFunction::~BluetoothReadFunction() {} |
| 577 | 578 |
| 578 BluetoothWriteFunction::BluetoothWriteFunction() {} | 579 BluetoothWriteFunction::BluetoothWriteFunction() {} |
| 579 BluetoothWriteFunction::~BluetoothWriteFunction() {} | 580 BluetoothWriteFunction::~BluetoothWriteFunction() {} |
| 580 | 581 |
| 581 } // namespace api | 582 } // namespace api |
| 582 } // namespace extensions | 583 } // namespace extensions |
| OLD | NEW |