1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121

base / metrics / dummy_histogram.cc [blame]

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/metrics/dummy_histogram.h"

#include <memory>

#include "base/metrics/histogram_samples.h"
#include "base/metrics/metrics_hashes.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/values.h"

namespace base {

namespace {

// Helper classes for DummyHistogram.
class DummySampleCountIterator : public SampleCountIterator {
 public:
  DummySampleCountIterator() = default;
  DummySampleCountIterator(const DummySampleCountIterator&) = delete;
  DummySampleCountIterator& operator=(const DummySampleCountIterator&) = delete;
  ~DummySampleCountIterator() override = default;

  // SampleCountIterator:
  bool Done() const override { return true; }
  void Next() override { NOTREACHED(); }
  void Get(HistogramBase::Sample* min,
           int64_t* max,
           HistogramBase::Count* count) override {
    NOTREACHED();
  }
};

class DummyHistogramSamples : public HistogramSamples {
 public:
  DummyHistogramSamples()
      : HistogramSamples(0, std::make_unique<LocalMetadata>()) {}
  DummyHistogramSamples(const DummyHistogramSamples&) = delete;
  DummyHistogramSamples& operator=(const DummyHistogramSamples&) = delete;

  // HistogramSamples:
  void Accumulate(HistogramBase::Sample value,
                  HistogramBase::Count count) override {}
  HistogramBase::Count GetCount(HistogramBase::Sample value) const override {
    return HistogramBase::Count();
  }
  HistogramBase::Count TotalCount() const override {
    return HistogramBase::Count();
  }
  std::unique_ptr<SampleCountIterator> Iterator() const override {
    return std::make_unique<DummySampleCountIterator>();
  }
  std::unique_ptr<SampleCountIterator> ExtractingIterator() override {
    return std::make_unique<DummySampleCountIterator>();
  }
  bool IsDefinitelyEmpty() const override { NOTREACHED(); }
  bool AddSubtractImpl(SampleCountIterator* iter, Operator op) override {
    return true;
  }
};

}  // namespace

// static
DummyHistogram* DummyHistogram::GetInstance() {
  static base::NoDestructor<DummyHistogram> dummy_histogram;
  return dummy_histogram.get();
}

uint64_t DummyHistogram::name_hash() const {
  return HashMetricName(histogram_name());
}

HistogramType DummyHistogram::GetHistogramType() const {
  return DUMMY_HISTOGRAM;
}

bool DummyHistogram::HasConstructionArguments(
    Sample expected_minimum,
    Sample expected_maximum,
    size_t expected_bucket_count) const {
  return true;
}

bool DummyHistogram::AddSamples(const HistogramSamples& samples) {
  return true;
}

bool DummyHistogram::AddSamplesFromPickle(PickleIterator* iter) {
  return true;
}

std::unique_ptr<HistogramSamples> DummyHistogram::SnapshotSamples() const {
  return std::make_unique<DummyHistogramSamples>();
}

std::unique_ptr<HistogramSamples> DummyHistogram::SnapshotUnloggedSamples()
    const {
  return std::make_unique<DummyHistogramSamples>();
}

std::unique_ptr<HistogramSamples> DummyHistogram::SnapshotDelta() {
  return std::make_unique<DummyHistogramSamples>();
}

std::unique_ptr<HistogramSamples> DummyHistogram::SnapshotFinalDelta() const {
  return std::make_unique<DummyHistogramSamples>();
}

Value::Dict DummyHistogram::ToGraphDict() const {
  return Value::Dict();
}

Value::Dict DummyHistogram::GetParameters() const {
  return Value::Dict();
}

}  // namespace base