No more UmaHistogramEnumeration override variants

This function used to have two variants, one taking a string value, and
another taking a pointer. The two variants are now a single one using a
string view arg. This dispenses of two overrides for each variant, and
this change corrects that.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/bb5cb56e8987de4ee255ae9f67ed83009e24ed04

commit bb5cb56e8987de4ee255ae9f67ed83009e24ed04
Author: Alex Turner <alexmt@chromium.org>
Date:   Mon Aug 12 17:12:42 2024 +0000

    Add std::string_view versions of base::UmaHistogram* functions

    Defines an additional overload of these functions that uses
    std::string_view. We keep the existing const char* and const
    std::string& versions to avoid code bloat, but move some to a separate
    header. Introduces linting to keep those two versions synchronized.
    Also makes consequential changes to histogram classes to permit these
    new overloads. (Note that these changes cannot be easily moved to a
    separate header so are kept in the main class declarations.)

    Bug: 358538894
This commit is contained in:
Claudio DeSouza
2024-09-10 14:42:40 -04:00
committed by mkarolin
parent 9c554e979a
commit 7fd7b83e2b
3 changed files with 6 additions and 18 deletions
+1 -2
View File
@@ -21,8 +21,7 @@ if (is_redirect_cc_build) {
config("base_build_without_redirect_cc") {
defines = [
"BRAVE_GET_TARGET_FOR_DEFAULT_APP_SETTINGS=",
"BRAVE_HISTOGRAM_FUNCTIONS_UMA_HISTOGRAM_ENUMERATION_CHAR_POINTER_ARG=",
"BRAVE_HISTOGRAM_FUNCTIONS_UMA_HISTOGRAM_ENUMERATION_STRING_ARG=",
"BRAVE_HISTOGRAM_FUNCTIONS_UMA_HISTOGRAM_ENUMERATION=",
"BRAVE_SCOPED_ALLOW_BASE_SYNC_PRIMITIVES_H=",
"BRAVE_INTERNAL_TRACE_LIST_BUILTIN_CATEGORIES(X)=",
]
@@ -12,14 +12,11 @@
// PageActionIconType values are less than T::kMaxValue and it casts the sample
// to an unsigned int, so we fail the DCHECK. This override only performs the
// DCHECK if the sample is non-negative.
#define BRAVE_HISTOGRAM_FUNCTIONS_UMA_HISTOGRAM_ENUMERATION_STRING_ARG \
if (static_cast<intmax_t>(sample) >= 0)
#define BRAVE_HISTOGRAM_FUNCTIONS_UMA_HISTOGRAM_ENUMERATION_CHAR_POINTER_ARG \
#define BRAVE_HISTOGRAM_FUNCTIONS_UMA_HISTOGRAM_ENUMERATION \
if (static_cast<intmax_t>(sample) >= 0)
#include "src/base/metrics/histogram_functions.h" // IWYU pragma: export
#undef BRAVE_HISTOGRAM_FUNCTIONS_UMA_HISTOGRAM_ENUMERATION_STRING_ARG
#undef BRAVE_HISTOGRAM_FUNCTIONS_UMA_HISTOGRAM_ENUMERATION_CHAR_POINTER_ARG
#undef BRAVE_HISTOGRAM_FUNCTIONS_UMA_HISTOGRAM_ENUMERATION
#endif // BRAVE_CHROMIUM_SRC_BASE_METRICS_HISTOGRAM_FUNCTIONS_H_
@@ -1,20 +1,12 @@
diff --git a/base/metrics/histogram_functions.h b/base/metrics/histogram_functions.h
index 0036558c99046529998829e575773fd6e8eb7aaa..fa4b0fab23b5a0af57407401a5e78ca460fc12e2 100644
index 84d8945c4e027c6c362c365657becb8345e4ef74..ddc1a795964b3e953945642f9b58a62f0c873d1b 100644
--- a/base/metrics/histogram_functions.h
+++ b/base/metrics/histogram_functions.h
@@ -75,6 +75,7 @@ void UmaHistogramEnumeration(const std::string& name, T sample) {
@@ -79,6 +79,7 @@ void UmaHistogramEnumeration(std::string_view name, T sample) {
static_assert(static_cast<uintmax_t>(T::kMaxValue) <=
static_cast<uintmax_t>(INT_MAX) - 1,
"Enumeration's kMaxValue is out of range of INT_MAX!");
+ BRAVE_HISTOGRAM_FUNCTIONS_UMA_HISTOGRAM_ENUMERATION_STRING_ARG
DCHECK_LE(static_cast<uintmax_t>(sample),
static_cast<uintmax_t>(T::kMaxValue));
return UmaHistogramExactLinear(name, static_cast<int>(sample),
@@ -89,6 +90,7 @@ void UmaHistogramEnumeration(const char* name, T sample) {
static_assert(static_cast<uintmax_t>(T::kMaxValue) <=
static_cast<uintmax_t>(INT_MAX) - 1,
"Enumeration's kMaxValue is out of range of INT_MAX!");
+ BRAVE_HISTOGRAM_FUNCTIONS_UMA_HISTOGRAM_ENUMERATION_CHAR_POINTER_ARG
+ BRAVE_HISTOGRAM_FUNCTIONS_UMA_HISTOGRAM_ENUMERATION
DCHECK_LE(static_cast<uintmax_t>(sample),
static_cast<uintmax_t>(T::kMaxValue));
return UmaHistogramExactLinear(name, static_cast<int>(sample),