xref: /aosp_15_r20/external/cronet/components/metrics/structured/delegating_events_processor.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 #include "components/metrics/structured/delegating_events_processor.h"
6 #include "delegating_events_processor.h"
7 #include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h"
8 
9 namespace metrics::structured {
10 
11 DelegatingEventsProcessor::DelegatingEventsProcessor() = default;
12 DelegatingEventsProcessor::~DelegatingEventsProcessor() = default;
13 
14 // Each individual events_processor could be checked, but this will need to be
15 // checked during OnEventsRecord().
ShouldProcessOnEventRecord(const Event & event)16 bool DelegatingEventsProcessor::ShouldProcessOnEventRecord(const Event& event) {
17   return true;
18 }
19 
OnEventsRecord(Event * event)20 void DelegatingEventsProcessor::OnEventsRecord(Event* event) {
21   DCHECK(event);
22 
23   for (auto& events_processor : events_processors_) {
24     if (events_processor->ShouldProcessOnEventRecord(*event)) {
25       // Note that every |events_processor| is operating on the same |event|.
26       // Race conditions should be mangaged by the client.
27       events_processor->OnEventsRecord(event);
28     }
29   }
30 }
31 
OnEventRecorded(StructuredEventProto * event)32 void DelegatingEventsProcessor::OnEventRecorded(StructuredEventProto* event) {
33   DCHECK(event);
34 
35   for (auto& events_processor : events_processors_) {
36     // Note that every |events_processor| is operating on the same |event|.
37     // Race conditions should be mangaged by the client.
38     events_processor->OnEventRecorded(event);
39   }
40 }
41 
AddEventsProcessor(std::unique_ptr<EventsProcessorInterface> events_processor)42 void DelegatingEventsProcessor::AddEventsProcessor(
43     std::unique_ptr<EventsProcessorInterface> events_processor) {
44   DCHECK(events_processor);
45 
46   events_processors_.push_back(std::move(events_processor));
47 }
48 
OnProvideIndependentMetrics(ChromeUserMetricsExtension * uma_proto)49 void DelegatingEventsProcessor::OnProvideIndependentMetrics(
50     ChromeUserMetricsExtension* uma_proto) {
51   for (auto& events_processor : events_processors_) {
52     events_processor->OnProvideIndependentMetrics(uma_proto);
53   }
54 }
55 
OnProfileAdded(const base::FilePath & path)56 void DelegatingEventsProcessor::OnProfileAdded(const base::FilePath& path) {
57   for (auto& events_processor : events_processors_) {
58     events_processor->OnProfileAdded(path);
59   }
60 }
61 
62 }  // namespace metrics::structured
63