xref: /aosp_15_r20/external/cronet/base/test/metrics/histogram_variants_reader.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 BASE_TEST_METRICS_HISTOGRAM_VARIANTS_READER_H_
6 #define BASE_TEST_METRICS_HISTOGRAM_VARIANTS_READER_H_
7 
8 #include <map>
9 #include <optional>
10 #include <string>
11 #include <variant>
12 
13 namespace base {
14 
15 using HistogramVariantsEntryMap = std::map<std::string, std::string>;
16 
17 // Find and read the variants list with the given |variants_name| from
18 // histograms.xml in the given |subdirectory| of
19 // tools/metrics/histograms or (if |from_metadata| is set), from
20 // tools/metrics/histograms/metadata. The default is to source from the
21 // metadata folder.
22 //
23 // Useful for when you want to verify that the set of variants associated with
24 // a particular set of values actually matches the set of values. For example,
25 // BrowserUserEducationServiceTest.CheckFeaturePromoHistograms verifies that
26 // for every registered Chrome Desktop in-product-help experience, there is a
27 // corresponding variant for metrics collection. This prevents someone from
28 // adding an IPH experience without adding the corresponding histogram entry.
29 //
30 // Returns a map from name to summary, or nullopt on failure.
31 extern std::optional<HistogramVariantsEntryMap> ReadVariantsFromHistogramsXml(
32     const std::string& variants_name,
33     const std::string& subdirectory,
34     bool from_metadata = true);
35 
36 }  // namespace base
37 
38 #endif  // BASE_TEST_METRICS_HISTOGRAM_VARIANTS_READER_H_
39