diff options
author | zork <zork@chromium.org> | 2014-09-16 18:22:53 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-17 01:23:02 +0000 |
commit | 20e0b1a5f52f1cc0ab24becf9d6ec3d4ba84b7c7 (patch) | |
tree | 2f83f1742bd79af809e803f2fe9fff2950e66a27 | |
parent | 9d512d39f67d54651f9eead2d94e8262f8b156f9 (diff) | |
download | chromium_src-20e0b1a5f52f1cc0ab24becf9d6ec3d4ba84b7c7.zip chromium_src-20e0b1a5f52f1cc0ab24becf9d6ec3d4ba84b7c7.tar.gz chromium_src-20e0b1a5f52f1cc0ab24becf9d6ec3d4ba84b7c7.tar.bz2 |
Wait for the Bluetooth adapter to be present before starting pairing.
BUG=None
Review URL: https://codereview.chromium.org/552983003
Cr-Commit-Position: refs/heads/master@{#295207}
-rw-r--r-- | components/pairing/bluetooth_host_pairing_controller.cc | 25 | ||||
-rw-r--r-- | components/pairing/bluetooth_host_pairing_controller.h | 7 |
2 files changed, 31 insertions, 1 deletions
diff --git a/components/pairing/bluetooth_host_pairing_controller.cc b/components/pairing/bluetooth_host_pairing_controller.cc index 53a6187..3d62c3ac 100644 --- a/components/pairing/bluetooth_host_pairing_controller.cc +++ b/components/pairing/bluetooth_host_pairing_controller.cc @@ -26,7 +26,10 @@ BluetoothHostPairingController::BluetoothHostPairingController() ptr_factory_(this) { } -BluetoothHostPairingController::~BluetoothHostPairingController() {} +BluetoothHostPairingController::~BluetoothHostPairingController() { + if (adapter_.get()) + adapter_->RemoveObserver(this); +} void BluetoothHostPairingController::ChangeStage(Stage new_stage) { if (current_stage_ == new_stage) @@ -106,9 +109,19 @@ void BluetoothHostPairingController::OnGetAdapter( DCHECK(!adapter_.get()); adapter_ = adapter; + if (adapter_->IsPresent()) { + SetName(); + } else { + // Set the name once the adapter is present. + adapter_->AddObserver(this); + } +} + +void BluetoothHostPairingController::SetName() { // TODO(zork): Make the device name prettier. (http://crbug.com/405774) device_name_ = base::StringPrintf("%s%s", kDeviceNamePrefix, adapter_->GetAddress().c_str()); + adapter_->SetName( device_name_, base::Bind(&BluetoothHostPairingController::OnSetName, @@ -298,6 +311,16 @@ void BluetoothHostPairingController::OnErrorMessage( NOTREACHED(); } +void BluetoothHostPairingController::AdapterPresentChanged( + device::BluetoothAdapter* adapter, + bool present) { + DCHECK_EQ(adapter, adapter_.get()); + if (present) { + adapter_->RemoveObserver(this); + SetName(); + } +} + void BluetoothHostPairingController::AddObserver(Observer* observer) { observers_.AddObserver(observer); } diff --git a/components/pairing/bluetooth_host_pairing_controller.h b/components/pairing/bluetooth_host_pairing_controller.h index 4dd0962..05feab1 100644 --- a/components/pairing/bluetooth_host_pairing_controller.h +++ b/components/pairing/bluetooth_host_pairing_controller.h @@ -12,6 +12,7 @@ #include "base/threading/thread_checker.h" #include "components/pairing/host_pairing_controller.h" #include "components/pairing/proto_decoder.h" +#include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_device.h" #include "device/bluetooth/bluetooth_socket.h" @@ -28,6 +29,7 @@ namespace pairing_chromeos { class BluetoothHostPairingController : public HostPairingController, public ProtoDecoder::Observer, + public device::BluetoothAdapter::Observer, public device::BluetoothDevice::PairingDelegate { public: typedef HostPairingController::Observer Observer; @@ -42,6 +44,7 @@ class BluetoothHostPairingController void Reset(); void OnGetAdapter(scoped_refptr<device::BluetoothAdapter> adapter); + void SetName(); void OnSetName(); void OnSetPowered(); void OnCreateService(scoped_refptr<device::BluetoothSocket> socket); @@ -80,6 +83,10 @@ class BluetoothHostPairingController const pairing_api::CompleteSetup& message) OVERRIDE; virtual void OnErrorMessage(const pairing_api::Error& message) OVERRIDE; + // BluetoothAdapter::Observer: + virtual void AdapterPresentChanged(device::BluetoothAdapter* adapter, + bool present) OVERRIDE; + // device::BluetoothDevice::PairingDelegate: virtual void RequestPinCode(device::BluetoothDevice* device) OVERRIDE; virtual void RequestPasskey(device::BluetoothDevice* device) OVERRIDE; |