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

Side by Side Diff: net/tools/quic/quic_epoll_alarm_factory.cc

Issue 1908103002: Landing Recent QUIC changes until 4/15/2016 17:20 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix 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(QuicAlarm::Delegate* delegate) {
63 return new QuicEpollAlarm(epoll_server_,
64 QuicArenaScopedPtr<QuicAlarm::Delegate>(delegate));
65 }
66
67 QuicArenaScopedPtr<QuicAlarm> QuicEpollAlarmFactory::CreateAlarm(
68 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate,
69 QuicConnectionArena* arena) {
70 if (arena != nullptr) {
71 return arena->New<QuicEpollAlarm>(epoll_server_, std::move(delegate));
72 } else {
73 return QuicArenaScopedPtr<QuicAlarm>(
74 new QuicEpollAlarm(epoll_server_, std::move(delegate)));
75 }
76 }
77
78 } // 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