1 // Copyright 2017 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_EXPIRED_HISTOGRAMS_CHECKER_H_ 6 #define COMPONENTS_METRICS_EXPIRED_HISTOGRAMS_CHECKER_H_ 7 8 #include <stdint.h> 9 10 #include <set> 11 12 #include "base/containers/span.h" 13 #include "base/memory/raw_span.h" 14 #include "base/metrics/record_histogram_checker.h" 15 16 namespace metrics { 17 18 // ExpiredHistogramsChecker implements RecordHistogramChecker interface 19 // to avoid recording expired metrics. 20 class ExpiredHistogramsChecker final : public base::RecordHistogramChecker { 21 public: 22 // Takes a sorted array of histogram hashes in ascending order and a 23 // list of explicitly allowed histogram names as a comma-separated string. 24 // Histograms in the |allowlist_str| are logged even if their hash is in the 25 // |expired_histograms_hashes|. 26 ExpiredHistogramsChecker(base::span<const uint32_t> expired_histogram_hashes, 27 const std::string& allowlist_str); 28 29 ExpiredHistogramsChecker(const ExpiredHistogramsChecker&) = delete; 30 ExpiredHistogramsChecker& operator=(const ExpiredHistogramsChecker&) = delete; 31 32 ~ExpiredHistogramsChecker() override; 33 34 // Checks if the given |histogram_hash| corresponds to an expired histogram. 35 bool ShouldRecord(uint32_t histogram_hash) const override; 36 37 private: 38 // Initializes the |allowlist_| array of histogram hashes that should be 39 // recorded regardless of their expiration. 40 void InitAllowlist(const std::string& allowlist_str); 41 42 // Array of expired histogram hashes. 43 const base::raw_span<const uint32_t> expired_histogram_hashes_; 44 45 // Set of expired histogram hashes that should be recorded. 46 std::set<uint32_t> allowlist_; 47 }; 48 49 } // namespace metrics 50 51 #endif // COMPONENTS_METRICS_EXPIRED_HISTOGRAMS_CHECKER_H_ 52