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_WATCHER_H_ 6 #define COMPONENTS_METRICS_DEBUG_STRUCTURED_STRUCTURED_METRICS_WATCHER_H_ 7 8 #include <vector> 9 10 #include "base/memory/raw_ptr.h" 11 #include "components/metrics/structured/event.h" 12 #include "components/metrics/structured/recorder.h" 13 14 namespace metrics::structured { 15 16 class StructuredMetricsService; 17 18 // Watches the state of the Structured Metrics Recorder to know when an event is 19 // recorded. 20 class StructuredMetricsWatcher : public Recorder::RecorderImpl { 21 public: 22 explicit StructuredMetricsWatcher(StructuredMetricsService* service); 23 24 StructuredMetricsWatcher(const StructuredMetricsWatcher&) = delete; 25 StructuredMetricsWatcher& operator=(const StructuredMetricsWatcher&) = delete; 26 27 ~StructuredMetricsWatcher() override; 28 29 // Recorder::RecorderImpl: 30 void OnEventRecord(const Event& event) override; 31 void OnProfileAdded(const base::FilePath& profile_path) override; 32 void OnReportingStateChanged(bool enabled) override; 33 events()34 const std::vector<Event>& events() const { return events_; } 35 36 private: 37 // Maintain copy of the events to be displayed by the debug page. 38 std::vector<Event> events_; 39 40 raw_ptr<StructuredMetricsService> service_; 41 }; 42 43 } // namespace metrics::structured 44 45 #endif // COMPONENTS_METRICS_DEBUG_STRUCTURED_STRUCTURED_METRICS_WATCHER_H_ 46