1 // Copyright 2022 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_EVENTS_PROCESSOR_INTERFACE_H_ 6 #define COMPONENTS_METRICS_STRUCTURED_EVENTS_PROCESSOR_INTERFACE_H_ 7 8 #include "base/files/file_path.h" 9 #include "components/metrics/structured/event.h" 10 #include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h" 11 #include "third_party/metrics_proto/structured_data.pb.h" 12 13 namespace metrics::structured { 14 15 namespace { 16 17 using ::metrics::ChromeUserMetricsExtension; 18 using ::metrics::StructuredEventProto; 19 20 } // namespace 21 22 // An interface allowing different classes to add fields and metadata to events 23 // after the events are recorded by a client. 24 class EventsProcessorInterface { 25 public: 26 EventsProcessorInterface() = default; 27 28 EventsProcessorInterface(const EventsProcessorInterface& events_processor) = 29 delete; 30 EventsProcessorInterface& operator=( 31 const EventsProcessorInterface& events_processor) = delete; 32 33 virtual ~EventsProcessorInterface() = default; 34 35 // Returns true if |event| should be processed by |this|. 36 virtual bool ShouldProcessOnEventRecord(const Event& event) = 0; 37 38 // Processes |event|. Note that this function may mutate |event|. 39 virtual void OnEventsRecord(Event* event) = 0; 40 41 // Processes |event| proto. Note that this function may mutate |event|. 42 // This is called by the StructuredMetricsRecorder::OnRecordEvent once the 43 // StructuredEventProto is built. 44 virtual void OnEventRecorded(StructuredEventProto* event) = 0; 45 46 // Attach metadata when |ProvideIndependentMetrics| is called from the 47 // MetricsService. This will be called before events are attached. 48 virtual void OnProvideIndependentMetrics( 49 ChromeUserMetricsExtension* uma_proto) = 0; 50 51 // Notify the processor that a profile has been added. OnProfileAdded(const base::FilePath & path)52 virtual void OnProfileAdded(const base::FilePath& path) {} 53 }; 54 55 } // namespace metrics::structured 56 57 #endif // COMPONENTS_METRICS_STRUCTURED_EVENTS_PROCESSOR_INTERFACE_H_ 58