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 |
| 7 #include <utility> |
| 8 |
6 #include "third_party/webrtc/base/ratelimiter.h" | 9 #include "third_party/webrtc/base/ratelimiter.h" |
7 #include "third_party/webrtc/base/timing.h" | 10 #include "third_party/webrtc/base/timing.h" |
8 | 11 |
9 namespace content { | 12 namespace content { |
10 | 13 |
11 namespace { | 14 namespace { |
12 | 15 |
13 const int kMaxIceMessageBandwidth = 256 * 1024; | 16 const int kMaxIceMessageBandwidth = 256 * 1024; |
14 | 17 |
15 } // namespace | 18 } // namespace |
16 | 19 |
17 | 20 |
18 P2PMessageThrottler::P2PMessageThrottler() | 21 P2PMessageThrottler::P2PMessageThrottler() |
19 : timing_(new rtc::Timing()), | 22 : timing_(new rtc::Timing()), |
20 rate_limiter_(new rtc::RateLimiter(kMaxIceMessageBandwidth, 1.0)) { | 23 rate_limiter_(new rtc::RateLimiter(kMaxIceMessageBandwidth, 1.0)) { |
21 } | 24 } |
22 | 25 |
23 P2PMessageThrottler::~P2PMessageThrottler() { | 26 P2PMessageThrottler::~P2PMessageThrottler() { |
24 } | 27 } |
25 | 28 |
26 void P2PMessageThrottler::SetTiming(scoped_ptr<rtc::Timing> timing) { | 29 void P2PMessageThrottler::SetTiming(scoped_ptr<rtc::Timing> timing) { |
27 timing_ = timing.Pass(); | 30 timing_ = std::move(timing); |
28 } | 31 } |
29 | 32 |
30 void P2PMessageThrottler::SetSendIceBandwidth(int bandwidth_kbps) { | 33 void P2PMessageThrottler::SetSendIceBandwidth(int bandwidth_kbps) { |
31 rate_limiter_.reset(new rtc::RateLimiter(bandwidth_kbps, 1.0)); | 34 rate_limiter_.reset(new rtc::RateLimiter(bandwidth_kbps, 1.0)); |
32 } | 35 } |
33 | 36 |
34 bool P2PMessageThrottler::DropNextPacket(size_t packet_len) { | 37 bool P2PMessageThrottler::DropNextPacket(size_t packet_len) { |
35 double now = timing_->TimerNow(); | 38 double now = timing_->TimerNow(); |
36 if (!rate_limiter_->CanUse(packet_len, now)) { | 39 if (!rate_limiter_->CanUse(packet_len, now)) { |
37 // Exceeding the send rate, this packet should be dropped. | 40 // Exceeding the send rate, this packet should be dropped. |
38 return true; | 41 return true; |
39 } | 42 } |
40 | 43 |
41 rate_limiter_->Use(packet_len, now); | 44 rate_limiter_->Use(packet_len, now); |
42 return false; | 45 return false; |
43 } | 46 } |
44 | 47 |
45 } // namespace content | 48 } // namespace content |
OLD | NEW |