| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/browser/renderer_host/p2p/socket_host_throttler.h" | 5 #include "content/browser/renderer_host/p2p/socket_host_throttler.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "third_party/webrtc/base/ratelimiter.h" | 9 #include "third_party/webrtc/base/ratelimiter.h" |
| 10 #include "third_party/webrtc/base/timeutils.h" | 10 #include "third_party/webrtc/base/timeutils.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 P2PMessageThrottler::~P2PMessageThrottler() { | 25 P2PMessageThrottler::~P2PMessageThrottler() { |
| 26 } | 26 } |
| 27 | 27 |
| 28 void P2PMessageThrottler::SetSendIceBandwidth(int bandwidth_kbps) { | 28 void P2PMessageThrottler::SetSendIceBandwidth(int bandwidth_kbps) { |
| 29 rate_limiter_.reset(new rtc::RateLimiter(bandwidth_kbps, 1.0)); | 29 rate_limiter_.reset(new rtc::RateLimiter(bandwidth_kbps, 1.0)); |
| 30 } | 30 } |
| 31 | 31 |
| 32 bool P2PMessageThrottler::DropNextPacket(size_t packet_len) { | 32 bool P2PMessageThrottler::DropNextPacket(size_t packet_len) { |
| 33 double now = | 33 double now = |
| 34 rtc::TimeMicros() / static_cast<double>(rtc::kNumMicrosecsPerMillisec); | 34 rtc::TimeNanos() / static_cast<double>(rtc::kNumNanosecsPerSec); |
| 35 if (!rate_limiter_->CanUse(packet_len, now)) { | 35 if (!rate_limiter_->CanUse(packet_len, now)) { |
| 36 // Exceeding the send rate, this packet should be dropped. | 36 // Exceeding the send rate, this packet should be dropped. |
| 37 return true; | 37 return true; |
| 38 } | 38 } |
| 39 | 39 |
| 40 rate_limiter_->Use(packet_len, now); | 40 rate_limiter_->Use(packet_len, now); |
| 41 return false; | 41 return false; |
| 42 } | 42 } |
| 43 | 43 |
| 44 } // namespace content | 44 } // namespace content |
| OLD | NEW |