Chromium Code Reviews| Index: talk/app/webrtc/fakemetricsobserver.cc |
| diff --git a/talk/app/webrtc/fakemetricsobserver.cc b/talk/app/webrtc/fakemetricsobserver.cc |
| index 66e1c51f2a4035dd1ea011b78ae19ee2271ff692..e833834d4865ff1da03030a118db3582d3539b30 100644 |
| --- a/talk/app/webrtc/fakemetricsobserver.cc |
| +++ b/talk/app/webrtc/fakemetricsobserver.cc |
| @@ -36,16 +36,26 @@ FakeMetricsObserver::FakeMetricsObserver() { |
| void FakeMetricsObserver::Reset() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - memset(counters_, 0, sizeof(counters_)); |
| + counters_ = std::vector<std::vector<int>>(); |
|
juberti1
2015/08/20 23:14:25
this could be done via counters_.clear(), I think
|
| memset(int_histogram_samples_, 0, sizeof(int_histogram_samples_)); |
| for (std::string& type : string_histogram_samples_) { |
| type.clear(); |
| } |
| } |
| -void FakeMetricsObserver::IncrementCounter(PeerConnectionMetricsCounter type) { |
| +void FakeMetricsObserver::IncrementEnumCounter( |
| + PeerConnectionEnumCounterType type, |
| + int counter, |
| + int counter_max) { |
|
juberti1
2015/08/20 23:14:25
I don't understand why we need to pass in a maximu
|
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - ++counters_[type]; |
| + if (counters_.size() <= static_cast<size_t>(type)) { |
| + counters_.resize(type + 1); |
| + } |
| + auto& counters = counters_[type]; |
| + if (counters.size() < static_cast<size_t>(counter_max)) { |
| + counters.resize(counter_max); |
| + } |
| + ++counters[counter]; |
| } |
| void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, |
| @@ -61,9 +71,12 @@ void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, |
| string_histogram_samples_[type].assign(value); |
| } |
| -int FakeMetricsObserver::GetCounter(PeerConnectionMetricsCounter type) const { |
| +int FakeMetricsObserver::GetEnumCounter(PeerConnectionEnumCounterType type, |
| + int counter) const { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - return counters_[type]; |
| + CHECK(counters_.size() > static_cast<size_t>(type) && |
| + counters_[type].size() > static_cast<size_t>(counter)); |
| + return counters_[type][counter]; |
| } |
| int FakeMetricsObserver::GetIntHistogramSample( |