Files
brave-core/components/p3a_utils/bucket.h
T
Darnell Andries ba76cdd46f Add media_session_usage custom attribute, add attribute to daily query metrics (#35420)
* Add media_session_usage custom attribute, add attribute to daily query metrics

* Add `TestEventRelayObserver`, update media session metric tests

* Use more specific values for media session attribute

* Address PR feedback
2026-04-14 17:40:34 -07:00

35 lines
1.1 KiB
C++

// Copyright (c) 2022 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef BRAVE_COMPONENTS_P3A_UTILS_BUCKET_H_
#define BRAVE_COMPONENTS_P3A_UTILS_BUCKET_H_
#include <algorithm>
#include "base/check.h"
#include "base/check_op.h"
#include "base/metrics/histogram_functions.h"
namespace p3a_utils {
template <std::size_t N>
int BucketIndex(const int (&buckets)[N], int value) {
DCHECK_GE(value, 0);
return std::lower_bound(buckets, std::end(buckets), value) - buckets;
}
template <std::size_t N>
void RecordToHistogramBucket(const char* histogram_name,
const int (&buckets)[N],
int value) {
DCHECK(histogram_name);
base::UmaHistogramExactLinear(histogram_name, BucketIndex(buckets, value),
std::size(buckets) + 1);
}
} // namespace p3a_utils
#endif // BRAVE_COMPONENTS_P3A_UTILS_BUCKET_H_