| 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 <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 PA_LOG(INFO) << "Adapter ready"; | 190 PA_LOG(INFO) << "Adapter ready"; |
| 191 | 191 |
| 192 adapter_ = adapter; | 192 adapter_ = adapter; |
| 193 adapter_->AddObserver(this); | 193 adapter_->AddObserver(this); |
| 194 | 194 |
| 195 // This is important for debugging. To eliminate the case where the device was | 195 // This is important for debugging. To eliminate the case where the device was |
| 196 // removed (forgotten) by the user, or BlueZ didn't load the device correctly. | 196 // removed (forgotten) by the user, or BlueZ didn't load the device correctly. |
| 197 if (finder_strategy_ == FIND_PAIRED_DEVICE) { | 197 if (finder_strategy_ == FIND_PAIRED_DEVICE) { |
| 198 PA_LOG(INFO) << "Looking for paired device: " | 198 PA_LOG(INFO) << "Looking for paired device: " |
| 199 << remote_device_.bluetooth_address; | 199 << remote_device_.bluetooth_address; |
| 200 for (auto& device : adapter_->GetDevices()) { | 200 for (auto* device : adapter_->GetDevices()) { |
| 201 if (device->IsPaired()) | 201 if (device->IsPaired()) |
| 202 PA_LOG(INFO) << device->GetAddress() << " is paired"; | 202 PA_LOG(INFO) << device->GetAddress() << " is paired"; |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 | 205 |
| 206 // Note: It's possible to connect to the paired directly, so when using | 206 // Note: It's possible to connect to the paired directly, so when using |
| 207 // FIND_PAIRED_DEVICE strategy this is not necessary. However, the discovery | 207 // FIND_PAIRED_DEVICE strategy this is not necessary. However, the discovery |
| 208 // doesn't add a lot of latency, and the makes the code path for both | 208 // doesn't add a lot of latency, and the makes the code path for both |
| 209 // strategies more similar. | 209 // strategies more similar. |
| 210 StartDiscoverySession(); | 210 StartDiscoverySession(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 BluetoothDevice* BluetoothLowEnergyConnectionFinder::GetDevice( | 299 BluetoothDevice* BluetoothLowEnergyConnectionFinder::GetDevice( |
| 300 const std::string& device_address) { | 300 const std::string& device_address) { |
| 301 // It's not possible to simply use | 301 // It's not possible to simply use |
| 302 // |adapter_->GetDevice(GetRemoteDeviceAddress())| to find the device with MAC | 302 // |adapter_->GetDevice(GetRemoteDeviceAddress())| to find the device with MAC |
| 303 // address |GetRemoteDeviceAddress()|. For paired devices, | 303 // address |GetRemoteDeviceAddress()|. For paired devices, |
| 304 // BluetoothAdapter::GetDevice(XXX) searches for the temporary MAC address | 304 // BluetoothAdapter::GetDevice(XXX) searches for the temporary MAC address |
| 305 // XXX, whereas |remote_device_.bluetooth_address| is the real MAC address. | 305 // XXX, whereas |remote_device_.bluetooth_address| is the real MAC address. |
| 306 // This is a bug in the way device::BluetoothAdapter is storing the devices | 306 // This is a bug in the way device::BluetoothAdapter is storing the devices |
| 307 // (see crbug.com/497841). | 307 // (see crbug.com/497841). |
| 308 std::vector<BluetoothDevice*> devices = adapter_->GetDevices(); | 308 std::vector<BluetoothDevice*> devices = adapter_->GetDevices(); |
| 309 for (const auto& device : devices) { | 309 for (auto* device : devices) { |
| 310 if (device->GetAddress() == device_address) | 310 if (device->GetAddress() == device_address) |
| 311 return device; | 311 return device; |
| 312 } | 312 } |
| 313 return nullptr; | 313 return nullptr; |
| 314 } | 314 } |
| 315 | 315 |
| 316 void BluetoothLowEnergyConnectionFinder::InvokeCallbackAsync() { | 316 void BluetoothLowEnergyConnectionFinder::InvokeCallbackAsync() { |
| 317 connection_callback_.Run(std::move(connection_)); | 317 connection_callback_.Run(std::move(connection_)); |
| 318 } | 318 } |
| 319 | 319 |
| 320 } // namespace proximity_auth | 320 } // namespace proximity_auth |
| OLD | NEW |