From 868fa2fe829687343ffae624259930155e16dbd8 Mon Sep 17 00:00:00 2001 From: "Torne (Richard Coles)" Date: Tue, 11 Jun 2013 10:57:03 +0100 Subject: Merge from Chromium at DEPS revision r205460 This commit was generated by merge_to_master.py. Change-Id: I4a744a5e426bd3bb378d887cfa56fe054742a540 --- content/browser/download/rate_estimator.h | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 content/browser/download/rate_estimator.h (limited to 'content/browser/download/rate_estimator.h') diff --git a/content/browser/download/rate_estimator.h b/content/browser/download/rate_estimator.h new file mode 100644 index 0000000000..b235ceccd7 --- /dev/null +++ b/content/browser/download/rate_estimator.h @@ -0,0 +1,52 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_DOWNLOAD_RATE_ESTIMATOR_H_ +#define CONTENT_BROWSER_DOWNLOAD_RATE_ESTIMATOR_H_ + +#include +#include + +#include "base/basictypes.h" +#include "base/time.h" +#include "content/common/content_export.h" + +namespace content { + +// RateEstimator generates rate estimates based on recent activity. +// +// Internally it uses a fixed-size ring buffer, and develops estimates +// based on a small sliding window of activity. +class CONTENT_EXPORT RateEstimator { + public: + RateEstimator(); + RateEstimator(base::TimeDelta bucket_time, + size_t num_buckets, + base::TimeTicks now); + ~RateEstimator(); + + // Increment the counter by |count|. The first variant uses the current time, + // the second variant provides the time that |count| is observed. + void Increment(uint32 count); + void Increment(uint32 count, base::TimeTicks now); + + // Get a rate estimate, in terms of counts/second. The first variant uses the + // current time, the second variant provides the time. + uint64 GetCountPerSecond() const; + uint64 GetCountPerSecond(base::TimeTicks now) const; + + private: + void ClearOldBuckets(base::TimeTicks now); + void ResetBuckets(base::TimeTicks now); + + std::vector history_; + base::TimeDelta bucket_time_; + size_t oldest_index_; + size_t bucket_count_; + base::TimeTicks oldest_time_; +}; + +} // namespace content + +#endif // CONTENT_BROWSER_DOWNLOAD_RATE_ESTIMATOR_H_ -- cgit v1.2.3