1 // Copyright 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.
5 #ifndef CONTENT_BROWSER_DOWNLOAD_RATE_ESTIMATOR_H_
6 #define CONTENT_BROWSER_DOWNLOAD_RATE_ESTIMATOR_H_
11 #include "base/basictypes.h"
12 #include "base/time/time.h"
13 #include "content/common/content_export.h"
17 // RateEstimator generates rate estimates based on recent activity.
19 // Internally it uses a fixed-size ring buffer, and develops estimates
20 // based on a small sliding window of activity.
21 class CONTENT_EXPORT RateEstimator
{
24 RateEstimator(base::TimeDelta bucket_time
,
29 // Increment the counter by |count|. The first variant uses the current time,
30 // the second variant provides the time that |count| is observed.
31 void Increment(uint32 count
);
32 void Increment(uint32 count
, base::TimeTicks now
);
34 // Get a rate estimate, in terms of counts/second. The first variant uses the
35 // current time, the second variant provides the time.
36 uint64
GetCountPerSecond() const;
37 uint64
GetCountPerSecond(base::TimeTicks now
) const;
40 void ClearOldBuckets(base::TimeTicks now
);
41 void ResetBuckets(base::TimeTicks now
);
43 std::vector
<uint32
> history_
;
44 base::TimeDelta bucket_time_
;
47 base::TimeTicks oldest_time_
;
50 } // namespace content
52 #endif // CONTENT_BROWSER_DOWNLOAD_RATE_ESTIMATOR_H_