Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: webrtc/p2p/base/quicconnectionhelper.cc

Issue 1648763002: Create QuicSession (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved.
pthatcher1 2016/01/30 03:01:52 2011??
mikescarlett 2016/02/03 17:41:01 Changed to 2016.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/p2p/base/quicconnectionhelper.h"
12
13 namespace {
14
15 // An alarm which will go off at a scheduled time, and execute the |OnAlarm|
16 // method of the delegate
17 class QuicWebrtcAlarm : public net::QuicAlarm, public rtc::MessageHandler {
18 public:
19 QuicWebrtcAlarm(const net::QuicClock* clock,
pthatcher1 2016/01/30 03:01:52 Can you write a unit test for this class?
mikescarlett 2016/02/03 17:41:01 Sure no problem.
20 rtc::Thread* thread,
21 QuicAlarm::Delegate* delegate)
22 : QuicAlarm(delegate),
23 clock_(clock),
24 thread_(thread),
25 in_message_queue_(false) {}
26
27 virtual ~QuicWebrtcAlarm() {}
28
29 void OnMessage(rtc::Message* msg) override {
30 DCHECK(in_message_queue_);
pthatcher1 2016/01/30 03:01:52 Because this is called on a different thread, it m
mikescarlett 2016/02/03 17:41:01 You are correct. I looked at the source code and T
31 in_message_queue_ = false;
32 // The alarm may have been cancelled.
33 if (!deadline().IsInitialized()) {
34 return;
35 }
36
37 // The alarm may have been re-set to a later time.
38 if (clock_->Now() < deadline()) {
39 SetImpl();
40 return;
41 }
42
43 Fire();
44 }
45
46 protected:
47 void SetImpl() override {
48 DCHECK(deadline().IsInitialized());
49 CancelImpl(); // Unregister if already posted
50
51 int64 delay_ms = deadline().Subtract(clock_->Now()).ToMilliseconds();
52 if (delay_ms < 0) {
53 delay_ms = 0;
54 }
55 thread_->PostDelayed(delay_ms, this);
56 in_message_queue_ = true;
57 }
58
59 void CancelImpl() override {
60 if (in_message_queue_) {
61 thread_->Clear(this);
62 in_message_queue_ = false;
63 }
64 }
65
66 private:
67 const net::QuicClock* clock_;
68 rtc::Thread* thread_;
69 bool in_message_queue_;
70 };
71
72 } // namespace
73
74 namespace cricket {
75
76 QuicConnectionHelper::QuicConnectionHelper(rtc::Thread* thread)
77 : thread_(thread) {}
78
79 QuicConnectionHelper::~QuicConnectionHelper() {}
80
81 const net::QuicClock* QuicConnectionHelper::GetClock() const {
82 return &clock_;
83 }
84
85 net::QuicRandom* QuicConnectionHelper::GetRandomGenerator() {
86 return net::QuicRandom::GetInstance();
87 }
88
89 net::QuicAlarm* QuicConnectionHelper::CreateAlarm(
90 net::QuicAlarm::Delegate* delegate) {
91 return new QuicWebrtcAlarm(GetClock(), thread_, delegate);
92 }
93
94 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698