1 // Copyright 2024 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_DWA_DWA_ENTRY_BUILDER_H_ 6 #define COMPONENTS_METRICS_DWA_DWA_ENTRY_BUILDER_H_ 7 8 #include <string_view> 9 10 #include "base/component_export.h" 11 #include "components/metrics/dwa/dwa_entry_builder_base.h" 12 13 namespace dwa { 14 15 // A generic builder object for recording entries in a DwaRecorder, when the 16 // recording code does not statically know the names of the events/metrics. 17 // Metrics must still be described in dwa.xml, and this will trigger a DCHECK 18 // if used to record metrics not described there. 19 // 20 // Where possible, prefer using generated objects from dwa_builders.h in the 21 // dwa::builders namespace instead. 22 // 23 // The example usage is: 24 // dwa::DwaEntryBuilder builder("PageLoad"); 25 // builder.SetContent("Content") 26 // builder.SetMetric("NavigationStart", navigation_start_time); 27 // builder.SetMetric("FirstPaint", first_paint_time); 28 // builder.AddToStudiesOfInterest("Study1"); 29 // builder.Record(dwa_recorder); COMPONENT_EXPORT(DWA)30class COMPONENT_EXPORT(DWA) DwaEntryBuilder final 31 : public dwa::internal::DwaEntryBuilderBase { 32 public: 33 explicit DwaEntryBuilder(std::string_view event_name); 34 35 DwaEntryBuilder(const DwaEntryBuilder&) = delete; 36 DwaEntryBuilder& operator=(const DwaEntryBuilder&) = delete; 37 38 ~DwaEntryBuilder() override; 39 40 void SetContent(std::string_view content); 41 void SetMetric(std::string_view metric_name, int64_t value); 42 43 void AddToStudiesOfInterest(std::string_view study_name); 44 }; 45 46 } // namespace dwa 47 48 #endif // COMPONENTS_METRICS_DWA_DWA_ENTRY_BUILDER_H_ 49