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 #ifndef COMPONENTS_METRICS_STRUCTURED_PROJECT_VALIDATOR_H_ 6 #define COMPONENTS_METRICS_STRUCTURED_PROJECT_VALIDATOR_H_ 7 8 #include <cstdint> 9 #include <string> 10 11 #include "components/metrics/structured/enums.h" 12 #include "components/metrics/structured/event_validator.h" 13 #include "third_party/abseil-cpp/absl/types/optional.h" 14 15 namespace metrics { 16 namespace structured { 17 18 // Interface to be implemented by codegen for every project to validate 19 // messages received by the structured metric service. 20 class ProjectValidator { 21 public: 22 // Should not be copied or moved. 23 ProjectValidator(const ProjectValidator&) = delete; 24 ProjectValidator& operator=(const ProjectValidator& other) = delete; 25 26 virtual ~ProjectValidator(); 27 28 // Returns the event validator if |event_name| is a valid event for this 29 // project. 30 virtual absl::optional<const EventValidator*> GetEventValidator( 31 const std::string& event_name) const = 0; 32 project_hash()33 uint64_t project_hash() const { return project_hash_; } id_type()34 IdType id_type() const { return id_type_; } id_scope()35 IdScope id_scope() const { return id_scope_; } event_type()36 EventType event_type() const { return event_type_; } key_rotation_period()37 int key_rotation_period() const { return key_rotation_period_; } 38 39 protected: 40 // Should not be constructed directly. 41 ProjectValidator(uint64_t project_hash, 42 IdType id_type, 43 IdScope id_scope, 44 EventType event_type, 45 int key_rotation_period); 46 47 private: 48 const uint64_t project_hash_; 49 const IdType id_type_; 50 const IdScope id_scope_; 51 const EventType event_type_; 52 const int key_rotation_period_; 53 }; 54 55 } // namespace structured 56 } // namespace metrics 57 58 #endif // COMPONENTS_METRICS_STRUCTURED_PROJECT_VALIDATOR_H_ 59