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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
18 #include "components/proximity_auth/ble/bluetooth_low_energy_connection.h" | 18 #include "components/proximity_auth/ble/bluetooth_low_energy_connection.h" |
19 #include "components/proximity_auth/ble/bluetooth_low_energy_device_whitelist.h" | 19 #include "components/proximity_auth/ble/bluetooth_low_energy_device_whitelist.h" |
20 #include "components/proximity_auth/logging/logging.h" | 20 #include "components/proximity_auth/logging/logging.h" |
21 #include "device/bluetooth/bluetooth_adapter_factory.h" | 21 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 22 #include "device/bluetooth/bluetooth_common.h" |
22 #include "device/bluetooth/bluetooth_device.h" | 23 #include "device/bluetooth/bluetooth_device.h" |
23 #include "device/bluetooth/bluetooth_discovery_session.h" | 24 #include "device/bluetooth/bluetooth_discovery_session.h" |
24 #include "device/bluetooth/bluetooth_uuid.h" | 25 #include "device/bluetooth/bluetooth_uuid.h" |
25 | 26 |
26 using device::BluetoothAdapter; | 27 using device::BluetoothAdapter; |
27 using device::BluetoothDevice; | 28 using device::BluetoothDevice; |
28 using device::BluetoothGattConnection; | 29 using device::BluetoothGattConnection; |
29 using device::BluetoothDiscoveryFilter; | 30 using device::BluetoothDiscoveryFilter; |
30 | 31 |
31 namespace proximity_auth { | 32 namespace proximity_auth { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } | 221 } |
221 | 222 |
222 void BluetoothLowEnergyConnectionFinder::StartDiscoverySession() { | 223 void BluetoothLowEnergyConnectionFinder::StartDiscoverySession() { |
223 DCHECK(adapter_); | 224 DCHECK(adapter_); |
224 if (discovery_session_ && discovery_session_->IsActive()) { | 225 if (discovery_session_ && discovery_session_->IsActive()) { |
225 PA_LOG(INFO) << "Discovery session already active"; | 226 PA_LOG(INFO) << "Discovery session already active"; |
226 return; | 227 return; |
227 } | 228 } |
228 | 229 |
229 // Discover only low energy (LE) devices with strong enough signal. | 230 // Discover only low energy (LE) devices with strong enough signal. |
230 std::unique_ptr<BluetoothDiscoveryFilter> filter(new BluetoothDiscoveryFilter( | 231 std::unique_ptr<BluetoothDiscoveryFilter> filter( |
231 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE)); | 232 new BluetoothDiscoveryFilter(device::BLUETOOTH_TRANSPORT_LE)); |
232 filter->SetRSSI(kMinDiscoveryRSSI); | 233 filter->SetRSSI(kMinDiscoveryRSSI); |
233 | 234 |
234 adapter_->StartDiscoverySessionWithFilter( | 235 adapter_->StartDiscoverySessionWithFilter( |
235 std::move(filter), | 236 std::move(filter), |
236 base::Bind(&BluetoothLowEnergyConnectionFinder::OnDiscoverySessionStarted, | 237 base::Bind(&BluetoothLowEnergyConnectionFinder::OnDiscoverySessionStarted, |
237 weak_ptr_factory_.GetWeakPtr()), | 238 weak_ptr_factory_.GetWeakPtr()), |
238 base::Bind( | 239 base::Bind( |
239 &BluetoothLowEnergyConnectionFinder::OnStartDiscoverySessionError, | 240 &BluetoothLowEnergyConnectionFinder::OnStartDiscoverySessionError, |
240 weak_ptr_factory_.GetWeakPtr())); | 241 weak_ptr_factory_.GetWeakPtr())); |
241 } | 242 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 return device; | 311 return device; |
311 } | 312 } |
312 return nullptr; | 313 return nullptr; |
313 } | 314 } |
314 | 315 |
315 void BluetoothLowEnergyConnectionFinder::InvokeCallbackAsync() { | 316 void BluetoothLowEnergyConnectionFinder::InvokeCallbackAsync() { |
316 connection_callback_.Run(std::move(connection_)); | 317 connection_callback_.Run(std::move(connection_)); |
317 } | 318 } |
318 | 319 |
319 } // namespace proximity_auth | 320 } // namespace proximity_auth |
OLD | NEW |