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_DEBUG_STRUCTURED_STRUCTURED_METRICS_DEBUG_PROVIDER_H_ 6 #define COMPONENTS_METRICS_DEBUG_STRUCTURED_STRUCTURED_METRICS_DEBUG_PROVIDER_H_ 7 8 #include "base/memory/raw_ptr.h" 9 #include "components/metrics/structured/event.h" 10 #include "components/metrics/structured/recorder.h" 11 #include "components/metrics/structured/structured_metrics_recorder.h" 12 13 namespace metrics::structured { 14 15 class StructuredMetricsService; 16 17 // Provides events recorded by Structured Metrics Recorder. 18 // TODO(b/314841749): Update this class to use a watcher interface. 19 class StructuredMetricsDebugProvider 20 : public StructuredMetricsRecorder::Observer { 21 public: 22 explicit StructuredMetricsDebugProvider(StructuredMetricsService* service); 23 24 StructuredMetricsDebugProvider(const StructuredMetricsDebugProvider&) = 25 delete; 26 StructuredMetricsDebugProvider& operator=( 27 const StructuredMetricsDebugProvider&) = delete; 28 29 ~StructuredMetricsDebugProvider() override; 30 31 // StructuredMetricsRecorder::Observer: 32 void OnEventRecorded(const StructuredEventProto& event) override; 33 events()34 const base::Value::List& events() const { return events_; } 35 36 private: 37 // Loads the events that are recorded before the page is loaded. 38 void LoadRecordedEvents(); 39 40 // Maintain copy of the events to be displayed by the debug page. 41 base::Value::List events_; 42 43 raw_ptr<StructuredMetricsService> service_; 44 }; 45 46 } // namespace metrics::structured 47 48 #endif // COMPONENTS_METRICS_DEBUG_STRUCTURED_STRUCTURED_METRICS_DEBUG_PROVIDER_H_ 49