Cleanup test files to use only one HttpUrlRequestFactory
[chromium-blink-merge.git] / base / metrics / sample_vector.h
blob6b2adcf2094a55c6bd4a1a1f93f12a8a489a3546
1 // Copyright (c) 2012 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.
5 // SampleVector implements HistogramSamples interface. It is used by all
6 // Histogram based classes to store samples.
8 #ifndef BASE_METRICS_SAMPLE_VECTOR_H_
9 #define BASE_METRICS_SAMPLE_VECTOR_H_
11 #include <vector>
13 #include "base/compiler_specific.h"
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/metrics/histogram_base.h"
17 #include "base/metrics/histogram_samples.h"
19 namespace base {
21 class BucketRanges;
23 class BASE_EXPORT_PRIVATE SampleVector : public HistogramSamples {
24 public:
25 explicit SampleVector(const BucketRanges* bucket_ranges);
26 virtual ~SampleVector();
28 // HistogramSamples implementation:
29 virtual void Accumulate(HistogramBase::Sample value,
30 HistogramBase::Count count) OVERRIDE;
31 virtual HistogramBase::Count GetCount(
32 HistogramBase::Sample value) const OVERRIDE;
33 virtual HistogramBase::Count TotalCount() const OVERRIDE;
34 virtual scoped_ptr<SampleCountIterator> Iterator() const OVERRIDE;
36 // Get count of a specific bucket.
37 HistogramBase::Count GetCountAtIndex(size_t bucket_index) const;
39 protected:
40 virtual bool AddSubtractImpl(
41 SampleCountIterator* iter,
42 HistogramSamples::Operator op) OVERRIDE; // |op| is ADD or SUBTRACT.
44 virtual size_t GetBucketIndex(HistogramBase::Sample value) const;
46 private:
47 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts);
49 std::vector<HistogramBase::AtomicCount> counts_;
51 // Shares the same BucketRanges with Histogram object.
52 const BucketRanges* const bucket_ranges_;
54 DISALLOW_COPY_AND_ASSIGN(SampleVector);
57 class BASE_EXPORT_PRIVATE SampleVectorIterator : public SampleCountIterator {
58 public:
59 SampleVectorIterator(const std::vector<HistogramBase::AtomicCount>* counts,
60 const BucketRanges* bucket_ranges);
61 virtual ~SampleVectorIterator();
63 // SampleCountIterator implementation:
64 virtual bool Done() const OVERRIDE;
65 virtual void Next() OVERRIDE;
66 virtual void Get(HistogramBase::Sample* min,
67 HistogramBase::Sample* max,
68 HistogramBase::Count* count) const OVERRIDE;
70 // SampleVector uses predefined buckets, so iterator can return bucket index.
71 virtual bool GetBucketIndex(size_t* index) const OVERRIDE;
73 private:
74 void SkipEmptyBuckets();
76 const std::vector<HistogramBase::AtomicCount>* counts_;
77 const BucketRanges* bucket_ranges_;
79 size_t index_;
82 } // namespace base
84 #endif // BASE_METRICS_SAMPLE_VECTOR_H_