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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/p2p/base/quicconnectionhelper.cc
diff --git a/webrtc/p2p/base/quicconnectionhelper.cc b/webrtc/p2p/base/quicconnectionhelper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a63bde18eab45c0903871a423ccbe5589714f638
--- /dev/null
+++ b/webrtc/p2p/base/quicconnectionhelper.cc
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/p2p/base/quicconnectionhelper.h"
+
+namespace {
+
+// An alarm which will go off at a scheduled time, and execute the |OnAlarm|
+// method of the delegate
+class QuicWebrtcAlarm : public net::QuicAlarm, public rtc::MessageHandler {
+ public:
+ 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.
+ rtc::Thread* thread,
+ QuicAlarm::Delegate* delegate)
+ : QuicAlarm(delegate),
+ clock_(clock),
+ thread_(thread),
+ in_message_queue_(false) {}
+
+ virtual ~QuicWebrtcAlarm() {}
+
+ void OnMessage(rtc::Message* msg) override {
+ 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
+ in_message_queue_ = false;
+ // The alarm may have been cancelled.
+ if (!deadline().IsInitialized()) {
+ return;
+ }
+
+ // The alarm may have been re-set to a later time.
+ if (clock_->Now() < deadline()) {
+ SetImpl();
+ return;
+ }
+
+ Fire();
+ }
+
+ protected:
+ void SetImpl() override {
+ DCHECK(deadline().IsInitialized());
+ CancelImpl(); // Unregister if already posted
+
+ int64 delay_ms = deadline().Subtract(clock_->Now()).ToMilliseconds();
+ if (delay_ms < 0) {
+ delay_ms = 0;
+ }
+ thread_->PostDelayed(delay_ms, this);
+ in_message_queue_ = true;
+ }
+
+ void CancelImpl() override {
+ if (in_message_queue_) {
+ thread_->Clear(this);
+ in_message_queue_ = false;
+ }
+ }
+
+ private:
+ const net::QuicClock* clock_;
+ rtc::Thread* thread_;
+ bool in_message_queue_;
+};
+
+} // namespace
+
+namespace cricket {
+
+QuicConnectionHelper::QuicConnectionHelper(rtc::Thread* thread)
+ : thread_(thread) {}
+
+QuicConnectionHelper::~QuicConnectionHelper() {}
+
+const net::QuicClock* QuicConnectionHelper::GetClock() const {
+ return &clock_;
+}
+
+net::QuicRandom* QuicConnectionHelper::GetRandomGenerator() {
+ return net::QuicRandom::GetInstance();
+}
+
+net::QuicAlarm* QuicConnectionHelper::CreateAlarm(
+ net::QuicAlarm::Delegate* delegate) {
+ return new QuicWebrtcAlarm(GetClock(), thread_, delegate);
+}
+
+} // namespace cricket

Powered by Google App Engine
This is Rietveld 408576698