Chromium Code Reviews| Index: components/arc/bluetooth/arc_bluetooth_bridge.cc |
| diff --git a/components/arc/bluetooth/arc_bluetooth_bridge.cc b/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| index dbc6747b662299696c5c1ebb56d1a9f069e3b04c..389a208ec23febdd23e4e323927cc419dcab362f 100644 |
| --- a/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| +++ b/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| @@ -186,7 +186,6 @@ ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) |
| } else { |
| VLOG(1) << "no bluetooth adapter available"; |
| } |
| - |
| arc_bridge_service()->bluetooth()->AddObserver(this); |
| } |
| @@ -207,7 +206,14 @@ void ArcBluetoothBridge::OnAdapterInitialized( |
| // so our adapter uses BlueZ. |
| bluetooth_adapter_ = |
| static_cast<bluez::BluetoothAdapterBlueZ*>(adapter.get()); |
| - bluetooth_adapter_->AddObserver(this); |
| + |
| + // Arc instance is ready before Bluetooth adapter. |
| + // We should register ourself to bluetooth observer here. |
|
Luis Héctor Chávez
2016/08/08 21:12:03
nit: s/ourself/ourselves/. Same below.
puthik_chromium
2016/08/08 21:40:25
Done.
|
| + if (!bluetooth_observer_flag_ && |
| + arc_bridge_service()->bluetooth()->instance()) { |
| + bluetooth_observer_flag_ = true; |
| + bluetooth_adapter_->AddObserver(this); |
| + } |
| } |
| void ArcBluetoothBridge::OnInstanceReady() { |
| @@ -218,7 +224,19 @@ void ArcBluetoothBridge::OnInstanceReady() { |
| << "but no bluetooth instance found"; |
| return; |
| } |
| - bluetooth_instance->Init(binding_.CreateInterfacePtrAndBind()); |
|
rkc
2016/08/08 21:16:15
Where are we doing this now?
puthik_chromium
2016/08/08 21:40:25
My error. Fixed
|
| + |
| + // Bluetooth adapter is ready before Arc instance. |
| + // We should register ourself to bluetooth observer here. |
| + if (!bluetooth_observer_flag_ && bluetooth_adapter_) { |
| + bluetooth_observer_flag_ = true; |
| + bluetooth_adapter_->AddObserver(this); |
| + } |
| +} |
| + |
| +void ArcBluetoothBridge::OnInstanceClosed() { |
| + if (bluetooth_observer_flag_ && bluetooth_adapter_) |
|
Luis Héctor Chávez
2016/08/08 21:12:03
If you remove the flag like rkc@ suggested, maybe
rkc
2016/08/08 21:16:15
+1
puthik_chromium
2016/08/08 21:40:25
I changed to code to hold make bluetooth_adapter_
|
| + bluetooth_adapter_->RemoveObserver(this); |
| + bluetooth_observer_flag_ = false; |
| } |
| void ArcBluetoothBridge::AdapterPoweredChanged(BluetoothAdapter* adapter, |