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