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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/tools/quic/quic_epoll_alarm_factory.h"
6
7 #include "base/logging.h"
8 #include "net/tools/epoll_server/epoll_server.h"
9
10 namespace net {
11
12 namespace {
13
14 class QuicEpollAlarm : public QuicAlarm {
15 public:
16 QuicEpollAlarm(EpollServer* epoll_server,
17 QuicArenaScopedPtr<Delegate> delegate)
18 : QuicAlarm(std::move(delegate)),
19 epoll_server_(epoll_server),
20 epoll_alarm_impl_(this) {}
21
22 protected:
23 void SetImpl() override {
24 DCHECK(deadline().IsInitialized());
25 epoll_server_->RegisterAlarm(
26 deadline().Subtract(QuicTime::Zero()).ToMicroseconds(),
27 &epoll_alarm_impl_);
28 }
29
30 void CancelImpl() override {
31 DCHECK(!deadline().IsInitialized());
32 epoll_alarm_impl_.UnregisterIfRegistered();
33 }
34
35 private:
36 class EpollAlarmImpl : public EpollAlarm {
37 public:
38 explicit EpollAlarmImpl(QuicEpollAlarm* alarm) : alarm_(alarm) {}
39
40 int64_t OnAlarm() override {
41 EpollAlarm::OnAlarm();
42 alarm_->Fire();
43 // Fire will take care of registering the alarm, if needed.
44 return 0;
45 }
46
47 private:
48 QuicEpollAlarm* alarm_;
49 };
50
51 EpollServer* epoll_server_;
52 EpollAlarmImpl epoll_alarm_impl_;
53 };
54
55 } // namespace
56
57 QuicEpollAlarmFactory::QuicEpollAlarmFactory(EpollServer* epoll_server)
58 : epoll_server_(epoll_server) {}
59
60 QuicEpollAlarmFactory::~QuicEpollAlarmFactory() {}
61
62 QuicAlarm* QuicEpollAlarmFactory::CreateAlarm(
63 QuicAlarm::Delegate* delegate) {
64 return new QuicEpollAlarm(epoll_server_,
65 QuicArenaScopedPtr<QuicAlarm::Delegate>(delegate));
66 }
67
68 QuicArenaScopedPtr<QuicAlarm> QuicEpollAlarmFactory::CreateAlarm(
69 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate,
70 QuicConnectionArena* arena) {
71 if (arena != nullptr) {
72 return arena->New<QuicEpollAlarm>(epoll_server_, std::move(delegate));
73 } else {
74 return QuicArenaScopedPtr<QuicAlarm>(
75 new QuicEpollAlarm(epoll_server_, std::move(delegate)));
76 }
77 }
78
79 } // namespace net
OLDNEW
« 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