• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 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/test/test_event_storage.h"
6 
7 #include "base/functional/callback_forward.h"
8 #include "base/task/current_thread.h"
9 #include "components/metrics/structured/histogram_util.h"
10 
11 namespace metrics::structured {
12 
13 TestEventStorage::TestEventStorage() = default;
14 
15 TestEventStorage::~TestEventStorage() = default;
16 
AddEvent(StructuredEventProto && event)17 void TestEventStorage::AddEvent(StructuredEventProto&& event) {
18   *events()->add_non_uma_events() = event;
19 }
20 
MoveEvents(ChromeUserMetricsExtension & uma_proto)21 void TestEventStorage::MoveEvents(ChromeUserMetricsExtension& uma_proto) {
22   StructuredDataProto* proto = uma_proto.mutable_structured_data();
23   proto->mutable_events()->Swap(events_.mutable_non_uma_events());
24 
25   events_.clear_uma_events();
26   events_.clear_non_uma_events();
27 }
28 
RecordedEventsCount() const29 int TestEventStorage::RecordedEventsCount() const {
30   return events_.non_uma_events_size();
31 }
32 
Purge()33 void TestEventStorage::Purge() {
34   events_.clear_uma_events();
35   events_.clear_non_uma_events();
36 }
37 
AddBatchEvents(const google::protobuf::RepeatedPtrField<StructuredEventProto> & events)38 void TestEventStorage::AddBatchEvents(
39     const google::protobuf::RepeatedPtrField<StructuredEventProto>& events) {
40   events_.mutable_non_uma_events()->MergeFrom(events);
41 }
42 
43 }  // namespace metrics::structured
44