Chromium Code Reviews| Index: components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc |
| diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc |
| index 420500f835164e10d34bf340c0cc85e059354514..c4c7afe1f77d1aea5cf28489fbe80c7affc90f87 100644 |
| --- a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc |
| +++ b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc |
| @@ -114,7 +114,6 @@ void BluetoothLowEnergyConnectionFinder::DeviceChanged( |
| BluetoothDevice* device) { |
| DCHECK_EQ(adapter_.get(), adapter); |
| DCHECK(device); |
| - PA_LOG(INFO) << "Device changed: " << device->GetAddress(); |
|
sacomoto
2015/08/10 19:40:28
nit: move it inside the if instead of removing it.
Tim Song
2015/08/10 22:17:55
Done.
|
| // Note: Only consider |device| when it was actually added/updated during a |
| // scanning, otherwise the device is stale and the GATT connection will fail. |
| @@ -266,11 +265,14 @@ void BluetoothLowEnergyConnectionFinder::OnConnectionStatusChanged( |
| adapter_->RemoveObserver(this); |
| connection_->RemoveObserver(this); |
| - // Note: any observer of |connection_| added in |connection_callback_| will |
| - // also receive this |OnConnectionStatusChanged| notification (IN_PROGRESS |
| - // -> CONNECTED). |
| - connection_callback_.Run(connection_.Pass()); |
| - connection_callback_.Reset(); |
| + // If we invoke the callback now, the callback function may install its own |
| + // observer to |connection_|. Because we are in the ConnectionObserver |
| + // callstack, this new observer will receive this connection event. |
| + // Therefore, we need to invoke the callback asynchronously. |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&BluetoothLowEnergyConnectionFinder::InvokeCallbackAsync, |
| + weak_ptr_factory_.GetWeakPtr())); |
| } else if (old_status == Connection::IN_PROGRESS) { |
| PA_LOG(WARNING) << "Connection failed. Retrying."; |
| RestartDiscoverySessionWhenReady(); |
| @@ -315,4 +317,8 @@ BluetoothDevice* BluetoothLowEnergyConnectionFinder::GetDevice( |
| return nullptr; |
| } |
| +void BluetoothLowEnergyConnectionFinder::InvokeCallbackAsync() { |
| + connection_callback_.Run(connection_.Pass()); |
| +} |
| + |
| } // namespace proximity_auth |