OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "jingle/glue/pseudotcp_adapter.h" | 5 #include "jingle/glue/pseudotcp_adapter.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 virtual bool DropNextPacket() = 0; | 39 virtual bool DropNextPacket() = 0; |
40 }; | 40 }; |
41 | 41 |
42 class LeakyBucket : public RateLimiter { | 42 class LeakyBucket : public RateLimiter { |
43 public: | 43 public: |
44 // |rate| is in drops per second. | 44 // |rate| is in drops per second. |
45 LeakyBucket(double volume, double rate) | 45 LeakyBucket(double volume, double rate) |
46 : volume_(volume), | 46 : volume_(volume), |
47 rate_(rate), | 47 rate_(rate), |
48 level_(0.0), | 48 level_(0.0), |
49 last_update_(base::TimeTicks::HighResNow()) { | 49 last_update_(base::TimeTicks::Now()) { |
50 } | 50 } |
51 | 51 |
52 ~LeakyBucket() override {} | 52 ~LeakyBucket() override {} |
53 | 53 |
54 bool DropNextPacket() override { | 54 bool DropNextPacket() override { |
55 base::TimeTicks now = base::TimeTicks::HighResNow(); | 55 base::TimeTicks now = base::TimeTicks::Now(); |
56 double interval = (now - last_update_).InSecondsF(); | 56 double interval = (now - last_update_).InSecondsF(); |
57 last_update_ = now; | 57 last_update_ = now; |
58 level_ = level_ + 1.0 - interval * rate_; | 58 level_ = level_ + 1.0 - interval * rate_; |
59 if (level_ > volume_) { | 59 if (level_ > volume_) { |
60 level_ = volume_; | 60 level_ = volume_; |
61 return true; | 61 return true; |
62 } else if (level_ < 0.0) { | 62 } else if (level_ < 0.0) { |
63 level_ = 0.0; | 63 level_ = 0.0; |
64 } | 64 } |
65 return false; | 65 return false; |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 client_pseudotcp_.get()); | 435 client_pseudotcp_.get()); |
436 | 436 |
437 tester->Start(); | 437 tester->Start(); |
438 message_loop_.Run(); | 438 message_loop_.Run(); |
439 tester->CheckResults(); | 439 tester->CheckResults(); |
440 } | 440 } |
441 | 441 |
442 } // namespace | 442 } // namespace |
443 | 443 |
444 } // namespace jingle_glue | 444 } // namespace jingle_glue |
OLD | NEW |