Index: components/pairing/bluetooth_host_pairing_controller.cc |
diff --git a/components/pairing/bluetooth_host_pairing_controller.cc b/components/pairing/bluetooth_host_pairing_controller.cc |
index 53a6187eb072ec6058607cc09d48ab2570cd7920..3d62c3ace401f0eafd34b146eb00e1dc0c04e8c1 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); |
} |