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_BASE_H_ 6 #define COMPONENTS_METRICS_DWA_DWA_ENTRY_BUILDER_BASE_H_ 7 8 #include <cstdint> 9 #include <optional> 10 #include <string> 11 #include <unordered_map> 12 13 #include "base/component_export.h" 14 #include "components/metrics/dwa/dwa_recorder.h" 15 #include "components/metrics/dwa/mojom/dwa_interface.mojom.h" 16 17 namespace dwa::internal { 18 19 // An internal base class for the generated DwaEntry builder objects and the 20 // DwaEntryBuilder class. DwaEntryBuilder is reserved for the case where it is 21 // not appropriate to use the auto-generated class. This class should not be 22 // used directly. COMPONENT_EXPORT(DWA)23class COMPONENT_EXPORT(DWA) DwaEntryBuilderBase { 24 public: 25 DwaEntryBuilderBase(const DwaEntryBuilderBase&) = delete; 26 DwaEntryBuilderBase(DwaEntryBuilderBase&&); 27 DwaEntryBuilderBase& operator=(const DwaEntryBuilderBase&) = delete; 28 DwaEntryBuilderBase& operator=(DwaEntryBuilderBase&&); 29 30 virtual ~DwaEntryBuilderBase(); 31 32 // Records the complete entry into the recorder. If recorder is null, the 33 // entry is simply discarded. The |entry_| is used up by this call so 34 // further calls to this will do nothing. 35 void Record(metrics::dwa::DwaRecorder* recorder); 36 37 // Return a pointer to internal DwaEntryPtr for testing. 38 metrics::dwa::mojom::DwaEntryPtr* GetEntryForTesting(); 39 40 protected: 41 explicit DwaEntryBuilderBase(uint64_t event_hash); 42 43 // Sets the content to the entry. The content is represented as a 44 // hash. 45 void SetContentInternal(uint64_t content_hash); 46 47 // Add metric to the entry. A metric contains a metric hash and value. 48 void SetMetricInternal(uint64_t metric_hash, int64_t value); 49 50 // Add study name to the set of studies of interest. 51 void AddToStudiesOfInterestInternal(std::string_view study_name); 52 53 private: 54 metrics::dwa::mojom::DwaEntryPtr entry_; 55 }; 56 57 } // namespace dwa::internal 58 59 #endif // COMPONENTS_METRICS_DWA_DWA_ENTRY_BUILDER_BASE_H_ 60