Index: counter.cc |
diff --git a/counter.cc b/counter.cc |
index b81a0d1beb9f9b93183148d30c90f93c198e1fc0..4de1db1051fb7570d07f5413b04adee46b87a49d 100644 |
--- a/counter.cc |
+++ b/counter.cc |
@@ -183,4 +183,32 @@ void TaggedCounter::WriteRecord(int fd) { |
} |
} |
+FrequencyCounter::FrequencyCounter() : cycle_duration_(1) { |
+} |
+ |
+FrequencyCounter::~FrequencyCounter() { |
+} |
+ |
+void FrequencyCounter::Init(const char* filename, |
+ TaggedCounterInterface::Reporter reporter, |
+ void* reporter_handle, |
+ time_t cycle_duration) { |
+ // Allow tests to inject tagged_counter_ dependency. |
+ if (tagged_counter_.get() == NULL) { |
+ tagged_counter_.reset(new TaggedCounter()); |
+ } |
+ tagged_counter_->Init(filename, reporter, reporter_handle); |
+ DCHECK(cycle_duration > 0); |
+ cycle_duration_ = cycle_duration; |
+} |
+ |
+void FrequencyCounter::UpdateInternal(int32 count, time_t now) { |
+ DCHECK(tagged_counter_.get() != NULL); |
+ tagged_counter_->Update(GetCycleNumber(now), count); |
+} |
+ |
+int32 FrequencyCounter::GetCycleNumber(time_t now) { |
+ return now / cycle_duration_; |
+} |
+ |
} // namespace chromeos_metrics |