| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 REMOTING_BASE_LEAKY_BUCKET_H_ |
| 6 #define REMOTING_BASE_LEAKY_BUCKET_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/time/time.h" |
| 10 |
| 11 namespace remoting { |
| 12 |
| 13 class LeakyBucket { |
| 14 public: |
| 15 static const int kUnlimitedDepth = -1; |
| 16 |
| 17 // |depth| specifies depth of the bucket in drops. kUnlimitedDepth indicate |
| 18 // that bucket size is unlimited. |rate| is specified in drops per second. |
| 19 LeakyBucket(int depth, int rate); |
| 20 ~LeakyBucket(); |
| 21 |
| 22 // If the bucket can fit |drops| then adds them and returns true. Otherwise |
| 23 // returns false. |
| 24 bool RefillOrSpill(int drops, base::TimeTicks now); |
| 25 |
| 26 // Updates rate. |
| 27 void UpdateRate(int new_rate, base::TimeTicks now); |
| 28 |
| 29 // Returns time when the bucket will be empty. The returned value may be in |
| 30 // the past. |
| 31 base::TimeTicks GetEmptyTime(); |
| 32 |
| 33 int rate() { return rate_; } |
| 34 |
| 35 private: |
| 36 void UpdateLevel(base::TimeTicks now); |
| 37 |
| 38 int depth_; |
| 39 int rate_; |
| 40 |
| 41 // |current_level_| stores water level at |level_updated_time_|. Updated in |
| 42 // UpdateLevel(), which is called from RefillOrSpill() and UpdateRate(). |
| 43 int current_level_; |
| 44 base::TimeTicks level_updated_time_; |
| 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(LeakyBucket); |
| 47 }; |
| 48 |
| 49 } // namespace remoting |
| 50 |
| 51 #endif // REMOTING_BASE_LEAKY_BUCKET_H_ |
| OLD | NEW |