| 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/bluetooth_low_energy_connection_finder.h" | 5 #include "components/proximity_auth/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 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 namespace proximity_auth { | 35 namespace proximity_auth { |
| 36 namespace { | 36 namespace { |
| 37 const char kAdvertisementUUID[] = "0000fe50-0000-1000-8000-00805f9b34fb"; | 37 const char kAdvertisementUUID[] = "0000fe50-0000-1000-8000-00805f9b34fb"; |
| 38 const char kBLEGattServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11"; | 38 const char kBLEGattServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11"; |
| 39 const int kRestartDiscoveryOnErrorDelaySeconds = 2; | 39 const int kRestartDiscoveryOnErrorDelaySeconds = 2; |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 BluetoothLowEnergyConnectionFinder::BluetoothLowEnergyConnectionFinder( | 42 BluetoothLowEnergyConnectionFinder::BluetoothLowEnergyConnectionFinder( |
| 43 const cryptauth::RemoteDevice remote_device, | 43 const cryptauth::RemoteDevice remote_device, |
| 44 const std::vector<cryptauth::BeaconSeed>& beacon_seeds, | |
| 45 cryptauth::BluetoothThrottler* bluetooth_throttler) | 44 cryptauth::BluetoothThrottler* bluetooth_throttler) |
| 46 : BluetoothLowEnergyConnectionFinder( | 45 : BluetoothLowEnergyConnectionFinder( |
| 47 remote_device, | 46 remote_device, |
| 48 kBLEGattServiceUUID, | 47 kBLEGattServiceUUID, |
| 49 beacon_seeds, | |
| 50 base::MakeUnique<cryptauth::BackgroundEidGenerator>(), | 48 base::MakeUnique<cryptauth::BackgroundEidGenerator>(), |
| 51 bluetooth_throttler) {} | 49 bluetooth_throttler) {} |
| 52 | 50 |
| 53 BluetoothLowEnergyConnectionFinder::BluetoothLowEnergyConnectionFinder( | 51 BluetoothLowEnergyConnectionFinder::BluetoothLowEnergyConnectionFinder( |
| 54 const cryptauth::RemoteDevice remote_device, | 52 const cryptauth::RemoteDevice remote_device, |
| 55 const std::string& service_uuid, | 53 const std::string& service_uuid, |
| 56 const std::vector<cryptauth::BeaconSeed>& beacon_seeds, | |
| 57 std::unique_ptr<cryptauth::BackgroundEidGenerator> eid_generator, | 54 std::unique_ptr<cryptauth::BackgroundEidGenerator> eid_generator, |
| 58 cryptauth::BluetoothThrottler* bluetooth_throttler) | 55 cryptauth::BluetoothThrottler* bluetooth_throttler) |
| 59 : remote_device_(remote_device), | 56 : remote_device_(remote_device), |
| 60 service_uuid_(service_uuid), | 57 service_uuid_(service_uuid), |
| 61 beacon_seeds_(beacon_seeds), | |
| 62 eid_generator_(std::move(eid_generator)), | 58 eid_generator_(std::move(eid_generator)), |
| 63 bluetooth_throttler_(bluetooth_throttler), | 59 bluetooth_throttler_(bluetooth_throttler), |
| 64 weak_ptr_factory_(this) {} | 60 weak_ptr_factory_(this) {} |
| 65 | 61 |
| 66 BluetoothLowEnergyConnectionFinder::~BluetoothLowEnergyConnectionFinder() { | 62 BluetoothLowEnergyConnectionFinder::~BluetoothLowEnergyConnectionFinder() { |
| 67 if (discovery_session_) { | 63 if (discovery_session_) { |
| 68 StopDiscoverySession(); | 64 StopDiscoverySession(); |
| 69 } | 65 } |
| 70 | 66 |
| 71 if (connection_) { | 67 if (connection_) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 BluetoothDevice* device) { | 157 BluetoothDevice* device) { |
| 162 if (!device) | 158 if (!device) |
| 163 return false; | 159 return false; |
| 164 | 160 |
| 165 device::BluetoothUUID advertisement_uuid(kAdvertisementUUID); | 161 device::BluetoothUUID advertisement_uuid(kAdvertisementUUID); |
| 166 const std::vector<uint8_t>* service_data = | 162 const std::vector<uint8_t>* service_data = |
| 167 device->GetServiceDataForUUID(advertisement_uuid); | 163 device->GetServiceDataForUUID(advertisement_uuid); |
| 168 if (!service_data) | 164 if (!service_data) |
| 169 return false; | 165 return false; |
| 170 | 166 |
| 167 PA_LOG(INFO) << "Generating EIDs for: " << device->GetAddress(); |
| 171 std::string service_data_string(service_data->begin(), service_data->end()); | 168 std::string service_data_string(service_data->begin(), service_data->end()); |
| 172 std::vector<cryptauth::DataWithTimestamp> nearest_eids = | 169 std::vector<cryptauth::DataWithTimestamp> nearest_eids = |
| 173 eid_generator_->GenerateNearestEids(beacon_seeds_); | 170 eid_generator_->GenerateNearestEids(remote_device_.beacon_seeds); |
| 174 for (const cryptauth::DataWithTimestamp& eid : nearest_eids) { | 171 for (const cryptauth::DataWithTimestamp& eid : nearest_eids) { |
| 175 if (eid.data == service_data_string) { | 172 if (eid.data == service_data_string) { |
| 176 PA_LOG(INFO) << "Found a matching EID: " << eid.DataInHex(); | 173 PA_LOG(INFO) << "Found a matching EID: " << eid.DataInHex(); |
| 177 return true; | 174 return true; |
| 178 } | 175 } |
| 179 } | 176 } |
| 180 return false; | 177 return false; |
| 181 } | 178 } |
| 182 | 179 |
| 183 void BluetoothLowEnergyConnectionFinder::OnAdapterInitialized( | 180 void BluetoothLowEnergyConnectionFinder::OnAdapterInitialized( |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 connection_.reset(); | 272 connection_.reset(); |
| 276 if (!discovery_session_ || !discovery_session_->IsActive()) | 273 if (!discovery_session_ || !discovery_session_->IsActive()) |
| 277 StartDiscoverySession(); | 274 StartDiscoverySession(); |
| 278 } | 275 } |
| 279 | 276 |
| 280 void BluetoothLowEnergyConnectionFinder::InvokeCallbackAsync() { | 277 void BluetoothLowEnergyConnectionFinder::InvokeCallbackAsync() { |
| 281 connection_callback_.Run(std::move(connection_)); | 278 connection_callback_.Run(std::move(connection_)); |
| 282 } | 279 } |
| 283 | 280 |
| 284 } // namespace proximity_auth | 281 } // namespace proximity_auth |
| OLD | NEW |