| 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 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 std::vector<uint8> value(signal.begin(), signal.end()); | 543 std::vector<uint8> value(signal.begin(), signal.end()); |
| 544 value.insert(value.end(), bytes.begin(), bytes.end()); | 544 value.insert(value.end(), bytes.begin(), bytes.end()); |
| 545 return WriteRequest(value, is_last_write_for_wire_message); | 545 return WriteRequest(value, is_last_write_for_wire_message); |
| 546 } | 546 } |
| 547 | 547 |
| 548 void BluetoothLowEnergyConnection::ClearWriteRequestsQueue() { | 548 void BluetoothLowEnergyConnection::ClearWriteRequestsQueue() { |
| 549 while (!write_requests_queue_.empty()) | 549 while (!write_requests_queue_.empty()) |
| 550 write_requests_queue_.pop(); | 550 write_requests_queue_.pop(); |
| 551 } | 551 } |
| 552 | 552 |
| 553 const std::string& BluetoothLowEnergyConnection::GetRemoteDeviceAddress() { | 553 std::string BluetoothLowEnergyConnection::GetRemoteDeviceAddress() { |
| 554 return remote_device().bluetooth_address; | 554 // When the remote device is connected we should rely on the address given by |
| 555 // |gatt_connection_|. As the device address may change if the device is |
| 556 // paired. The address in |gatt_connection_| is automatically updated in this |
| 557 // case. |
| 558 return gatt_connection_ ? gatt_connection_->GetDeviceAddress() |
| 559 : remote_device().bluetooth_address; |
| 555 } | 560 } |
| 556 | 561 |
| 557 BluetoothDevice* BluetoothLowEnergyConnection::GetRemoteDevice() { | 562 BluetoothDevice* BluetoothLowEnergyConnection::GetRemoteDevice() { |
| 558 // It's not possible to simply use | 563 // It's not possible to simply use |
| 559 // |adapter_->GetDevice(GetRemoteDeviceAddress())| to find the device with MAC | 564 // |adapter_->GetDevice(GetRemoteDeviceAddress())| to find the device with MAC |
| 560 // address |GetRemoteDeviceAddress()|. For paired devices, | 565 // address |GetRemoteDeviceAddress()|. For paired devices, |
| 561 // BluetoothAdapter::GetDevice(XXX) searches for the temporary MAC address | 566 // BluetoothAdapter::GetDevice(XXX) searches for the temporary MAC address |
| 562 // XXX, whereas |GetRemoteDeviceAddress()| is the real MAC address. This is a | 567 // XXX, whereas |GetRemoteDeviceAddress()| is the real MAC address. This is a |
| 563 // bug in the way device::BluetoothAdapter is storing the devices (see | 568 // bug in the way device::BluetoothAdapter is storing the devices (see |
| 564 // crbug.com/497841). | 569 // crbug.com/497841). |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 const uint32 value) { | 617 const uint32 value) { |
| 613 std::vector<uint8> bytes(4, 0); | 618 std::vector<uint8> bytes(4, 0); |
| 614 bytes[0] = static_cast<uint8>(value); | 619 bytes[0] = static_cast<uint8>(value); |
| 615 bytes[1] = static_cast<uint8>(value >> 8); | 620 bytes[1] = static_cast<uint8>(value >> 8); |
| 616 bytes[2] = static_cast<uint8>(value >> 16); | 621 bytes[2] = static_cast<uint8>(value >> 16); |
| 617 bytes[3] = static_cast<uint8>(value >> 24); | 622 bytes[3] = static_cast<uint8>(value >> 24); |
| 618 return bytes; | 623 return bytes; |
| 619 } | 624 } |
| 620 | 625 |
| 621 } // namespace proximity_auth | 626 } // namespace proximity_auth |
| OLD | NEW |