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/core/quic_alarm.h" | 5 #include "net/quic/core/quic_alarm.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "net/quic/core/quic_flags.h" | 8 #include "net/quic/core/quic_flags.h" |
9 | 9 |
10 namespace net { | 10 namespace net { |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 void QuicAlarm::Update(QuicTime new_deadline, QuicTime::Delta granularity) { | 33 void QuicAlarm::Update(QuicTime new_deadline, QuicTime::Delta granularity) { |
34 if (!new_deadline.IsInitialized()) { | 34 if (!new_deadline.IsInitialized()) { |
35 Cancel(); | 35 Cancel(); |
36 return; | 36 return; |
37 } | 37 } |
38 if (std::abs((new_deadline - deadline_).ToMicroseconds()) < | 38 if (std::abs((new_deadline - deadline_).ToMicroseconds()) < |
39 granularity.ToMicroseconds()) { | 39 granularity.ToMicroseconds()) { |
40 return; | 40 return; |
41 } | 41 } |
42 if (FLAGS_quic_change_alarms_efficiently) { | 42 const bool was_set = IsSet(); |
43 const bool was_set = IsSet(); | 43 deadline_ = new_deadline; |
44 deadline_ = new_deadline; | 44 if (was_set) { |
45 if (was_set) { | 45 UpdateImpl(); |
46 UpdateImpl(); | |
47 } else { | |
48 SetImpl(); | |
49 } | |
50 } else { | 46 } else { |
51 Cancel(); | 47 SetImpl(); |
52 Set(new_deadline); | |
53 } | 48 } |
54 } | 49 } |
55 | 50 |
56 bool QuicAlarm::IsSet() const { | 51 bool QuicAlarm::IsSet() const { |
57 return deadline_.IsInitialized(); | 52 return deadline_.IsInitialized(); |
58 } | 53 } |
59 | 54 |
60 void QuicAlarm::Fire() { | 55 void QuicAlarm::Fire() { |
61 if (!IsSet()) { | 56 if (!IsSet()) { |
62 return; | 57 return; |
63 } | 58 } |
64 | 59 |
65 deadline_ = QuicTime::Zero(); | 60 deadline_ = QuicTime::Zero(); |
66 delegate_->OnAlarm(); | 61 delegate_->OnAlarm(); |
67 } | 62 } |
68 | 63 |
69 void QuicAlarm::UpdateImpl() { | 64 void QuicAlarm::UpdateImpl() { |
70 // CancelImpl and SetImpl take the new deadline by way of the deadline_ | 65 // CancelImpl and SetImpl take the new deadline by way of the deadline_ |
71 // member, so save and restore deadline_ before canceling. | 66 // member, so save and restore deadline_ before canceling. |
72 const QuicTime new_deadline = deadline_; | 67 const QuicTime new_deadline = deadline_; |
73 | 68 |
74 deadline_ = QuicTime::Zero(); | 69 deadline_ = QuicTime::Zero(); |
75 CancelImpl(); | 70 CancelImpl(); |
76 | 71 |
77 deadline_ = new_deadline; | 72 deadline_ = new_deadline; |
78 SetImpl(); | 73 SetImpl(); |
79 } | 74 } |
80 | 75 |
81 } // namespace net | 76 } // namespace net |
OLD | NEW |