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 5 #include "base/metrics/dummy_histogram.h" 6 7 #include <memory> 8 9 #include "base/logging.h" 10 #include "base/metrics/histogram_samples.h" 11 #include "base/metrics/metrics_hashes.h" 12 13 namespace base { 14 15 namespace { 16 17 // Helper classes for DummyHistogram. 18 class DummySampleCountIterator : public SampleCountIterator { 19 public: 20 DummySampleCountIterator() {} 21 ~DummySampleCountIterator() override {} 22 23 // SampleCountIterator: 24 bool Done() const override { return true; } 25 void Next() override { NOTREACHED(); } 26 void Get(HistogramBase::Sample* min, 27 int64_t* max, 28 HistogramBase::Count* count) const override { 29 NOTREACHED(); 30 } 31 32 private: 33 DISALLOW_COPY_AND_ASSIGN(DummySampleCountIterator); 34 }; 35 36 class DummyHistogramSamples : public HistogramSamples { 37 public: 38 explicit DummyHistogramSamples() : HistogramSamples(0, new LocalMetadata()) {} 39 ~DummyHistogramSamples() override { 40 delete static_cast<LocalMetadata*>(meta()); 41 } 42 43 // HistogramSamples: 44 void Accumulate(HistogramBase::Sample value, 45 HistogramBase::Count count) override {} 46 HistogramBase::Count GetCount(HistogramBase::Sample value) const override { 47 return HistogramBase::Count(); 48 } 49 HistogramBase::Count TotalCount() const override { 50 return HistogramBase::Count(); 51 } 52 std::unique_ptr<SampleCountIterator> Iterator() const override { 53 return std::make_unique<DummySampleCountIterator>(); 54 } 55 bool AddSubtractImpl(SampleCountIterator* iter, Operator op) override { 56 return true; 57 } 58 59 private: 60 DISALLOW_COPY_AND_ASSIGN(DummyHistogramSamples); 61 }; 62 63 } // namespace 64 65 // static 66 DummyHistogram* DummyHistogram::GetInstance() { 67 static base::NoDestructor<DummyHistogram> dummy_histogram; 68 return dummy_histogram.get(); 69 } 70 71 uint64_t DummyHistogram::name_hash() const { 72 return HashMetricName(histogram_name()); 73 } 74 75 HistogramType DummyHistogram::GetHistogramType() const { 76 return DUMMY_HISTOGRAM; 77 } 78 79 bool DummyHistogram::HasConstructionArguments( 80 Sample expected_minimum, 81 Sample expected_maximum, 82 uint32_t expected_bucket_count) const { 83 return true; 84 } 85 86 bool DummyHistogram::AddSamplesFromPickle(PickleIterator* iter) { 87 return true; 88 } 89 90 std::unique_ptr<HistogramSamples> DummyHistogram::SnapshotSamples() const { 91 return std::make_unique<DummyHistogramSamples>(); 92 } 93 94 std::unique_ptr<HistogramSamples> DummyHistogram::SnapshotDelta() { 95 return std::make_unique<DummyHistogramSamples>(); 96 } 97 98 std::unique_ptr<HistogramSamples> DummyHistogram::SnapshotFinalDelta() const { 99 return std::make_unique<DummyHistogramSamples>(); 100 } 101 102 } // namespace base 103