Update ASan/Android runtime and setup script to LLVM r200682.
[chromium-blink-merge.git] / content / browser / download / rate_estimator.h
blob111e8eb8d8b0dd0f0b83e46deae0b2b1012b8025
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_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/time/time.h"
13 #include "content/common/content_export.h"
15 namespace content {
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 {
22 public:
23 RateEstimator();
24 RateEstimator(base::TimeDelta bucket_time,
25 size_t num_buckets,
26 base::TimeTicks now);
27 ~RateEstimator();
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;
39 private:
40 void ClearOldBuckets(base::TimeTicks now);
41 void ResetBuckets(base::TimeTicks now);
43 std::vector<uint32> history_;
44 base::TimeDelta bucket_time_;
45 size_t oldest_index_;
46 size_t bucket_count_;
47 base::TimeTicks oldest_time_;
50 } // namespace content
52 #endif // CONTENT_BROWSER_DOWNLOAD_RATE_ESTIMATOR_H_