1 // Copyright (c) 2008 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 8 #include <string> 9 10 #include "base/histogram.h" 11 12 namespace disk_cache { 13 14 class Stats; 15 16 // This class provides support for sending the disk cache size stats as a UMA 17 // histogram. We'll provide our own storage and management for the data, and a 18 // SampleSet with a copy of our data. 19 // 20 // Class derivation of Histogram "deprecated," and should not be copied, and 21 // may eventually go away. 22 // 23 class StatsHistogram : public Histogram { 24 public: 25 class StatsSamples : public SampleSet { 26 public: GetCounts()27 Counts* GetCounts() { 28 return &counts_; 29 } 30 }; 31 StatsHistogram(const std::string & name,Sample minimum,Sample maximum,size_t bucket_count)32 explicit StatsHistogram(const std::string& name, Sample minimum, 33 Sample maximum, size_t bucket_count) 34 : Histogram(name, minimum, maximum, bucket_count), init_(false) {} 35 ~StatsHistogram(); 36 37 static scoped_refptr<StatsHistogram> 38 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 47 private: 48 friend class Histogram; 49 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