Commit 36d7d61a authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

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

Bug: 1000055
Change-Id: Ie9432692525fe21719b88cf8b06f015785824cc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1793264
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694965}
parent 3e6aa26e
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/numerics/ranges.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
...@@ -80,7 +81,7 @@ float AveragePower(const media::AudioBus& buffer) { ...@@ -80,7 +81,7 @@ float AveragePower(const media::AudioBus& buffer) {
// Update accumulated average results, with clamping for sanity. // Update accumulated average results, with clamping for sanity.
const float average_power = const float average_power =
std::max(0.0f, std::min(1.0f, sum_power / (frames * channels))); base::ClampToRange(sum_power / (frames * channels), 0.0f, 1.0f);
// Convert average power level to dBFS units, and pin it down to zero if it // Convert average power level to dBFS units, and pin it down to zero if it
// is insignificantly small. // is insignificantly small.
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <utility> #include <utility>
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/numerics/ranges.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
...@@ -89,11 +90,6 @@ bool GetProductID(const std::string hardware_id, uint32_t* product_id) { ...@@ -89,11 +90,6 @@ bool GetProductID(const std::string hardware_id, uint32_t* product_id) {
base::HexStringToUInt(product_id_str, product_id); base::HexStringToUInt(product_id_str, product_id);
} }
// Returns value clamped to the range of [min, max].
int Clamp(int value, int min, int max) {
return std::min(std::max(value, min), max);
}
} // namespace } // namespace
// static // static
...@@ -109,8 +105,9 @@ std::vector<mojom::SerialPortInfoPtr> SerialDeviceEnumeratorWin::GetDevices() { ...@@ -109,8 +105,9 @@ std::vector<mojom::SerialPortInfoPtr> SerialDeviceEnumeratorWin::GetDevices() {
std::vector<mojom::SerialPortInfoPtr> devices = GetDevicesNew(); std::vector<mojom::SerialPortInfoPtr> devices = GetDevicesNew();
std::vector<mojom::SerialPortInfoPtr> old_devices = GetDevicesOld(); std::vector<mojom::SerialPortInfoPtr> old_devices = GetDevicesOld();
base::UmaHistogramSparse("Hardware.Serial.NewMinusOldDeviceListSize", base::UmaHistogramSparse(
Clamp(devices.size() - old_devices.size(), -10, 10)); "Hardware.Serial.NewMinusOldDeviceListSize",
base::ClampToRange<int>(devices.size() - old_devices.size(), -10, 10));
// Add devices found from both the new and old methods of enumeration. If a // Add devices found from both the new and old methods of enumeration. If a
// device is found using both the new and the old enumeration method, then we // device is found using both the new and the old enumeration method, then we
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/numerics/ranges.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "base/values.h" #include "base/values.h"
...@@ -533,7 +534,7 @@ void NetworkService::SetMaxConnectionsPerProxy(int32_t max_connections) { ...@@ -533,7 +534,7 @@ void NetworkService::SetMaxConnectionsPerProxy(int32_t max_connections) {
int max_limit = 99; int max_limit = 99;
int min_limit = net::ClientSocketPoolManager::max_sockets_per_group( int min_limit = net::ClientSocketPoolManager::max_sockets_per_group(
net::HttpNetworkSession::NORMAL_SOCKET_POOL); net::HttpNetworkSession::NORMAL_SOCKET_POOL);
new_limit = std::max(std::min(new_limit, max_limit), min_limit); new_limit = base::ClampToRange(new_limit, min_limit, max_limit);
// Assign the global limit. // Assign the global limit.
net::ClientSocketPoolManager::set_max_sockets_per_proxy_server( net::ClientSocketPoolManager::set_max_sockets_per_proxy_server(
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <vector> #include <vector>
#include "base/logging.h" #include "base/logging.h"
#include "base/numerics/ranges.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
...@@ -445,7 +446,7 @@ void ConsumerHost::TracingSession::OnTraceStats( ...@@ -445,7 +446,7 @@ void ConsumerHost::TracingSession::OnTraceStats(
buf_stats.padding_bytes_cleared(); buf_stats.padding_bytes_cleared();
double percent_full = double percent_full =
bytes_in_buffer / static_cast<double>(buf_stats.buffer_size()); bytes_in_buffer / static_cast<double>(buf_stats.buffer_size());
percent_full = std::min(std::max(0.0, percent_full), 1.0); percent_full = base::ClampToRange(percent_full, 0.0, 1.0);
bool data_loss = buf_stats.chunks_overwritten() > 0 || bool data_loss = buf_stats.chunks_overwritten() > 0 ||
buf_stats.chunks_discarded() > 0 || buf_stats.chunks_discarded() > 0 ||
buf_stats.abi_violations() > 0 || buf_stats.abi_violations() > 0 ||
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/numerics/ranges.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/trace_event/trace_log.h" #include "base/trace_event/trace_log.h"
...@@ -188,7 +189,7 @@ class PerfettoTracingCoordinator::TracingSession : public perfetto::Consumer { ...@@ -188,7 +189,7 @@ class PerfettoTracingCoordinator::TracingSession : public perfetto::Consumer {
buf_stats.padding_bytes_cleared(); buf_stats.padding_bytes_cleared();
double percent_full = double percent_full =
bytes_in_buffer / static_cast<double>(buf_stats.buffer_size()); bytes_in_buffer / static_cast<double>(buf_stats.buffer_size());
percent_full = std::min(std::max(0.0, percent_full), 1.0); percent_full = base::ClampToRange(percent_full, 0.0, 1.0);
// We know the size of data in the buffer, but not the number of events. // We know the size of data in the buffer, but not the number of events.
std::move(request_buffer_usage_callback_) std::move(request_buffer_usage_callback_)
.Run(true, percent_full, 0 /*approx_event_count*/); .Run(true, percent_full, 0 /*approx_event_count*/);
......
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