summaryrefslogtreecommitdiff
path: root/content/browser/download/rate_estimator.h
diff options
context:
space:
mode:
authorTorne (Richard Coles) <torne@google.com>2013-06-11 10:57:03 +0100
committerTorne (Richard Coles) <torne@google.com>2013-06-11 10:57:03 +0100
commit868fa2fe829687343ffae624259930155e16dbd8 (patch)
tree54d316199dd9739c57c3aacd131853bbd6554a94 /content/browser/download/rate_estimator.h
parentbb1bdbd796f966b5bf11f40ecbea12621c7bfac9 (diff)
downloadchromium_org-868fa2fe829687343ffae624259930155e16dbd8.tar.gz
Merge from Chromium at DEPS revision r205460
This commit was generated by merge_to_master.py. Change-Id: I4a744a5e426bd3bb378d887cfa56fe054742a540
Diffstat (limited to 'content/browser/download/rate_estimator.h')
-rw-r--r--content/browser/download/rate_estimator.h52
1 files changed, 52 insertions, 0 deletions
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 <string>
+#include <vector>
+
+#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<uint32> 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_