Index: 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 0000000000000000000000000000000000000000..103e61e40b1ccf4962c6c6056c739238f37116c5 |
--- /dev/null |
+++ b/content/browser/download/rate_estimator.h |
@@ -0,0 +1,45 @@ |
+// Copyright (c) 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 { |
+ |
+// This is only exported for unit tests. |
+class CONTENT_EXPORT RateEstimator { |
+ public: |
+ RateEstimator(); |
+ RateEstimator(base::TimeDelta bucket_time, |
+ size_t num_buckets, |
+ base::Time now); |
+ ~RateEstimator(); |
+ |
+ void AddBytes(uint32 byte_count); |
+ uint64 GetBytesPerSecond() const; |
+ |
+ void AddBytes(uint32 count, base::Time now); |
+ uint64 GetBytesPerSecond(base::Time now) const; |
+ |
+ private: |
+ void ClearOldBuckets(base::Time now); |
+ void ResetBuckets(base::Time now); |
+ |
+ std::vector<uint32> byte_history_; |
+ base::TimeDelta bucket_time_; |
+ size_t oldest_index_; |
+ size_t bucket_count_; |
+ base::Time oldest_time_; |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_BROWSER_DOWNLOAD_RATE_ESTIMATOR_H_ |