[Sync] Test Android passphrase creation UI
[chromium-blink-merge.git] / remoting / base / running_average.cc
blob83877dcf74e25d74a7ac4ed826cddee0aa9d8e11
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
3 // found in the LICENSE file.
5 #include "remoting/base/running_average.h"
7 #include "base/logging.h"
9 namespace remoting {
11 RunningAverage::RunningAverage(int window_size)
12 : window_size_(window_size),
13 sum_(0) {
14 DCHECK_GT(window_size, 0);
17 RunningAverage::~RunningAverage() {
20 void RunningAverage::Record(int64 value) {
21 base::AutoLock auto_lock(lock_);
23 data_points_.push_back(value);
24 sum_ += value;
26 if (data_points_.size() > window_size_) {
27 sum_ -= data_points_[0];
28 data_points_.pop_front();
32 double RunningAverage::Average() {
33 base::AutoLock auto_lock(lock_);
35 if (data_points_.empty())
36 return 0;
37 return static_cast<double>(sum_) / data_points_.size();
40 } // namespace remoting