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

Unified Diff: net/quic/core/congestion_control/simulation/alarm_factory.cc

Issue 2322233004: Landing Recent QUIC changes until Sun Sep 4 03:41:00 (Closed)
Patch Set: Remove simulation files from the build. Created 4 years, 3 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: net/quic/core/congestion_control/simulation/alarm_factory.cc
diff --git a/net/quic/core/congestion_control/simulation/alarm_factory.cc b/net/quic/core/congestion_control/simulation/alarm_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2a2d505f5c5759498a8f390ac920724876a1093f
--- /dev/null
+++ b/net/quic/core/congestion_control/simulation/alarm_factory.cc
@@ -0,0 +1,82 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/strings/stringprintf.h"
+#include "net/quic/core/congestion_control/simulation/alarm_factory.h"
+#include "net/quic/core/quic_alarm.h"
+
+using base::StringPrintf;
+
+namespace net {
+namespace simulation {
+
+// Alarm is an implementation of QuicAlarm which can schedule alarms in the
+// simulation timeline.
+class Alarm : public QuicAlarm {
+ public:
+ Alarm(Simulator* simulator,
+ std::string name,
+ QuicArenaScopedPtr<QuicAlarm::Delegate> delegate)
+ : QuicAlarm(std::move(delegate)), adapter_(simulator, name, this) {}
+ ~Alarm() override {}
+
+ void SetImpl() override {
+ DCHECK(deadline().IsInitialized());
+ adapter_.Set(deadline());
+ }
+
+ void CancelImpl() override { adapter_.Cancel(); }
+
+ private:
+ // An adapter class triggering a QuicAlarm using a simulation time system.
+ // An adapter is required here because neither Actor nor QuicAlarm are pure
+ // interfaces.
+ class Adapter : public Actor {
+ public:
+ Adapter(Simulator* simulator, std::string name, Alarm* parent)
+ : Actor(simulator, name), parent_(parent) {}
+ ~Adapter() override {}
+
+ void Set(QuicTime time) { Schedule(time); }
+ void Cancel() { Unschedule(); }
+
+ void Act() override {
+ DCHECK(clock_->Now() == parent_->deadline());
+ parent_->Fire();
+ }
+
+ private:
+ Alarm* parent_;
+ };
+ Adapter adapter_;
+};
+
+AlarmFactory::AlarmFactory(Simulator* simulator, std::string name)
+ : simulator_(simulator), name_(std::move(name)), counter_(0) {}
+
+AlarmFactory::~AlarmFactory() {}
+
+std::string AlarmFactory::GetNewAlarmName() {
+ ++counter_;
+ return StringPrintf("%s (alarm %i)", name_.c_str(), counter_);
+}
+
+QuicAlarm* AlarmFactory::CreateAlarm(QuicAlarm::Delegate* delegate) {
+ return new Alarm(simulator_, GetNewAlarmName(),
+ QuicArenaScopedPtr<QuicAlarm::Delegate>(delegate));
+}
+
+QuicArenaScopedPtr<QuicAlarm> AlarmFactory::CreateAlarm(
+ QuicArenaScopedPtr<QuicAlarm::Delegate> delegate,
+ QuicConnectionArena* arena) {
+ if (arena != nullptr) {
+ return arena->New<Alarm>(simulator_, GetNewAlarmName(),
+ std::move(delegate));
+ }
+ return QuicArenaScopedPtr<QuicAlarm>(
+ new Alarm(simulator_, GetNewAlarmName(), std::move(delegate)));
+}
+
+} // namespace simulation
+} // namespace net
« no previous file with comments | « net/quic/core/congestion_control/simulation/alarm_factory.h ('k') | net/quic/core/congestion_control/simulation/link.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698