OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_DOWNLOAD_RATE_ESTIMATOR_H_ |
| 6 #define CONTENT_BROWSER_DOWNLOAD_RATE_ESTIMATOR_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/time.h" |
| 13 #include "content/common/content_export.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 // This is only exported for unit tests. |
| 18 class CONTENT_EXPORT RateEstimator { |
| 19 public: |
| 20 RateEstimator(); |
| 21 RateEstimator(base::TimeDelta bucket_time, |
| 22 size_t num_buckets, |
| 23 base::Time now); |
| 24 ~RateEstimator(); |
| 25 |
| 26 void AddBytes(uint32 byte_count); |
| 27 uint64 GetBytesPerSecond() const; |
| 28 |
| 29 void AddBytes(uint32 count, base::Time now); |
| 30 uint64 GetBytesPerSecond(base::Time now) const; |
| 31 |
| 32 private: |
| 33 void ClearOldBuckets(base::Time now); |
| 34 void ResetBuckets(base::Time now); |
| 35 |
| 36 std::vector<uint32> byte_history_; |
| 37 base::TimeDelta bucket_time_; |
| 38 size_t oldest_index_; |
| 39 size_t bucket_count_; |
| 40 base::Time oldest_time_; |
| 41 }; |
| 42 |
| 43 } // namespace content |
| 44 |
| 45 #endif // CONTENT_BROWSER_DOWNLOAD_RATE_ESTIMATOR_H_ |
OLD | NEW |