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 #include <set> 10 11 #include "base/memory/raw_ptr.h" 12 #include "base/metrics/record_histogram_checker.h" 13 #include "base/strings/string_piece.h" 14 15 namespace metrics { 16 17 // ExpiredHistogramsChecker implements RecordHistogramChecker interface 18 // to avoid recording expired metrics. 19 class ExpiredHistogramsChecker final : public base::RecordHistogramChecker { 20 public: 21 // Takes a sorted array of histogram hashes in ascending order, its size and a 22 // list of explicitly allowed histogram names as a comma-separated string. 23 // Histograms in the |allowlist_str| are logged even if their hash is in the 24 // |expired_histograms_hashes|. 25 ExpiredHistogramsChecker(const uint32_t* expired_histogram_hashes, 26 size_t size, 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 raw_ptr<const uint32_t, AllowPtrArithmetic> expired_histogram_hashes_; 44 45 // Size of the |expired_histogram_hashes_|. 46 const size_t size_; 47 48 // Set of expired histogram hashes that should be recorded. 49 std::set<uint32_t> allowlist_; 50 }; 51 52 } // namespace metrics 53 54 #endif // COMPONENTS_METRICS_EXPIRED_HISTOGRAMS_CHECKER_H_ 55