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 #ifndef COMPONENTS_METRICS_STRUCTURED_TEST_TEST_EVENT_STORAGE_H_ 6 #define COMPONENTS_METRICS_STRUCTURED_TEST_TEST_EVENT_STORAGE_H_ 7 8 #include "components/metrics/structured/lib/event_storage.h" 9 #include "components/metrics/structured/proto/event_storage.pb.h" 10 #include "third_party/metrics_proto/structured_data.pb.h" 11 12 namespace metrics::structured { 13 14 // Simple in-memory event storage for unit and some browser tests. 15 class TestEventStorage final : public EventStorage<StructuredEventProto> { 16 public: 17 TestEventStorage(); 18 19 ~TestEventStorage() override; 20 21 // EventStorage: 22 void AddEvent(StructuredEventProto event) override; 23 ::google::protobuf::RepeatedPtrField<StructuredEventProto> TakeEvents() 24 override; 25 int RecordedEventsCount() const override; 26 void Purge() override; 27 void AddBatchEvents( 28 const google::protobuf::RepeatedPtrField<StructuredEventProto>& events) 29 override; 30 void CopyEvents(EventsProto* proto) const override; 31 events()32 EventsProto* events() { return &events_; } events()33 const EventsProto* events() const { return &events_; } 34 35 private: 36 EventsProto events_; 37 }; 38 39 } // namespace metrics::structured 40 41 #endif // COMPONENTS_METRICS_STRUCTURED_TEST_TEST_EVENT_STORAGE_H_ 42