xref: /aosp_15_r20/external/cronet/components/metrics/structured/event_validator.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "components/metrics/structured/event_validator.h"
6 
7 #include <cstdint>
8 
9 namespace metrics::structured {
10 
EventValidator(uint64_t event_hash,bool force_record)11 EventValidator::EventValidator(uint64_t event_hash, bool force_record)
12     : event_hash_(event_hash), force_record_(force_record) {}
13 EventValidator::~EventValidator() = default;
14 
event_hash() const15 uint64_t EventValidator::event_hash() const {
16   return event_hash_;
17 }
18 
can_force_record() const19 bool EventValidator::can_force_record() const {
20   return force_record_;
21 }
22 
GetMetricMetadata(const std::string & metric_name) const23 std::optional<EventValidator::MetricMetadata> EventValidator::GetMetricMetadata(
24     const std::string& metric_name) const {
25   const auto it = metric_metadata_.find(metric_name);
26   if (it == metric_metadata_.end()) {
27     return std::nullopt;
28   }
29   return it->second;
30 }
31 
GetMetricName(uint64_t metric_name_hash) const32 std::optional<base::StringPiece> EventValidator::GetMetricName(
33     uint64_t metric_name_hash) const {
34   const auto it = metrics_name_map_.find(metric_name_hash);
35   if (it == metrics_name_map_.end()) {
36     return std::nullopt;
37   }
38   return it->second;
39 }
40 
41 }  // namespace metrics::structured
42