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

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

Issue 1898793003: Make QuicDispatcher's helper and alarm factory arguments unique_ptrs to make ownership clear. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@119871679
Patch Set: fixing 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 2016 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 "net/tools/epoll_server/epoll_server.h"
8
9 namespace net {
10
11 namespace {
12
13 class QuicEpollAlarm : public QuicAlarm {
14 public:
15 QuicEpollAlarm(EpollServer* epoll_server,
16 QuicArenaScopedPtr<Delegate> delegate)
17 : QuicAlarm(std::move(delegate)),
18 epoll_server_(epoll_server),
19 epoll_alarm_impl_(this) {}
20
21 protected:
22 void SetImpl() override {
23 DCHECK(deadline().IsInitialized());
24 epoll_server_->RegisterAlarm(
25 deadline().Subtract(QuicTime::Zero()).ToMicroseconds(),
26 &epoll_alarm_impl_);
27 }
28
29 void CancelImpl() override {
30 DCHECK(!deadline().IsInitialized());
31 epoll_alarm_impl_.UnregisterIfRegistered();
32 }
33
34 private:
35 class EpollAlarmImpl : public EpollAlarm {
36 public:
37 explicit EpollAlarmImpl(QuicEpollAlarm* alarm) : alarm_(alarm) {}
38
39 int64_t OnAlarm() override {
40 EpollAlarm::OnAlarm();
41 alarm_->Fire();
42 // Fire will take care of registering the alarm, if needed.
43 return 0;
44 }
45
46 private:
47 QuicEpollAlarm* alarm_;
48 };
49
50 EpollServer* epoll_server_;
51 EpollAlarmImpl epoll_alarm_impl_;
52 };
53
54 } // namespace
55
56 QuicEpollAlarmFactory::QuicEpollAlarmFactory(EpollServer* epoll_server)
57 : epoll_server_(epoll_server) {}
58
59 QuicEpollAlarmFactory::~QuicEpollAlarmFactory() {}
60
61 QuicAlarm* QuicEpollAlarmFactory::CreateAlarm(QuicAlarm::Delegate* delegate) {
62 return new QuicEpollAlarm(epoll_server_,
63 QuicArenaScopedPtr<QuicAlarm::Delegate>(delegate));
64 }
65
66 QuicArenaScopedPtr<QuicAlarm> QuicEpollAlarmFactory::CreateAlarm(
67 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate,
68 QuicConnectionArena* arena) {
69 if (arena != nullptr) {
70 return arena->New<QuicEpollAlarm>(epoll_server_, std::move(delegate));
71 }
72 return QuicArenaScopedPtr<QuicAlarm>(
73 new QuicEpollAlarm(epoll_server_, std::move(delegate)));
74 }
75
76 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_epoll_alarm_factory.h ('k') | net/tools/quic/quic_epoll_connection_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698