| 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 "components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.
h" | 8 #include "components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.
h" |
| 9 #include "components/cryptauth/cryptauth_service.h" |
| 9 #include "components/proximity_auth/logging/logging.h" | 10 #include "components/proximity_auth/logging/logging.h" |
| 10 #include "device/bluetooth/bluetooth_uuid.h" | 11 #include "device/bluetooth/bluetooth_uuid.h" |
| 11 | 12 |
| 12 namespace chromeos { | 13 namespace chromeos { |
| 13 | 14 |
| 14 namespace tether { | 15 namespace tether { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 const char kTetherFeature[] = "magic_tether"; | 18 const char kTetherFeature[] = "magic_tether"; |
| 18 } // namespace | 19 } // namespace |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } | 159 } |
| 159 | 160 |
| 160 manager_->SendMessageReceivedEvent(remote_device_, payload); | 161 manager_->SendMessageReceivedEvent(remote_device_, payload); |
| 161 } | 162 } |
| 162 | 163 |
| 163 std::unique_ptr<base::Timer> BleConnectionManager::TimerFactory::CreateTimer() { | 164 std::unique_ptr<base::Timer> BleConnectionManager::TimerFactory::CreateTimer() { |
| 164 return base::MakeUnique<base::OneShotTimer>(); | 165 return base::MakeUnique<base::OneShotTimer>(); |
| 165 } | 166 } |
| 166 | 167 |
| 167 BleConnectionManager::BleConnectionManager( | 168 BleConnectionManager::BleConnectionManager( |
| 168 std::unique_ptr<Delegate> delegate, | 169 cryptauth::CryptAuthService* cryptauth_service, |
| 169 scoped_refptr<device::BluetoothAdapter> adapter, | 170 scoped_refptr<device::BluetoothAdapter> adapter, |
| 170 const LocalDeviceDataProvider* local_device_data_provider, | 171 const LocalDeviceDataProvider* local_device_data_provider, |
| 171 const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher, | 172 const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher, |
| 172 cryptauth::BluetoothThrottler* bluetooth_throttler) | 173 cryptauth::BluetoothThrottler* bluetooth_throttler) |
| 173 : BleConnectionManager( | 174 : BleConnectionManager( |
| 174 std::move(delegate), | 175 cryptauth_service, |
| 175 adapter, | 176 adapter, |
| 176 // TODO(khorimoto): Inject |adapter| into |BleScanner|. | 177 // TODO(khorimoto): Inject |adapter| into |BleScanner|. |
| 177 base::MakeUnique<BleScanner>(local_device_data_provider), | 178 base::MakeUnique<BleScanner>(local_device_data_provider), |
| 178 base::MakeUnique<BleAdvertiser>(adapter, | 179 base::MakeUnique<BleAdvertiser>(adapter, |
| 179 local_device_data_provider, | 180 local_device_data_provider, |
| 180 remote_beacon_seed_fetcher), | 181 remote_beacon_seed_fetcher), |
| 181 base::MakeUnique<BleAdvertisementDeviceQueue>(), | 182 base::MakeUnique<BleAdvertisementDeviceQueue>(), |
| 182 base::WrapUnique<TimerFactory>(new TimerFactory()), | 183 base::WrapUnique<TimerFactory>(new TimerFactory()), |
| 183 bluetooth_throttler) {} | 184 bluetooth_throttler) {} |
| 184 | 185 |
| 185 BleConnectionManager::BleConnectionManager( | 186 BleConnectionManager::BleConnectionManager( |
| 186 std::unique_ptr<Delegate> delegate, | 187 cryptauth::CryptAuthService* cryptauth_service, |
| 187 scoped_refptr<device::BluetoothAdapter> adapter, | 188 scoped_refptr<device::BluetoothAdapter> adapter, |
| 188 std::unique_ptr<BleScanner> ble_scanner, | 189 std::unique_ptr<BleScanner> ble_scanner, |
| 189 std::unique_ptr<BleAdvertiser> ble_advertiser, | 190 std::unique_ptr<BleAdvertiser> ble_advertiser, |
| 190 std::unique_ptr<BleAdvertisementDeviceQueue> device_queue, | 191 std::unique_ptr<BleAdvertisementDeviceQueue> device_queue, |
| 191 std::unique_ptr<TimerFactory> timer_factory, | 192 std::unique_ptr<TimerFactory> timer_factory, |
| 192 cryptauth::BluetoothThrottler* bluetooth_throttler) | 193 cryptauth::BluetoothThrottler* bluetooth_throttler) |
| 193 : delegate_(std::move(delegate)), | 194 : cryptauth_service_(cryptauth_service), |
| 194 adapter_(adapter), | 195 adapter_(adapter), |
| 195 ble_scanner_(std::move(ble_scanner)), | 196 ble_scanner_(std::move(ble_scanner)), |
| 196 ble_advertiser_(std::move(ble_advertiser)), | 197 ble_advertiser_(std::move(ble_advertiser)), |
| 197 device_queue_(std::move(device_queue)), | 198 device_queue_(std::move(device_queue)), |
| 198 timer_factory_(std::move(timer_factory)), | 199 timer_factory_(std::move(timer_factory)), |
| 199 bluetooth_throttler_(bluetooth_throttler), | 200 bluetooth_throttler_(bluetooth_throttler), |
| 200 has_registered_observer_(false), | 201 has_registered_observer_(false), |
| 201 weak_ptr_factory_(this) {} | 202 weak_ptr_factory_(this) {} |
| 202 | 203 |
| 203 BleConnectionManager::~BleConnectionManager() { | 204 BleConnectionManager::~BleConnectionManager() { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 << remote_device.GetTruncatedDeviceIdForLogs() << ". " | 323 << remote_device.GetTruncatedDeviceIdForLogs() << ". " |
| 323 << "Starting authentication handshake to that device."; | 324 << "Starting authentication handshake to that device."; |
| 324 | 325 |
| 325 // Create a connection to that device. | 326 // Create a connection to that device. |
| 326 std::unique_ptr<cryptauth::Connection> connection = | 327 std::unique_ptr<cryptauth::Connection> connection = |
| 327 cryptauth::weave::BluetoothLowEnergyWeaveClientConnection::Factory:: | 328 cryptauth::weave::BluetoothLowEnergyWeaveClientConnection::Factory:: |
| 328 NewInstance(remote_device, device_address, adapter_, | 329 NewInstance(remote_device, device_address, adapter_, |
| 329 device::BluetoothUUID(std::string(kGattServerUuid)), | 330 device::BluetoothUUID(std::string(kGattServerUuid)), |
| 330 bluetooth_throttler_); | 331 bluetooth_throttler_); |
| 331 std::unique_ptr<cryptauth::SecureChannel> secure_channel = | 332 std::unique_ptr<cryptauth::SecureChannel> secure_channel = |
| 332 cryptauth::SecureChannel::Factory::NewInstance( | 333 cryptauth::SecureChannel::Factory::NewInstance(std::move(connection), |
| 333 std::move(connection), delegate_->CreateSecureChannelDelegate()); | 334 cryptauth_service_); |
| 334 connection_metadata->SetSecureChannel(std::move(secure_channel)); | 335 connection_metadata->SetSecureChannel(std::move(secure_channel)); |
| 335 | 336 |
| 336 // Stop trying to connect to that device, since a connection already exists. | 337 // Stop trying to connect to that device, since a connection already exists. |
| 337 StopConnectionAttemptAndMoveToEndOfQueue(remote_device); | 338 StopConnectionAttemptAndMoveToEndOfQueue(remote_device); |
| 338 UpdateConnectionAttempts(); | 339 UpdateConnectionAttempts(); |
| 339 } | 340 } |
| 340 | 341 |
| 341 std::shared_ptr<BleConnectionManager::ConnectionMetadata> | 342 std::shared_ptr<BleConnectionManager::ConnectionMetadata> |
| 342 BleConnectionManager::GetConnectionMetadata( | 343 BleConnectionManager::GetConnectionMetadata( |
| 343 const cryptauth::RemoteDevice& remote_device) const { | 344 const cryptauth::RemoteDevice& remote_device) const { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 << cryptauth::SecureChannel::StatusToString(new_status); | 490 << cryptauth::SecureChannel::StatusToString(new_status); |
| 490 for (auto& observer : observer_list_) { | 491 for (auto& observer : observer_list_) { |
| 491 observer.OnSecureChannelStatusChanged(remote_device, old_status, | 492 observer.OnSecureChannelStatusChanged(remote_device, old_status, |
| 492 new_status); | 493 new_status); |
| 493 } | 494 } |
| 494 } | 495 } |
| 495 | 496 |
| 496 } // namespace tether | 497 } // namespace tether |
| 497 | 498 |
| 498 } // namespace chromeos | 499 } // namespace chromeos |
| OLD | NEW |