OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h
" | 5 #include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h
" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 StartDiscoverySession(); | 307 StartDiscoverySession(); |
308 } else { | 308 } else { |
309 base::ThreadTaskRunnerHandle::Get()->PostTask( | 309 base::ThreadTaskRunnerHandle::Get()->PostTask( |
310 FROM_HERE, base::Bind(&BluetoothLowEnergyConnectionFinder:: | 310 FROM_HERE, base::Bind(&BluetoothLowEnergyConnectionFinder:: |
311 RestartDiscoverySessionWhenReady, | 311 RestartDiscoverySessionWhenReady, |
312 weak_ptr_factory_.GetWeakPtr())); | 312 weak_ptr_factory_.GetWeakPtr())); |
313 } | 313 } |
314 } | 314 } |
315 | 315 |
316 BluetoothDevice* BluetoothLowEnergyConnectionFinder::GetDevice( | 316 BluetoothDevice* BluetoothLowEnergyConnectionFinder::GetDevice( |
317 std::string device_address) { | 317 const std::string& device_address) { |
318 // It's not possible to simply use | 318 // It's not possible to simply use |
319 // |adapter_->GetDevice(GetRemoteDeviceAddress())| to find the device with MAC | 319 // |adapter_->GetDevice(GetRemoteDeviceAddress())| to find the device with MAC |
320 // address |GetRemoteDeviceAddress()|. For paired devices, | 320 // address |GetRemoteDeviceAddress()|. For paired devices, |
321 // BluetoothAdapter::GetDevice(XXX) searches for the temporary MAC address | 321 // BluetoothAdapter::GetDevice(XXX) searches for the temporary MAC address |
322 // XXX, whereas |remote_device_.bluetooth_address| is the real MAC address. | 322 // XXX, whereas |remote_device_.bluetooth_address| is the real MAC address. |
323 // This is a bug in the way device::BluetoothAdapter is storing the devices | 323 // This is a bug in the way device::BluetoothAdapter is storing the devices |
324 // (see crbug.com/497841). | 324 // (see crbug.com/497841). |
325 std::vector<BluetoothDevice*> devices = adapter_->GetDevices(); | 325 std::vector<BluetoothDevice*> devices = adapter_->GetDevices(); |
326 for (const auto& device : devices) { | 326 for (const auto& device : devices) { |
327 if (device->GetAddress() == device_address) | 327 if (device->GetAddress() == device_address) |
328 return device; | 328 return device; |
329 } | 329 } |
330 return nullptr; | 330 return nullptr; |
331 } | 331 } |
332 | 332 |
333 void BluetoothLowEnergyConnectionFinder::InvokeCallbackAsync() { | 333 void BluetoothLowEnergyConnectionFinder::InvokeCallbackAsync() { |
334 connection_callback_.Run(connection_.Pass()); | 334 connection_callback_.Run(connection_.Pass()); |
335 } | 335 } |
336 | 336 |
337 } // namespace proximity_auth | 337 } // namespace proximity_auth |
OLD | NEW |