OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chromeos/components/tether/ble_connection_manager.h" | 5 #include "chromeos/components/tether/ble_connection_manager.h" |
6 | 6 |
7 #include "chromeos/components/tether/ble_constants.h" | 7 #include "chromeos/components/tether/ble_constants.h" |
| 8 #include "chromeos/components/tether/timer_factory.h" |
8 #include "components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.
h" | 9 #include "components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.
h" |
9 #include "components/cryptauth/cryptauth_service.h" | 10 #include "components/cryptauth/cryptauth_service.h" |
10 #include "components/proximity_auth/logging/logging.h" | 11 #include "components/proximity_auth/logging/logging.h" |
11 #include "device/bluetooth/bluetooth_uuid.h" | 12 #include "device/bluetooth/bluetooth_uuid.h" |
12 | 13 |
13 namespace chromeos { | 14 namespace chromeos { |
14 | 15 |
15 namespace tether { | 16 namespace tether { |
16 | 17 |
17 namespace { | 18 namespace { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 const std::string& payload) { | 159 const std::string& payload) { |
159 DCHECK(secure_channel_.get() == secure_channel); | 160 DCHECK(secure_channel_.get() == secure_channel); |
160 if (feature != std::string(kTetherFeature)) { | 161 if (feature != std::string(kTetherFeature)) { |
161 // If the message received was not a tether feature, ignore it. | 162 // If the message received was not a tether feature, ignore it. |
162 return; | 163 return; |
163 } | 164 } |
164 | 165 |
165 manager_->SendMessageReceivedEvent(remote_device_, payload); | 166 manager_->SendMessageReceivedEvent(remote_device_, payload); |
166 } | 167 } |
167 | 168 |
168 std::unique_ptr<base::Timer> BleConnectionManager::TimerFactory::CreateTimer() { | |
169 return base::MakeUnique<base::OneShotTimer>(); | |
170 } | |
171 | |
172 BleConnectionManager::BleConnectionManager( | 169 BleConnectionManager::BleConnectionManager( |
173 cryptauth::CryptAuthService* cryptauth_service, | 170 cryptauth::CryptAuthService* cryptauth_service, |
174 scoped_refptr<device::BluetoothAdapter> adapter, | 171 scoped_refptr<device::BluetoothAdapter> adapter, |
175 const LocalDeviceDataProvider* local_device_data_provider, | 172 const LocalDeviceDataProvider* local_device_data_provider, |
176 const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher, | 173 const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher, |
177 cryptauth::BluetoothThrottler* bluetooth_throttler) | 174 cryptauth::BluetoothThrottler* bluetooth_throttler) |
178 : BleConnectionManager( | 175 : BleConnectionManager( |
179 cryptauth_service, | 176 cryptauth_service, |
180 adapter, | 177 adapter, |
181 base::MakeUnique<BleScanner>(adapter, local_device_data_provider), | 178 base::MakeUnique<BleScanner>(adapter, local_device_data_provider), |
182 base::MakeUnique<BleAdvertiser>(adapter, | 179 base::MakeUnique<BleAdvertiser>(adapter, |
183 local_device_data_provider, | 180 local_device_data_provider, |
184 remote_beacon_seed_fetcher), | 181 remote_beacon_seed_fetcher), |
185 base::MakeUnique<BleAdvertisementDeviceQueue>(), | 182 base::MakeUnique<BleAdvertisementDeviceQueue>(), |
186 base::WrapUnique<TimerFactory>(new TimerFactory()), | 183 base::MakeUnique<TimerFactory>(), |
187 bluetooth_throttler) {} | 184 bluetooth_throttler) {} |
188 | 185 |
189 BleConnectionManager::BleConnectionManager( | 186 BleConnectionManager::BleConnectionManager( |
190 cryptauth::CryptAuthService* cryptauth_service, | 187 cryptauth::CryptAuthService* cryptauth_service, |
191 scoped_refptr<device::BluetoothAdapter> adapter, | 188 scoped_refptr<device::BluetoothAdapter> adapter, |
192 std::unique_ptr<BleScanner> ble_scanner, | 189 std::unique_ptr<BleScanner> ble_scanner, |
193 std::unique_ptr<BleAdvertiser> ble_advertiser, | 190 std::unique_ptr<BleAdvertiser> ble_advertiser, |
194 std::unique_ptr<BleAdvertisementDeviceQueue> device_queue, | 191 std::unique_ptr<BleAdvertisementDeviceQueue> device_queue, |
195 std::unique_ptr<TimerFactory> timer_factory, | 192 std::unique_ptr<TimerFactory> timer_factory, |
196 cryptauth::BluetoothThrottler* bluetooth_throttler) | 193 cryptauth::BluetoothThrottler* bluetooth_throttler) |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 | 362 |
366 std::shared_ptr<BleConnectionManager::ConnectionMetadata> | 363 std::shared_ptr<BleConnectionManager::ConnectionMetadata> |
367 BleConnectionManager::AddMetadataForDevice( | 364 BleConnectionManager::AddMetadataForDevice( |
368 const cryptauth::RemoteDevice& remote_device) { | 365 const cryptauth::RemoteDevice& remote_device) { |
369 std::shared_ptr<ConnectionMetadata> existing_data = | 366 std::shared_ptr<ConnectionMetadata> existing_data = |
370 GetConnectionMetadata(remote_device); | 367 GetConnectionMetadata(remote_device); |
371 if (existing_data) { | 368 if (existing_data) { |
372 return existing_data; | 369 return existing_data; |
373 } | 370 } |
374 | 371 |
375 std::unique_ptr<base::Timer> timer = timer_factory_->CreateTimer(); | 372 std::unique_ptr<base::Timer> timer = timer_factory_->CreateOneShotTimer(); |
376 device_to_metadata_map_.insert( | 373 device_to_metadata_map_.insert( |
377 std::pair<cryptauth::RemoteDevice, std::shared_ptr<ConnectionMetadata>>( | 374 std::pair<cryptauth::RemoteDevice, std::shared_ptr<ConnectionMetadata>>( |
378 remote_device, | 375 remote_device, |
379 std::shared_ptr<ConnectionMetadata>( | 376 std::shared_ptr<ConnectionMetadata>( |
380 new ConnectionMetadata(remote_device, std::move(timer), | 377 new ConnectionMetadata(remote_device, std::move(timer), |
381 weak_ptr_factory_.GetWeakPtr())))); | 378 weak_ptr_factory_.GetWeakPtr())))); |
382 return device_to_metadata_map_.at(remote_device); | 379 return device_to_metadata_map_.at(remote_device); |
383 } | 380 } |
384 | 381 |
385 void BleConnectionManager::UpdateConnectionAttempts() { | 382 void BleConnectionManager::UpdateConnectionAttempts() { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 << cryptauth::SecureChannel::StatusToString(new_status); | 500 << cryptauth::SecureChannel::StatusToString(new_status); |
504 for (auto& observer : observer_list_) { | 501 for (auto& observer : observer_list_) { |
505 observer.OnSecureChannelStatusChanged(remote_device, old_status, | 502 observer.OnSecureChannelStatusChanged(remote_device, old_status, |
506 new_status); | 503 new_status); |
507 } | 504 } |
508 } | 505 } |
509 | 506 |
510 } // namespace tether | 507 } // namespace tether |
511 | 508 |
512 } // namespace chromeos | 509 } // namespace chromeos |
OLD | NEW |