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

Side by Side Diff: net/quic/quic_alarm.cc

Issue 1778243005: Call QuicAlarm::IsSet instead of looking at deadline_ directly, rename some variables for readabili… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@116142833
Patch Set: Created 4 years, 9 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
« no previous file with comments | « net/quic/quic_alarm.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_alarm.h" 5 #include "net/quic/quic_alarm.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "net/quic/quic_flags.h" 8 #include "net/quic/quic_flags.h"
9 9
10 namespace net { 10 namespace net {
11 11
12 QuicAlarm::QuicAlarm(QuicArenaScopedPtr<Delegate> delegate) 12 QuicAlarm::QuicAlarm(QuicArenaScopedPtr<Delegate> delegate)
13 : delegate_(std::move(delegate)), deadline_(QuicTime::Zero()) {} 13 : delegate_(std::move(delegate)), deadline_(QuicTime::Zero()) {}
14 14
15 QuicAlarm::~QuicAlarm() {} 15 QuicAlarm::~QuicAlarm() {}
16 16
17 void QuicAlarm::Set(QuicTime deadline) { 17 void QuicAlarm::Set(QuicTime new_deadline) {
18 DCHECK(!IsSet()); 18 DCHECK(!IsSet());
19 DCHECK(deadline.IsInitialized()); 19 DCHECK(new_deadline.IsInitialized());
20 deadline_ = deadline; 20 deadline_ = new_deadline;
21 SetImpl(); 21 SetImpl();
22 } 22 }
23 23
24 void QuicAlarm::Cancel() { 24 void QuicAlarm::Cancel() {
25 if (FLAGS_quic_only_cancel_set_alarms && !IsSet()) { 25 if (FLAGS_quic_only_cancel_set_alarms && !IsSet()) {
26 // Don't try to cancel an alarm that hasn't been set. 26 // Don't try to cancel an alarm that hasn't been set.
27 return; 27 return;
28 } 28 }
29 deadline_ = QuicTime::Zero(); 29 deadline_ = QuicTime::Zero();
30 CancelImpl(); 30 CancelImpl();
31 } 31 }
32 32
33 void QuicAlarm::Update(QuicTime deadline, QuicTime::Delta granularity) { 33 void QuicAlarm::Update(QuicTime new_deadline, QuicTime::Delta granularity) {
34 if (!deadline.IsInitialized()) { 34 if (!new_deadline.IsInitialized()) {
35 Cancel(); 35 Cancel();
36 return; 36 return;
37 } 37 }
38 if (std::abs(deadline.Subtract(deadline_).ToMicroseconds()) < 38 if (std::abs(new_deadline.Subtract(deadline_).ToMicroseconds()) <
39 granularity.ToMicroseconds()) { 39 granularity.ToMicroseconds()) {
40 return; 40 return;
41 } 41 }
42 Cancel(); 42 Cancel();
43 Set(deadline); 43 Set(new_deadline);
44 } 44 }
45 45
46 bool QuicAlarm::IsSet() const { 46 bool QuicAlarm::IsSet() const {
47 return deadline_.IsInitialized(); 47 return deadline_.IsInitialized();
48 } 48 }
49 49
50 void QuicAlarm::Fire() { 50 void QuicAlarm::Fire() {
51 if (!deadline_.IsInitialized()) { 51 if (!IsSet()) {
52 return; 52 return;
53 } 53 }
54 54
55 deadline_ = QuicTime::Zero(); 55 deadline_ = QuicTime::Zero();
56 QuicTime deadline = delegate_->OnAlarm(); 56 QuicTime new_deadline = delegate_->OnAlarm();
57 // delegate_->OnAlarm() might call Set(), in which case deadline_ 57 // delegate_->OnAlarm() might call Set(), in which case deadline_
58 // will already contain the new value, so don't overwrite it. Also, 58 // will already contain the new value, so don't overwrite it. Also,
59 // OnAlarm() might delete |this| so check |deadline| before 59 // OnAlarm() might delete |this| so check |deadline| before
60 // |deadline_|. 60 // |deadline_|.
61 if (deadline.IsInitialized() && !deadline_.IsInitialized()) { 61 if (new_deadline.IsInitialized() && !IsSet()) {
62 Set(deadline); 62 Set(new_deadline);
63 } 63 }
64 } 64 }
65 65
66 } // namespace net 66 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_alarm.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698