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_EVENT_STORAGE_H_ 6 #define COMPONENTS_METRICS_STRUCTURED_EVENT_STORAGE_H_ 7 8 #include "base/files/file_path.h" 9 #include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h" 10 #include "third_party/metrics_proto/structured_data.pb.h" 11 12 namespace metrics { 13 class StructuredEventProto; 14 class ChromeUserMetricsExtension; 15 } // namespace metrics 16 17 namespace metrics::structured { 18 19 // Abstraction for how events are stored in Structured Metrics. 20 class EventStorage { 21 public: 22 EventStorage() = default; 23 24 virtual ~EventStorage() = default; 25 26 EventStorage(const EventStorage&) = delete; 27 EventStorage& operator=(const EventStorage&) = delete; 28 29 virtual bool IsReady(); 30 31 // A callback to be run when the storage is ready. OnReady()32 virtual void OnReady() {} 33 34 // Add a new StructuredEventProto to be stored. 35 virtual void AddEvent(StructuredEventProto&& event) = 0; 36 37 // Events are moved to UMA proto to be uploaded. 38 virtual void MoveEvents(ChromeUserMetricsExtension& uma_proto) = 0; 39 40 // The number of events that have been recorded. 41 virtual int RecordedEventsCount() const = 0; 42 43 // Checks if events have been stored. HasEvents()44 bool HasEvents() const { return RecordedEventsCount() > 0; } 45 46 // Delete all events. 47 virtual void Purge() = 0; 48 49 // Temporary API for notifying storage that a profile has been added. OnProfileAdded(const base::FilePath & path)50 virtual void OnProfileAdded(const base::FilePath& path) {} 51 52 // Temporary API for external metrics. AddBatchEvents(const google::protobuf::RepeatedPtrField<StructuredEventProto> & events)53 virtual void AddBatchEvents( 54 const google::protobuf::RepeatedPtrField<StructuredEventProto>& events) {} 55 }; 56 57 } // namespace metrics::structured 58 59 #endif // COMPONENTS_METRICS_STRUCTURED_EVENT_STORAGE_H_ 60