Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1814)

Unified Diff: device/bluetooth/bluez/bluetooth_device_bluez.cc

Issue 1941923002: bluetooth: Return int8_t and use -128 for unknown tx power. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Fix extensions tests Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluez/bluetooth_device_bluez.cc
diff --git a/device/bluetooth/bluez/bluetooth_device_bluez.cc b/device/bluetooth/bluez/bluetooth_device_bluez.cc
index 73e54871143c0599a4789e551dcd622dbde82343..d7ceecdb0eeecdae0e34ff687592b0219c80a597 100644
--- a/device/bluetooth/bluez/bluetooth_device_bluez.cc
+++ b/device/bluetooth/bluez/bluetooth_device_bluez.cc
@@ -11,6 +11,7 @@
#include "base/bind.h"
#include "base/metrics/histogram.h"
+#include "base/optional.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "dbus/bus.h"
@@ -137,6 +138,11 @@ BluetoothDevice::ConnectErrorCode DBusErrorToConnectError(
return error_code;
}
+base::Optional<int8_t> EnsureValidPower(int16_t power) {
+ return ((power < INT8_MIN) || (power > INT8_MAX)) ? base::Optional<int8_t>()
+ : power;
+}
+
} // namespace
namespace bluez {
@@ -316,28 +322,28 @@ BluetoothDeviceBlueZ::UUIDList BluetoothDeviceBlueZ::GetUUIDs() const {
return uuids;
}
-int16_t BluetoothDeviceBlueZ::GetInquiryRSSI() const {
+base::Optional<int8_t> BluetoothDeviceBlueZ::GetInquiryRSSI() const {
bluez::BluetoothDeviceClient::Properties* properties =
bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
object_path_);
DCHECK(properties);
if (!properties->rssi.is_valid())
- return kUnknownPower;
+ return base::Optional<int8_t>();
- return properties->rssi.value();
+ return EnsureValidPower(properties->rssi.value());
}
-int16_t BluetoothDeviceBlueZ::GetInquiryTxPower() const {
+base::Optional<int8_t> BluetoothDeviceBlueZ::GetInquiryTxPower() const {
bluez::BluetoothDeviceClient::Properties* properties =
bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
object_path_);
DCHECK(properties);
if (!properties->tx_power.is_valid())
- return kUnknownPower;
+ return base::Optional<int8_t>();
- return properties->tx_power.value();
+ return EnsureValidPower(properties->tx_power.value());
}
bool BluetoothDeviceBlueZ::ExpectingPinCode() const {
@@ -594,11 +600,20 @@ void BluetoothDeviceBlueZ::GattServiceRemoved(
adapter()->NotifyGattServiceRemoved(service);
}
-void BluetoothDeviceBlueZ::OnGetConnInfo(const ConnectionInfoCallback& callback,
- int16_t rssi,
- int16_t transmit_power,
- int16_t max_transmit_power) {
- callback.Run(ConnectionInfo(rssi, transmit_power, max_transmit_power));
+void BluetoothDeviceBlueZ::OnGetConnInfo(
+ const ConnectionInfoCallback& callback,
+ const base::Optional<int16_t>& rssi,
+ const base::Optional<int16_t>& transmit_power,
+ const base::Optional<int16_t>& max_transmit_power) {
+ if (!rssi) {
+ DCHECK(!transmit_power);
+ DCHECK(!max_transmit_power);
+ callback.Run(ConnectionInfo());
+ }
+
+ callback.Run(ConnectionInfo(EnsureValidPower(rssi.value()),
+ EnsureValidPower(transmit_power.value()),
+ EnsureValidPower(max_transmit_power.value())));
}
void BluetoothDeviceBlueZ::OnGetConnInfoError(

Powered by Google App Engine
This is Rietveld 408576698