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

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

Issue 476023002: Land Recent QUIC Changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Final_0814_2
Patch Set: Created 6 years, 4 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') | net/quic/quic_alarm_test.cc » ('j') | 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 8
9 namespace net { 9 namespace net {
10 10
11 QuicAlarm::QuicAlarm(Delegate* delegate) 11 QuicAlarm::QuicAlarm(Delegate* delegate)
12 : delegate_(delegate), 12 : delegate_(delegate),
13 deadline_(QuicTime::Zero()) { 13 deadline_(QuicTime::Zero()) {
14 } 14 }
15 15
16 QuicAlarm::~QuicAlarm() {} 16 QuicAlarm::~QuicAlarm() {}
17 17
18 void QuicAlarm::Set(QuicTime deadline) { 18 void QuicAlarm::Set(QuicTime deadline) {
19 DCHECK(!IsSet()); 19 DCHECK(!IsSet());
20 DCHECK(deadline.IsInitialized()); 20 DCHECK(deadline.IsInitialized());
21 deadline_ = deadline; 21 deadline_ = deadline;
22 SetImpl(); 22 SetImpl();
23 } 23 }
24 24
25 void QuicAlarm::Cancel() { 25 void QuicAlarm::Cancel() {
26 deadline_ = QuicTime::Zero(); 26 deadline_ = QuicTime::Zero();
27 CancelImpl(); 27 CancelImpl();
28 } 28 }
29 29
30 void QuicAlarm::Update(QuicTime deadline, QuicTime::Delta granularity) {
31 if (!deadline.IsInitialized()) {
32 Cancel();
33 return;
34 }
35 if (std::abs(deadline.Subtract(deadline_).ToMicroseconds()) <
36 granularity.ToMicroseconds()) {
37 return;
38 }
39 Cancel();
40 Set(deadline);
41 }
42
30 bool QuicAlarm::IsSet() const { 43 bool QuicAlarm::IsSet() const {
31 return deadline_.IsInitialized(); 44 return deadline_.IsInitialized();
32 } 45 }
33 46
34 void QuicAlarm::Fire() { 47 void QuicAlarm::Fire() {
35 if (!deadline_.IsInitialized()) { 48 if (!deadline_.IsInitialized()) {
36 return; 49 return;
37 } 50 }
38 51
39 deadline_ = QuicTime::Zero(); 52 deadline_ = QuicTime::Zero();
40 QuicTime deadline = delegate_->OnAlarm(); 53 QuicTime deadline = delegate_->OnAlarm();
41 // delegate_->OnAlarm() might call Set(), in which case deadline_ will 54 // delegate_->OnAlarm() might call Set(), in which case deadline_ will
42 // already contain the new value, so don't overwrite it. 55 // already contain the new value, so don't overwrite it.
43 if (!deadline_.IsInitialized() && deadline.IsInitialized()) { 56 if (!deadline_.IsInitialized() && deadline.IsInitialized()) {
44 Set(deadline); 57 Set(deadline);
45 } 58 }
46 } 59 }
47 60
48 } // namespace net 61 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_alarm.h ('k') | net/quic/quic_alarm_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698