Chromium Code Reviews| Index: remoting/base/leaky_bucket.h |
| diff --git a/remoting/base/leaky_bucket.h b/remoting/base/leaky_bucket.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..90f6987d1bc0ab126d3ffb7d95226fe99436b0b0 |
| --- /dev/null |
| +++ b/remoting/base/leaky_bucket.h |
| @@ -0,0 +1,48 @@ |
| +// Copyright 2016 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 REMOTING_BASE_LEAKY_BUCKET_H_ |
| +#define REMOTING_BASE_LEAKY_BUCKET_H_ |
| + |
| +#include "base/macros.h" |
| +#include "base/time/time.h" |
| + |
| +namespace remoting { |
| + |
| +class LeakyBucket { |
| + public: |
| + // |depth| is in bytes. |rate| is specified in bytes/second. Zero depth |
|
Irfan
2016/09/29 22:22:41
bytes/second is a bit odd to track (for debug etc.
Sergey Ulanov
2016/09/29 23:25:20
I think it's best to use the same units for depth
|
| + // value indicates a bucket of infinite size. |
| + LeakyBucket(int depth, int rate); |
| + ~LeakyBucket(); |
| + |
| + // If the bucket can fit |size| bytes then adds them and returns true. |
| + // Otherwise returns false. |
| + bool RefillOrSpill(int size, base::TimeTicks now); |
| + |
| + // Updates rate. |
| + void UpdateRate(int new_rate, base::TimeTicks now); |
| + |
| + // Returns time when the bucket will be empty. The returned value may be in |
| + // the past. |
| + base::TimeTicks GetEmptyTime(); |
| + |
| + int rate() { return rate_; } |
| + int level() { return level_; } |
| + |
| + private: |
| + void UpdateLevel(base::TimeTicks now); |
| + |
| + int depth_; |
| + int rate_; |
| + |
| + int level_; |
|
Irfan
2016/09/29 22:22:41
document what level means ? may be call it curren
Sergey Ulanov
2016/09/29 23:25:20
Done.
|
| + base::TimeTicks last_update_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(LeakyBucket); |
| +}; |
| + |
| +} // namespace remoting |
| + |
| +#endif // REMOTING_BASE_LEAKY_BUCKET_H_ |