• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
7 namespace metrics::structured {
8 
9 DelegatingEventsProcessor::DelegatingEventsProcessor() = default;
10 DelegatingEventsProcessor::~DelegatingEventsProcessor() = default;
11 
12 // Each individual events_processor could be checked, but this will need to be
13 // checked during OnEventsRecord().
ShouldProcessOnEventRecord(const Event & event)14 bool DelegatingEventsProcessor::ShouldProcessOnEventRecord(const Event& event) {
15   return true;
16 }
17 
OnEventsRecord(Event * event)18 void DelegatingEventsProcessor::OnEventsRecord(Event* event) {
19   DCHECK(event);
20 
21   for (auto& events_processor : events_processors_) {
22     if (events_processor->ShouldProcessOnEventRecord(*event)) {
23       // Note that every |events_processor| is operating on the same |event|.
24       // Race conditions should be mangaged by the client.
25       events_processor->OnEventsRecord(event);
26     }
27   }
28 }
29 
AddEventsProcessor(std::unique_ptr<EventsProcessorInterface> events_processor)30 void DelegatingEventsProcessor::AddEventsProcessor(
31     std::unique_ptr<EventsProcessorInterface> events_processor) {
32   DCHECK(events_processor);
33 
34   events_processors_.push_back(std::move(events_processor));
35 }
36 
37 }  // namespace metrics::structured
38