OLD | NEW |
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 | 9 |
9 namespace net { | 10 namespace net { |
10 | 11 |
11 QuicAlarm::QuicAlarm(QuicArenaScopedPtr<Delegate> delegate) | 12 QuicAlarm::QuicAlarm(QuicArenaScopedPtr<Delegate> delegate) |
12 : delegate_(std::move(delegate)), deadline_(QuicTime::Zero()) {} | 13 : delegate_(std::move(delegate)), deadline_(QuicTime::Zero()) {} |
13 | 14 |
14 QuicAlarm::~QuicAlarm() {} | 15 QuicAlarm::~QuicAlarm() {} |
15 | 16 |
16 void QuicAlarm::Set(QuicTime deadline) { | 17 void QuicAlarm::Set(QuicTime deadline) { |
17 DCHECK(!IsSet()); | 18 DCHECK(!IsSet()); |
18 DCHECK(deadline.IsInitialized()); | 19 DCHECK(deadline.IsInitialized()); |
19 deadline_ = deadline; | 20 deadline_ = deadline; |
20 SetImpl(); | 21 SetImpl(); |
21 } | 22 } |
22 | 23 |
23 void QuicAlarm::Cancel() { | 24 void QuicAlarm::Cancel() { |
| 25 if (FLAGS_quic_only_cancel_set_alarms && !IsSet()) { |
| 26 // Don't try to cancel an alarm that hasn't been set. |
| 27 return; |
| 28 } |
24 deadline_ = QuicTime::Zero(); | 29 deadline_ = QuicTime::Zero(); |
25 CancelImpl(); | 30 CancelImpl(); |
26 } | 31 } |
27 | 32 |
28 void QuicAlarm::Update(QuicTime deadline, QuicTime::Delta granularity) { | 33 void QuicAlarm::Update(QuicTime deadline, QuicTime::Delta granularity) { |
29 if (!deadline.IsInitialized()) { | 34 if (!deadline.IsInitialized()) { |
30 Cancel(); | 35 Cancel(); |
31 return; | 36 return; |
32 } | 37 } |
33 if (std::abs(deadline.Subtract(deadline_).ToMicroseconds()) < | 38 if (std::abs(deadline.Subtract(deadline_).ToMicroseconds()) < |
(...skipping 18 matching lines...) Expand all Loading... |
52 // delegate_->OnAlarm() might call Set(), in which case deadline_ | 57 // delegate_->OnAlarm() might call Set(), in which case deadline_ |
53 // 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, |
54 // OnAlarm() might delete |this| so check |deadline| before | 59 // OnAlarm() might delete |this| so check |deadline| before |
55 // |deadline_|. | 60 // |deadline_|. |
56 if (deadline.IsInitialized() && !deadline_.IsInitialized()) { | 61 if (deadline.IsInitialized() && !deadline_.IsInitialized()) { |
57 Set(deadline); | 62 Set(deadline); |
58 } | 63 } |
59 } | 64 } |
60 | 65 |
61 } // namespace net | 66 } // namespace net |
OLD | NEW |