1 // Copyright (c) 2011 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 5 #ifndef NET_DISK_CACHE_STATS_HISTOGRAM_H_ 6 #define NET_DISK_CACHE_STATS_HISTOGRAM_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "base/metrics/histogram.h" 12 13 namespace disk_cache { 14 15 class Stats; 16 17 // This class provides support for sending the disk cache size stats as a UMA 18 // histogram. We'll provide our own storage and management for the data, and a 19 // SampleSet with a copy of our data. 20 // 21 // Class derivation of Histogram "deprecated," and should not be copied, and 22 // may eventually go away. 23 // 24 class StatsHistogram : public base::Histogram { 25 public: 26 class StatsSamples : public SampleSet { 27 public: 28 Counts* GetCounts() { 29 return &counts_; 30 } 31 }; 32 33 explicit StatsHistogram(const std::string& name, Sample minimum, 34 Sample maximum, size_t bucket_count) 35 : Histogram(name, minimum, maximum, bucket_count), init_(false) {} 36 ~StatsHistogram(); 37 38 static StatsHistogram* StatsHistogramFactoryGet(const std::string& name); 39 40 // We'll be reporting data from the given set of cache stats. 41 bool Init(const Stats* stats); 42 43 virtual Sample ranges(size_t i) const; 44 virtual size_t bucket_count() const; 45 virtual void SnapshotSample(SampleSet* sample) const; 46 virtual Inconsistencies FindCorruption(const SampleSet& snapshot) const; 47 virtual uint32 CalculateRangeChecksum() const; 48 49 private: 50 bool init_; 51 static const Stats* stats_; 52 DISALLOW_COPY_AND_ASSIGN(StatsHistogram); 53 }; 54 55 } // namespace disk_cache 56 57 #endif // NET_DISK_CACHE_STATS_HISTOGRAM_H_ 58