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

Unified Diff: net/tools/quic/quic_epoll_alarm_factory.cc

Issue 1905843003: Split out QuicAlarm creation from QuicConnectionHelper to new QuicAlarmFactory. No behavior change,… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@119753783
Patch Set: Rebase Created 4 years, 8 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
« no previous file with comments | « net/tools/quic/quic_epoll_alarm_factory.h ('k') | net/tools/quic/quic_epoll_alarm_factory_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/quic/quic_epoll_alarm_factory.cc
diff --git a/net/tools/quic/quic_epoll_alarm_factory.cc b/net/tools/quic/quic_epoll_alarm_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ffd0c5e0c4a37b07b5355730385c2e1b0e6d79c7
--- /dev/null
+++ b/net/tools/quic/quic_epoll_alarm_factory.cc
@@ -0,0 +1,79 @@
+// 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 "net/tools/quic/quic_epoll_alarm_factory.h"
+
+#include "base/logging.h"
+#include "net/tools/epoll_server/epoll_server.h"
+
+namespace net {
+
+namespace {
+
+class QuicEpollAlarm : public QuicAlarm {
+ public:
+ QuicEpollAlarm(EpollServer* epoll_server,
+ QuicArenaScopedPtr<Delegate> delegate)
+ : QuicAlarm(std::move(delegate)),
+ epoll_server_(epoll_server),
+ epoll_alarm_impl_(this) {}
+
+ protected:
+ void SetImpl() override {
+ DCHECK(deadline().IsInitialized());
+ epoll_server_->RegisterAlarm(
+ deadline().Subtract(QuicTime::Zero()).ToMicroseconds(),
+ &epoll_alarm_impl_);
+ }
+
+ void CancelImpl() override {
+ DCHECK(!deadline().IsInitialized());
+ epoll_alarm_impl_.UnregisterIfRegistered();
+ }
+
+ private:
+ class EpollAlarmImpl : public EpollAlarm {
+ public:
+ explicit EpollAlarmImpl(QuicEpollAlarm* alarm) : alarm_(alarm) {}
+
+ int64_t OnAlarm() override {
+ EpollAlarm::OnAlarm();
+ alarm_->Fire();
+ // Fire will take care of registering the alarm, if needed.
+ return 0;
+ }
+
+ private:
+ QuicEpollAlarm* alarm_;
+ };
+
+ EpollServer* epoll_server_;
+ EpollAlarmImpl epoll_alarm_impl_;
+};
+
+} // namespace
+
+QuicEpollAlarmFactory::QuicEpollAlarmFactory(EpollServer* epoll_server)
+ : epoll_server_(epoll_server) {}
+
+QuicEpollAlarmFactory::~QuicEpollAlarmFactory() {}
+
+QuicAlarm* QuicEpollAlarmFactory::CreateAlarm(
+ QuicAlarm::Delegate* delegate) {
+ return new QuicEpollAlarm(epoll_server_,
+ QuicArenaScopedPtr<QuicAlarm::Delegate>(delegate));
+}
+
+QuicArenaScopedPtr<QuicAlarm> QuicEpollAlarmFactory::CreateAlarm(
+ QuicArenaScopedPtr<QuicAlarm::Delegate> delegate,
+ QuicConnectionArena* arena) {
+ if (arena != nullptr) {
+ return arena->New<QuicEpollAlarm>(epoll_server_, std::move(delegate));
+ } else {
+ return QuicArenaScopedPtr<QuicAlarm>(
+ new QuicEpollAlarm(epoll_server_, std::move(delegate)));
+ }
+}
+
+} // namespace net
« no previous file with comments | « net/tools/quic/quic_epoll_alarm_factory.h ('k') | net/tools/quic/quic_epoll_alarm_factory_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698