OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/p2p/quic/quicconnectionhelper.h" | 11 #include "webrtc/p2p/quic/quicconnectionhelper.h" |
12 | 12 |
13 namespace cricket { | 13 namespace cricket { |
14 | 14 |
15 QuicAlarm* QuicConnectionHelper::CreateAlarm( | 15 QuicAlarm* QuicConnectionHelper::CreateAlarm( |
16 net::QuicAlarm::Delegate* delegate) { | 16 net::QuicAlarm::Delegate* delegate) { |
17 return new QuicAlarm(GetClock(), thread_, delegate); | 17 return new QuicAlarm(GetClock(), thread_, |
| 18 net::QuicArenaScopedPtr<QuicAlarm::Delegate>(delegate)); |
| 19 } |
| 20 |
| 21 net::QuicArenaScopedPtr<net::QuicAlarm> QuicConnectionHelper::CreateAlarm( |
| 22 net::QuicArenaScopedPtr<QuicAlarm::Delegate> delegate, |
| 23 net::QuicConnectionArena* arena) { |
| 24 return net::QuicArenaScopedPtr<QuicAlarm>( |
| 25 new QuicAlarm(GetClock(), thread_, std::move(delegate))); |
18 } | 26 } |
19 | 27 |
20 QuicAlarm::QuicAlarm(const net::QuicClock* clock, | 28 QuicAlarm::QuicAlarm(const net::QuicClock* clock, |
21 rtc::Thread* thread, | 29 rtc::Thread* thread, |
22 QuicAlarm::Delegate* delegate) | 30 net::QuicArenaScopedPtr<net::QuicAlarm::Delegate> delegate) |
23 : net::QuicAlarm(delegate), clock_(clock), thread_(thread) {} | 31 : net::QuicAlarm(std::move(delegate)), clock_(clock), thread_(thread) {} |
24 | 32 |
25 QuicAlarm::~QuicAlarm() {} | 33 QuicAlarm::~QuicAlarm() {} |
26 | 34 |
27 void QuicAlarm::OnMessage(rtc::Message* msg) { | 35 void QuicAlarm::OnMessage(rtc::Message* msg) { |
28 // The alarm may have been cancelled. | 36 // The alarm may have been cancelled. |
29 if (!deadline().IsInitialized()) { | 37 if (!deadline().IsInitialized()) { |
30 return; | 38 return; |
31 } | 39 } |
32 | 40 |
33 // The alarm may have been re-set to a later time. | 41 // The alarm may have been re-set to a later time. |
34 if (clock_->Now() < deadline()) { | 42 if (clock_->Now() < deadline()) { |
35 SetImpl(); | 43 SetImpl(); |
36 return; | 44 return; |
37 } | 45 } |
38 | 46 |
39 Fire(); | 47 Fire(); |
40 } | 48 } |
41 | 49 |
42 int64 QuicAlarm::GetDelay() const { | 50 int64_t QuicAlarm::GetDelay() const { |
43 return deadline().Subtract(clock_->Now()).ToMilliseconds(); | 51 return deadline().Subtract(clock_->Now()).ToMilliseconds(); |
44 } | 52 } |
45 | 53 |
46 void QuicAlarm::SetImpl() { | 54 void QuicAlarm::SetImpl() { |
47 DCHECK(deadline().IsInitialized()); | 55 DCHECK(deadline().IsInitialized()); |
48 CancelImpl(); // Unregister if already posted. | 56 CancelImpl(); // Unregister if already posted. |
49 | 57 |
50 int64 delay_ms = GetDelay(); | 58 int64_t delay_ms = GetDelay(); |
51 if (delay_ms < 0) { | 59 if (delay_ms < 0) { |
52 delay_ms = 0; | 60 delay_ms = 0; |
53 } | 61 } |
54 thread_->PostDelayed(delay_ms, this); | 62 thread_->PostDelayed(delay_ms, this); |
55 } | 63 } |
56 | 64 |
57 void QuicAlarm::CancelImpl() { | 65 void QuicAlarm::CancelImpl() { |
58 thread_->Clear(this); | 66 thread_->Clear(this); |
59 } | 67 } |
60 | 68 |
61 QuicConnectionHelper::QuicConnectionHelper(rtc::Thread* thread) | 69 QuicConnectionHelper::QuicConnectionHelper(rtc::Thread* thread) |
62 : thread_(thread) {} | 70 : thread_(thread) {} |
63 | 71 |
64 QuicConnectionHelper::~QuicConnectionHelper() {} | 72 QuicConnectionHelper::~QuicConnectionHelper() {} |
65 | 73 |
66 const net::QuicClock* QuicConnectionHelper::GetClock() const { | 74 const net::QuicClock* QuicConnectionHelper::GetClock() const { |
67 return &clock_; | 75 return &clock_; |
68 } | 76 } |
69 | 77 |
70 net::QuicRandom* QuicConnectionHelper::GetRandomGenerator() { | 78 net::QuicRandom* QuicConnectionHelper::GetRandomGenerator() { |
71 return net::QuicRandom::GetInstance(); | 79 return net::QuicRandom::GetInstance(); |
72 } | 80 } |
73 | 81 |
| 82 net::QuicBufferAllocator* QuicConnectionHelper::GetBufferAllocator() { |
| 83 return &buffer_allocator_; |
| 84 } |
| 85 |
74 } // namespace cricket | 86 } // namespace cricket |
OLD | NEW |