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> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 SetStatus(IN_PROGRESS); | 158 SetStatus(IN_PROGRESS); |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 void BluetoothLowEnergyConnection::SetTaskRunnerForTesting( | 162 void BluetoothLowEnergyConnection::SetTaskRunnerForTesting( |
163 scoped_refptr<base::TaskRunner> task_runner) { | 163 scoped_refptr<base::TaskRunner> task_runner) { |
164 task_runner_ = task_runner; | 164 task_runner_ = task_runner; |
165 } | 165 } |
166 | 166 |
167 void BluetoothLowEnergyConnection::SendMessageImpl( | 167 void BluetoothLowEnergyConnection::SendMessageImpl( |
168 scoped_ptr<WireMessage> message) { | 168 std::unique_ptr<WireMessage> message) { |
169 PA_LOG(INFO) << "Sending message " << message->Serialize(); | 169 PA_LOG(INFO) << "Sending message " << message->Serialize(); |
170 std::string serialized_msg = message->Serialize(); | 170 std::string serialized_msg = message->Serialize(); |
171 | 171 |
172 // [First write]: Build a header with the [send signal] + [size of the | 172 // [First write]: Build a header with the [send signal] + [size of the |
173 // message]. | 173 // message]. |
174 WriteRequest write_request = BuildWriteRequest( | 174 WriteRequest write_request = BuildWriteRequest( |
175 ToByteVector(static_cast<uint32_t>(ControlSignal::kSendSignal)), | 175 ToByteVector(static_cast<uint32_t>(ControlSignal::kSendSignal)), |
176 ToByteVector(static_cast<uint32_t>(serialized_msg.size())), false); | 176 ToByteVector(static_cast<uint32_t>(serialized_msg.size())), false); |
177 | 177 |
178 // [First write]: Fill the it with a prefix of |serialized_msg| up to | 178 // [First write]: Fill the it with a prefix of |serialized_msg| up to |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 void BluetoothLowEnergyConnection::OnCreateGattConnectionError( | 332 void BluetoothLowEnergyConnection::OnCreateGattConnectionError( |
333 device::BluetoothDevice::ConnectErrorCode error_code) { | 333 device::BluetoothDevice::ConnectErrorCode error_code) { |
334 DCHECK(sub_status_ == SubStatus::WAITING_GATT_CONNECTION); | 334 DCHECK(sub_status_ == SubStatus::WAITING_GATT_CONNECTION); |
335 PA_LOG(WARNING) << "Error creating GATT connection to " | 335 PA_LOG(WARNING) << "Error creating GATT connection to " |
336 << remote_device().bluetooth_address | 336 << remote_device().bluetooth_address |
337 << "error code: " << error_code; | 337 << "error code: " << error_code; |
338 Disconnect(); | 338 Disconnect(); |
339 } | 339 } |
340 | 340 |
341 void BluetoothLowEnergyConnection::OnGattConnectionCreated( | 341 void BluetoothLowEnergyConnection::OnGattConnectionCreated( |
342 scoped_ptr<device::BluetoothGattConnection> gatt_connection) { | 342 std::unique_ptr<device::BluetoothGattConnection> gatt_connection) { |
343 DCHECK(sub_status() == SubStatus::WAITING_GATT_CONNECTION); | 343 DCHECK(sub_status() == SubStatus::WAITING_GATT_CONNECTION); |
344 PA_LOG(INFO) << "GATT connection with " << gatt_connection->GetDeviceAddress() | 344 PA_LOG(INFO) << "GATT connection with " << gatt_connection->GetDeviceAddress() |
345 << " created."; | 345 << " created."; |
346 PrintTimeElapsed(); | 346 PrintTimeElapsed(); |
347 | 347 |
348 // Informing |bluetooth_trottler_| a new connection was established. | 348 // Informing |bluetooth_trottler_| a new connection was established. |
349 bluetooth_throttler_->OnConnection(this); | 349 bluetooth_throttler_->OnConnection(this); |
350 | 350 |
351 gatt_connection_ = std::move(gatt_connection); | 351 gatt_connection_ = std::move(gatt_connection); |
352 SetSubStatus(SubStatus::WAITING_CHARACTERISTICS); | 352 SetSubStatus(SubStatus::WAITING_CHARACTERISTICS); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 } | 427 } |
428 | 428 |
429 void BluetoothLowEnergyConnection::OnNotifySessionError( | 429 void BluetoothLowEnergyConnection::OnNotifySessionError( |
430 BluetoothGattService::GattErrorCode error) { | 430 BluetoothGattService::GattErrorCode error) { |
431 DCHECK(sub_status() == SubStatus::WAITING_NOTIFY_SESSION); | 431 DCHECK(sub_status() == SubStatus::WAITING_NOTIFY_SESSION); |
432 PA_LOG(WARNING) << "Error starting notification session: " << error; | 432 PA_LOG(WARNING) << "Error starting notification session: " << error; |
433 Disconnect(); | 433 Disconnect(); |
434 } | 434 } |
435 | 435 |
436 void BluetoothLowEnergyConnection::OnNotifySessionStarted( | 436 void BluetoothLowEnergyConnection::OnNotifySessionStarted( |
437 scoped_ptr<BluetoothGattNotifySession> notify_session) { | 437 std::unique_ptr<BluetoothGattNotifySession> notify_session) { |
438 DCHECK(sub_status() == SubStatus::WAITING_NOTIFY_SESSION); | 438 DCHECK(sub_status() == SubStatus::WAITING_NOTIFY_SESSION); |
439 PA_LOG(INFO) << "Notification session started " | 439 PA_LOG(INFO) << "Notification session started " |
440 << notify_session->GetCharacteristicIdentifier(); | 440 << notify_session->GetCharacteristicIdentifier(); |
441 PrintTimeElapsed(); | 441 PrintTimeElapsed(); |
442 | 442 |
443 SetSubStatus(SubStatus::NOTIFY_SESSION_READY); | 443 SetSubStatus(SubStatus::NOTIFY_SESSION_READY); |
444 notify_session_ = std::move(notify_session); | 444 notify_session_ = std::move(notify_session); |
445 | 445 |
446 SendInviteToConnectSignal(); | 446 SendInviteToConnectSignal(); |
447 } | 447 } |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 const uint32_t value) { | 609 const uint32_t value) { |
610 std::vector<uint8_t> bytes(4, 0); | 610 std::vector<uint8_t> bytes(4, 0); |
611 bytes[0] = static_cast<uint8_t>(value); | 611 bytes[0] = static_cast<uint8_t>(value); |
612 bytes[1] = static_cast<uint8_t>(value >> 8); | 612 bytes[1] = static_cast<uint8_t>(value >> 8); |
613 bytes[2] = static_cast<uint8_t>(value >> 16); | 613 bytes[2] = static_cast<uint8_t>(value >> 16); |
614 bytes[3] = static_cast<uint8_t>(value >> 24); | 614 bytes[3] = static_cast<uint8_t>(value >> 24); |
615 return bytes; | 615 return bytes; |
616 } | 616 } |
617 | 617 |
618 } // namespace proximity_auth | 618 } // namespace proximity_auth |
OLD | NEW |