Commit afce5fbf authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Replace nested min/max calls with base::ClampToRange() in chromeos/.

Bug: 1000055
Change-Id: Ib0243d3de02c933546521c46ac20b97cbec3f88e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1793255
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Alexander Alekseev <alemate@chromium.org>
Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695567}
parent b416cca1
......@@ -12,6 +12,7 @@
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/ranges.h"
#include "base/stl_util.h"
#include "base/sys_byteorder.h"
......@@ -50,7 +51,7 @@ const int kUnknownProximityValue = 127;
void RecordAuthProximityRollingRssi(int rolling_rssi) {
if (rolling_rssi != kUnknownProximityValue)
rolling_rssi = std::min(50, std::max(-100, rolling_rssi));
rolling_rssi = base::ClampToRange(rolling_rssi, -100, 50);
base::UmaHistogramSparse("EasyUnlock.AuthProximity.RollingRssi",
rolling_rssi);
......
......@@ -4,26 +4,12 @@
#include "chromeos/components/tether/device_status_util.h"
#include "base/numerics/ranges.h"
namespace chromeos {
namespace tether {
namespace {
const char kDefaultCellCarrierName[] = "unknown-carrier";
// Android signal strength is measured between 0 and 4 (inclusive), but Chrome
// OS signal strength is measured between 0 and 100 (inclusive). In order to
// convert between Android signal strength to Chrome OS signal strength, the
// value must be multiplied by the below value.
const int32_t kAndroidTetherHostToChromeOSSignalStrengthMultiplier = 25;
int32_t ForceBetweenZeroAndOneHundred(int32_t value) {
return std::min(std::max(value, 0), 100);
}
} // namespace
void NormalizeDeviceStatus(const DeviceStatus& status,
std::string* carrier_out,
int32_t* battery_percentage_out,
......@@ -31,6 +17,7 @@ void NormalizeDeviceStatus(const DeviceStatus& status,
// Use a sentinel value if carrier information is not available. This value is
// special-cased and replaced with a localized string in the settings UI.
if (carrier_out) {
constexpr char kDefaultCellCarrierName[] = "unknown-carrier";
*carrier_out =
(!status.has_cell_provider() || status.cell_provider().empty())
? kDefaultCellCarrierName
......@@ -44,15 +31,19 @@ void NormalizeDeviceStatus(const DeviceStatus& status,
if (battery_percentage_out) {
*battery_percentage_out =
status.has_battery_percentage()
? ForceBetweenZeroAndOneHundred(status.battery_percentage())
? base::ClampToRange(status.battery_percentage(), 0, 100)
: 100;
}
if (signal_strength_out) {
// Android signal strength is measured between 0 and 4 (inclusive), but
// Chrome OS signal strength is measured between 0 and 100 (inclusive). In
// order to convert between Android signal strength to Chrome OS signal
// strength, the value must be multiplied by the below value.
constexpr int32_t kConversionFactor = 100 / 4;
*signal_strength_out =
status.has_connection_strength()
? ForceBetweenZeroAndOneHundred(
kAndroidTetherHostToChromeOSSignalStrengthMultiplier *
status.connection_strength())
? base::ClampToRange(
kConversionFactor * status.connection_strength(), 0, 100)
: 100;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment