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.h" | 5 #include "components/proximity_auth/ble/bluetooth_low_energy_connection.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/location.h" | 10 #include "base/location.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
11 #include "base/task_runner.h" | 13 #include "base/task_runner.h" |
12 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
13 #include "base/time/time.h" | 15 #include "base/time/time.h" |
14 #include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_fin
der.h" | 16 #include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_fin
der.h" |
15 #include "components/proximity_auth/ble/fake_wire_message.h" | 17 #include "components/proximity_auth/ble/fake_wire_message.h" |
16 #include "components/proximity_auth/bluetooth_throttler.h" | 18 #include "components/proximity_auth/bluetooth_throttler.h" |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 void BluetoothLowEnergyConnection::OnGattConnectionCreated( | 338 void BluetoothLowEnergyConnection::OnGattConnectionCreated( |
337 scoped_ptr<device::BluetoothGattConnection> gatt_connection) { | 339 scoped_ptr<device::BluetoothGattConnection> gatt_connection) { |
338 DCHECK(sub_status() == SubStatus::WAITING_GATT_CONNECTION); | 340 DCHECK(sub_status() == SubStatus::WAITING_GATT_CONNECTION); |
339 PA_LOG(INFO) << "GATT connection with " << gatt_connection->GetDeviceAddress() | 341 PA_LOG(INFO) << "GATT connection with " << gatt_connection->GetDeviceAddress() |
340 << " created."; | 342 << " created."; |
341 PrintTimeElapsed(); | 343 PrintTimeElapsed(); |
342 | 344 |
343 // Informing |bluetooth_trottler_| a new connection was established. | 345 // Informing |bluetooth_trottler_| a new connection was established. |
344 bluetooth_throttler_->OnConnection(this); | 346 bluetooth_throttler_->OnConnection(this); |
345 | 347 |
346 gatt_connection_ = gatt_connection.Pass(); | 348 gatt_connection_ = std::move(gatt_connection); |
347 SetSubStatus(SubStatus::WAITING_CHARACTERISTICS); | 349 SetSubStatus(SubStatus::WAITING_CHARACTERISTICS); |
348 characteristic_finder_.reset(CreateCharacteristicsFinder( | 350 characteristic_finder_.reset(CreateCharacteristicsFinder( |
349 base::Bind(&BluetoothLowEnergyConnection::OnCharacteristicsFound, | 351 base::Bind(&BluetoothLowEnergyConnection::OnCharacteristicsFound, |
350 weak_ptr_factory_.GetWeakPtr()), | 352 weak_ptr_factory_.GetWeakPtr()), |
351 base::Bind(&BluetoothLowEnergyConnection::OnCharacteristicsFinderError, | 353 base::Bind(&BluetoothLowEnergyConnection::OnCharacteristicsFinderError, |
352 weak_ptr_factory_.GetWeakPtr()))); | 354 weak_ptr_factory_.GetWeakPtr()))); |
353 } | 355 } |
354 | 356 |
355 BluetoothLowEnergyCharacteristicsFinder* | 357 BluetoothLowEnergyCharacteristicsFinder* |
356 BluetoothLowEnergyConnection::CreateCharacteristicsFinder( | 358 BluetoothLowEnergyConnection::CreateCharacteristicsFinder( |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 } | 431 } |
430 | 432 |
431 void BluetoothLowEnergyConnection::OnNotifySessionStarted( | 433 void BluetoothLowEnergyConnection::OnNotifySessionStarted( |
432 scoped_ptr<BluetoothGattNotifySession> notify_session) { | 434 scoped_ptr<BluetoothGattNotifySession> notify_session) { |
433 DCHECK(sub_status() == SubStatus::WAITING_NOTIFY_SESSION); | 435 DCHECK(sub_status() == SubStatus::WAITING_NOTIFY_SESSION); |
434 PA_LOG(INFO) << "Notification session started " | 436 PA_LOG(INFO) << "Notification session started " |
435 << notify_session->GetCharacteristicIdentifier(); | 437 << notify_session->GetCharacteristicIdentifier(); |
436 PrintTimeElapsed(); | 438 PrintTimeElapsed(); |
437 | 439 |
438 SetSubStatus(SubStatus::NOTIFY_SESSION_READY); | 440 SetSubStatus(SubStatus::NOTIFY_SESSION_READY); |
439 notify_session_ = notify_session.Pass(); | 441 notify_session_ = std::move(notify_session); |
440 | 442 |
441 SendInviteToConnectSignal(); | 443 SendInviteToConnectSignal(); |
442 } | 444 } |
443 | 445 |
444 void BluetoothLowEnergyConnection::StopNotifySession() { | 446 void BluetoothLowEnergyConnection::StopNotifySession() { |
445 if (notify_session_) { | 447 if (notify_session_) { |
446 notify_session_->Stop(base::Bind(&base::DoNothing)); | 448 notify_session_->Stop(base::Bind(&base::DoNothing)); |
447 notify_session_.reset(); | 449 notify_session_.reset(); |
448 } | 450 } |
449 } | 451 } |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 const uint32_t value) { | 606 const uint32_t value) { |
605 std::vector<uint8_t> bytes(4, 0); | 607 std::vector<uint8_t> bytes(4, 0); |
606 bytes[0] = static_cast<uint8_t>(value); | 608 bytes[0] = static_cast<uint8_t>(value); |
607 bytes[1] = static_cast<uint8_t>(value >> 8); | 609 bytes[1] = static_cast<uint8_t>(value >> 8); |
608 bytes[2] = static_cast<uint8_t>(value >> 16); | 610 bytes[2] = static_cast<uint8_t>(value >> 16); |
609 bytes[3] = static_cast<uint8_t>(value >> 24); | 611 bytes[3] = static_cast<uint8_t>(value >> 24); |
610 return bytes; | 612 return bytes; |
611 } | 613 } |
612 | 614 |
613 } // namespace proximity_auth | 615 } // namespace proximity_auth |
OLD | NEW |