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