Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Unified Diff: remoting/base/rate_counter.cc

Issue 2561173004: Cleanup RateCounter (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/base/rate_counter.h ('k') | remoting/base/rate_counter_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/base/rate_counter.cc
diff --git a/remoting/base/rate_counter.cc b/remoting/base/rate_counter.cc
index fdc798165b9afe770658bb42a5d7cebc35c9870d..f676fc50c98c9caa73c68181d2f9cca73a4ab976 100644
--- a/remoting/base/rate_counter.cc
+++ b/remoting/base/rate_counter.cc
@@ -9,40 +9,31 @@
namespace remoting {
RateCounter::RateCounter(base::TimeDelta time_window)
- : time_window_(time_window),
- sum_(0) {
- DCHECK_GT(time_window.InMilliseconds(), 0);
+ : time_window_(time_window), sum_(0) {
+ DCHECK_GT(time_window, base::TimeDelta());
}
-RateCounter::~RateCounter() {
-}
+RateCounter::~RateCounter() {}
void RateCounter::Record(int64_t value) {
DCHECK(CalledOnValidThread());
- base::Time current_time = CurrentTime();
- EvictOldDataPoints(current_time);
+ base::TimeTicks now = tick_clock_->NowTicks();
+ EvictOldDataPoints(now);
sum_ += value;
- data_points_.push(std::make_pair(current_time, value));
+ data_points_.push(std::make_pair(now, value));
}
double RateCounter::Rate() {
DCHECK(CalledOnValidThread());
- EvictOldDataPoints(CurrentTime());
+ EvictOldDataPoints(tick_clock_->NowTicks());
return sum_ / time_window_.InSecondsF();
}
-void RateCounter::SetCurrentTimeForTest(base::Time current_time) {
- DCHECK(CalledOnValidThread());
- DCHECK(current_time >= current_time_for_test_);
-
- current_time_for_test_ = current_time;
-}
-
-void RateCounter::EvictOldDataPoints(base::Time current_time) {
+void RateCounter::EvictOldDataPoints(base::TimeTicks now) {
// Remove data points outside of the window.
- base::Time window_start = current_time - time_window_;
+ base::TimeTicks window_start = now - time_window_;
while (!data_points_.empty()) {
if (data_points_.front().first > window_start)
@@ -53,10 +44,4 @@ void RateCounter::EvictOldDataPoints(base::Time current_time) {
}
}
-base::Time RateCounter::CurrentTime() const {
- if (current_time_for_test_ == base::Time())
- return base::Time::Now();
- return current_time_for_test_;
-}
-
} // namespace remoting
« no previous file with comments | « remoting/base/rate_counter.h ('k') | remoting/base/rate_counter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698