1 // Copyright 2014 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 #include "remoting/test/leaky_bucket.h"
7 #include "base/logging.h"
11 LeakyBucket::LeakyBucket(double depth
, double rate
)
15 last_update_(base::TimeTicks::Now()) {
18 LeakyBucket::~LeakyBucket() {
21 base::TimeDelta
LeakyBucket::AddPacket(int size
) {
24 double new_level
= level_
+ size
;
25 if (new_level
> depth_
)
26 return base::TimeDelta::Max();
28 base::TimeDelta result
= base::TimeDelta::FromSecondsD(level_
/ rate_
);
33 void LeakyBucket::UpdateLevel() {
34 base::TimeTicks now
= base::TimeTicks::Now();
35 level_
-= rate_
* (now
- last_update_
).InSecondsF();
41 } // namespace remoting