OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/base/rate_counter.h" | 5 #include "remoting/base/rate_counter.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace remoting { | 9 namespace remoting { |
10 | 10 |
11 RateCounter::RateCounter(base::TimeDelta time_window) | 11 RateCounter::RateCounter(base::TimeDelta time_window) |
12 : time_window_(time_window), | 12 : time_window_(time_window), |
13 sum_(0) { | 13 sum_(0) { |
14 DCHECK_GT(time_window.InMilliseconds(), 0); | 14 DCHECK_GT(time_window.InMilliseconds(), 0); |
15 } | 15 } |
16 | 16 |
17 RateCounter::~RateCounter() { | 17 RateCounter::~RateCounter() { |
18 } | 18 } |
19 | 19 |
20 void RateCounter::Record(int64 value) { | 20 void RateCounter::Record(int64_t value) { |
21 DCHECK(CalledOnValidThread()); | 21 DCHECK(CalledOnValidThread()); |
22 | 22 |
23 base::Time current_time = CurrentTime(); | 23 base::Time current_time = CurrentTime(); |
24 EvictOldDataPoints(current_time); | 24 EvictOldDataPoints(current_time); |
25 sum_ += value; | 25 sum_ += value; |
26 data_points_.push(std::make_pair(current_time, value)); | 26 data_points_.push(std::make_pair(current_time, value)); |
27 } | 27 } |
28 | 28 |
29 double RateCounter::Rate() { | 29 double RateCounter::Rate() { |
30 DCHECK(CalledOnValidThread()); | 30 DCHECK(CalledOnValidThread()); |
(...skipping 22 matching lines...) Expand all Loading... |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 base::Time RateCounter::CurrentTime() const { | 56 base::Time RateCounter::CurrentTime() const { |
57 if (current_time_for_test_ == base::Time()) | 57 if (current_time_for_test_ == base::Time()) |
58 return base::Time::Now(); | 58 return base::Time::Now(); |
59 return current_time_for_test_; | 59 return current_time_for_test_; |
60 } | 60 } |
61 | 61 |
62 } // namespace remoting | 62 } // namespace remoting |
OLD | NEW |