expired_histograms_checker.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_METRICS_EXPIRED_HISTOGRAMS_CHECKER_H_
  5. #define COMPONENTS_METRICS_EXPIRED_HISTOGRAMS_CHECKER_H_
  6. #include <stdint.h>
  7. #include <set>
  8. #include "base/memory/raw_ptr.h"
  9. #include "base/metrics/record_histogram_checker.h"
  10. #include "base/strings/string_piece.h"
  11. namespace metrics {
  12. // ExpiredHistogramsChecker implements RecordHistogramChecker interface
  13. // to avoid recording expired metrics.
  14. class ExpiredHistogramsChecker final : public base::RecordHistogramChecker {
  15. public:
  16. // Takes a sorted array of histogram hashes in ascending order, its size and a
  17. // list of explicitly allowed histogram names as a comma-separated string.
  18. // Histograms in the |allowlist_str| are logged even if their hash is in the
  19. // |expired_histograms_hashes|.
  20. ExpiredHistogramsChecker(const uint32_t* expired_histogram_hashes,
  21. size_t size,
  22. const std::string& allowlist_str);
  23. ExpiredHistogramsChecker(const ExpiredHistogramsChecker&) = delete;
  24. ExpiredHistogramsChecker& operator=(const ExpiredHistogramsChecker&) = delete;
  25. ~ExpiredHistogramsChecker() override;
  26. // Checks if the given |histogram_hash| corresponds to an expired histogram.
  27. bool ShouldRecord(uint32_t histogram_hash) const override;
  28. private:
  29. // Initializes the |allowlist_| array of histogram hashes that should be
  30. // recorded regardless of their expiration.
  31. void InitAllowlist(const std::string& allowlist_str);
  32. // Array of expired histogram hashes.
  33. const raw_ptr<const uint32_t> expired_histogram_hashes_;
  34. // Size of the |expired_histogram_hashes_|.
  35. const size_t size_;
  36. // Set of expired histogram hashes that should be recorded.
  37. std::set<uint32_t> allowlist_;
  38. };
  39. } // namespace metrics
  40. #endif // COMPONENTS_METRICS_EXPIRED_HISTOGRAMS_CHECKER_H_