| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 const std::vector<uint8>& val, | 292 const std::vector<uint8>& val, |
| 293 bool flag) | 293 bool flag) |
| 294 : value(val), | 294 : value(val), |
| 295 is_last_write_for_wire_message(flag), | 295 is_last_write_for_wire_message(flag), |
| 296 number_of_failed_attempts(0) { | 296 number_of_failed_attempts(0) { |
| 297 } | 297 } |
| 298 | 298 |
| 299 BluetoothLowEnergyConnection::WriteRequest::~WriteRequest() { | 299 BluetoothLowEnergyConnection::WriteRequest::~WriteRequest() { |
| 300 } | 300 } |
| 301 | 301 |
| 302 scoped_ptr<WireMessage> BluetoothLowEnergyConnection::DeserializeWireMessage( | |
| 303 bool* is_incomplete_message) { | |
| 304 return FakeWireMessage::Deserialize(received_bytes(), is_incomplete_message); | |
| 305 } | |
| 306 | |
| 307 void BluetoothLowEnergyConnection::CompleteConnection() { | 302 void BluetoothLowEnergyConnection::CompleteConnection() { |
| 308 PA_LOG(INFO) << "Connection completed. Time elapsed: " | 303 PA_LOG(INFO) << "Connection completed. Time elapsed: " |
| 309 << base::TimeTicks::Now() - start_time_; | 304 << base::TimeTicks::Now() - start_time_; |
| 310 SetSubStatus(SubStatus::CONNECTED); | 305 SetSubStatus(SubStatus::CONNECTED); |
| 311 } | 306 } |
| 312 | 307 |
| 313 void BluetoothLowEnergyConnection::OnCreateGattConnectionError( | 308 void BluetoothLowEnergyConnection::OnCreateGattConnectionError( |
| 314 device::BluetoothDevice::ConnectErrorCode error_code) { | 309 device::BluetoothDevice::ConnectErrorCode error_code) { |
| 315 DCHECK(sub_status_ == SubStatus::WAITING_GATT_CONNECTION); | 310 DCHECK(sub_status_ == SubStatus::WAITING_GATT_CONNECTION); |
| 316 PA_LOG(WARNING) << "Error creating GATT connection to " | 311 PA_LOG(WARNING) << "Error creating GATT connection to " |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 weak_ptr_factory_.GetWeakPtr(), | 468 weak_ptr_factory_.GetWeakPtr(), |
| 474 next_request.is_last_write_for_wire_message)); | 469 next_request.is_last_write_for_wire_message)); |
| 475 } | 470 } |
| 476 } | 471 } |
| 477 | 472 |
| 478 void BluetoothLowEnergyConnection::OnRemoteCharacteristicWritten( | 473 void BluetoothLowEnergyConnection::OnRemoteCharacteristicWritten( |
| 479 bool run_did_send_message_callback) { | 474 bool run_did_send_message_callback) { |
| 480 write_remote_characteristic_pending_ = false; | 475 write_remote_characteristic_pending_ = false; |
| 481 // TODO(sacomoto): Actually pass the current message to the observer. | 476 // TODO(sacomoto): Actually pass the current message to the observer. |
| 482 if (run_did_send_message_callback) | 477 if (run_did_send_message_callback) |
| 483 OnDidSendMessage(FakeWireMessage(""), true); | 478 OnDidSendMessage(WireMessage(std::string(), std::string()), true); |
| 484 | 479 |
| 485 // Removes the top of queue (already processed) and process the next request. | 480 // Removes the top of queue (already processed) and process the next request. |
| 486 DCHECK(!write_requests_queue_.empty()); | 481 DCHECK(!write_requests_queue_.empty()); |
| 487 write_requests_queue_.pop(); | 482 write_requests_queue_.pop(); |
| 488 ProcessNextWriteRequest(); | 483 ProcessNextWriteRequest(); |
| 489 } | 484 } |
| 490 | 485 |
| 491 void BluetoothLowEnergyConnection::OnWriteRemoteCharacteristicError( | 486 void BluetoothLowEnergyConnection::OnWriteRemoteCharacteristicError( |
| 492 bool run_did_send_message_callback, | 487 bool run_did_send_message_callback, |
| 493 BluetoothGattService::GattErrorCode error) { | 488 BluetoothGattService::GattErrorCode error) { |
| 494 PA_LOG(WARNING) << "Error " << error << " writing characteristic: " | 489 PA_LOG(WARNING) << "Error " << error << " writing characteristic: " |
| 495 << to_peripheral_char_.uuid.canonical_value(); | 490 << to_peripheral_char_.uuid.canonical_value(); |
| 496 write_remote_characteristic_pending_ = false; | 491 write_remote_characteristic_pending_ = false; |
| 497 // TODO(sacomoto): Actually pass the current message to the observer. | 492 // TODO(sacomoto): Actually pass the current message to the observer. |
| 498 if (run_did_send_message_callback) | 493 if (run_did_send_message_callback) |
| 499 OnDidSendMessage(FakeWireMessage(""), false); | 494 OnDidSendMessage(WireMessage(std::string(), std::string()), false); |
| 500 | 495 |
| 501 // Increases the number of failed attempts and retry. | 496 // Increases the number of failed attempts and retry. |
| 502 DCHECK(!write_requests_queue_.empty()); | 497 DCHECK(!write_requests_queue_.empty()); |
| 503 if (++write_requests_queue_.front().number_of_failed_attempts >= | 498 if (++write_requests_queue_.front().number_of_failed_attempts >= |
| 504 max_number_of_write_attempts_) { | 499 max_number_of_write_attempts_) { |
| 505 Disconnect(); | 500 Disconnect(); |
| 506 return; | 501 return; |
| 507 } | 502 } |
| 508 ProcessNextWriteRequest(); | 503 ProcessNextWriteRequest(); |
| 509 } | 504 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 const uint32 value) { | 580 const uint32 value) { |
| 586 std::vector<uint8> bytes(4, 0); | 581 std::vector<uint8> bytes(4, 0); |
| 587 bytes[0] = static_cast<uint8>(value); | 582 bytes[0] = static_cast<uint8>(value); |
| 588 bytes[1] = static_cast<uint8>(value >> 8); | 583 bytes[1] = static_cast<uint8>(value >> 8); |
| 589 bytes[2] = static_cast<uint8>(value >> 16); | 584 bytes[2] = static_cast<uint8>(value >> 16); |
| 590 bytes[3] = static_cast<uint8>(value >> 24); | 585 bytes[3] = static_cast<uint8>(value >> 24); |
| 591 return bytes; | 586 return bytes; |
| 592 } | 587 } |
| 593 | 588 |
| 594 } // namespace proximity_auth | 589 } // namespace proximity_auth |
| OLD | NEW |