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

Side by Side Diff: remoting/base/running_average.cc

Issue 12803008: Add unit tests for sub-components of CaptureScheduler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 7 years, 9 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/running_average.h"
6
5 #include "base/logging.h" 7 #include "base/logging.h"
6 #include "remoting/base/running_average.h"
7 8
8 namespace remoting { 9 namespace remoting {
9 10
10 RunningAverage::RunningAverage(int window_size) 11 RunningAverage::RunningAverage(int window_size)
11 : window_size_(window_size), 12 : window_size_(window_size),
12 sum_(0) { 13 sum_(0) {
13 CHECK(window_size_); 14 DCHECK_GT(window_size, 0);
14 } 15 }
15 16
16 RunningAverage::~RunningAverage() { 17 RunningAverage::~RunningAverage() {
17 } 18 }
18 19
19 void RunningAverage::Record(int64 value) { 20 void RunningAverage::Record(int64 value) {
20 base::AutoLock auto_lock(lock_); 21 DCHECK(CalledOnValidThread());
21 22
22 data_points_.push_back(value); 23 data_points_.push_back(value);
23 sum_ += value; 24 sum_ += value;
24 25
25 if (data_points_.size() > window_size_) { 26 if (data_points_.size() > window_size_) {
26 sum_ -= data_points_[0]; 27 sum_ -= data_points_[0];
27 data_points_.pop_front(); 28 data_points_.pop_front();
28 } 29 }
29 } 30 }
30 31
31 double RunningAverage::Average() { 32 double RunningAverage::Average() const {
32 base::AutoLock auto_lock(lock_); 33 DCHECK(CalledOnValidThread());
33 34
34 if (data_points_.empty()) 35 if (data_points_.empty())
35 return 0; 36 return 0;
36 return static_cast<double>(sum_) / data_points_.size(); 37 return static_cast<double>(sum_) / data_points_.size();
37 } 38 }
38 39
39 } // namespace remoting 40 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698