xref: /aosp_15_r20/external/cronet/components/metrics/structured/project_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/project_validator.h"
6 
7 #include <cstdint>
8 
9 #include "components/metrics/structured/enums.h"
10 #include "project_validator.h"
11 
12 namespace metrics::structured {
13 
ProjectValidator(uint64_t project_hash,IdType id_type,IdScope id_scope,EventType event_type,int key_rotation_period)14 ProjectValidator::ProjectValidator(uint64_t project_hash,
15                                    IdType id_type,
16                                    IdScope id_scope,
17                                    EventType event_type,
18                                    int key_rotation_period)
19     : project_hash_(project_hash),
20       id_type_(id_type),
21       id_scope_(id_scope),
22       event_type_(event_type),
23       key_rotation_period_(key_rotation_period) {}
24 
25 ProjectValidator::~ProjectValidator() = default;
26 
GetEventValidator(base::StringPiece event_name) const27 const EventValidator* ProjectValidator::GetEventValidator(
28     base::StringPiece event_name) const {
29   const auto it = event_validators_.find(event_name);
30   if (it == event_validators_.end()) {
31     return nullptr;
32   }
33   return it->second.get();
34 }
35 
GetEventName(uint64_t event_name_hash) const36 std::optional<base::StringPiece> ProjectValidator::GetEventName(
37     uint64_t event_name_hash) const {
38   const auto it = event_name_map_.find(event_name_hash);
39   if (it == event_name_map_.end()) {
40     return std::nullopt;
41   }
42   return it->second;
43 }
44 
45 }  // namespace metrics::structured
46