OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_connection_helper.h" | 5 #include "net/quic/quic_connection_helper.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/sparse_histogram.h" | 9 #include "base/metrics/sparse_histogram.h" |
10 #include "base/task_runner.h" | 10 #include "base/task_runner.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 QuicChromeAlarm(const QuicClock* clock, | 22 QuicChromeAlarm(const QuicClock* clock, |
23 base::TaskRunner* task_runner, | 23 base::TaskRunner* task_runner, |
24 QuicAlarm::Delegate* delegate) | 24 QuicAlarm::Delegate* delegate) |
25 : QuicAlarm(delegate), | 25 : QuicAlarm(delegate), |
26 clock_(clock), | 26 clock_(clock), |
27 task_runner_(task_runner), | 27 task_runner_(task_runner), |
28 task_deadline_(QuicTime::Zero()), | 28 task_deadline_(QuicTime::Zero()), |
29 weak_factory_(this) {} | 29 weak_factory_(this) {} |
30 | 30 |
31 protected: | 31 protected: |
32 virtual void SetImpl() OVERRIDE { | 32 virtual void SetImpl() override { |
33 DCHECK(deadline().IsInitialized()); | 33 DCHECK(deadline().IsInitialized()); |
34 if (task_deadline_.IsInitialized()) { | 34 if (task_deadline_.IsInitialized()) { |
35 if (task_deadline_ <= deadline()) { | 35 if (task_deadline_ <= deadline()) { |
36 // Since tasks can not be un-posted, OnAlarm will be invoked which | 36 // Since tasks can not be un-posted, OnAlarm will be invoked which |
37 // will notice that deadline has not yet been reached, and will set | 37 // will notice that deadline has not yet been reached, and will set |
38 // the alarm for the new deadline. | 38 // the alarm for the new deadline. |
39 return; | 39 return; |
40 } | 40 } |
41 // The scheduled task is after new deadline. Invalidate the weak ptrs | 41 // The scheduled task is after new deadline. Invalidate the weak ptrs |
42 // so that task does not execute when we're not expecting it. | 42 // so that task does not execute when we're not expecting it. |
43 weak_factory_.InvalidateWeakPtrs(); | 43 weak_factory_.InvalidateWeakPtrs(); |
44 } | 44 } |
45 | 45 |
46 int64 delay_us = deadline().Subtract(clock_->Now()).ToMicroseconds(); | 46 int64 delay_us = deadline().Subtract(clock_->Now()).ToMicroseconds(); |
47 if (delay_us < 0) { | 47 if (delay_us < 0) { |
48 delay_us = 0; | 48 delay_us = 0; |
49 } | 49 } |
50 task_runner_->PostDelayedTask( | 50 task_runner_->PostDelayedTask( |
51 FROM_HERE, | 51 FROM_HERE, |
52 base::Bind(&QuicChromeAlarm::OnAlarm, weak_factory_.GetWeakPtr()), | 52 base::Bind(&QuicChromeAlarm::OnAlarm, weak_factory_.GetWeakPtr()), |
53 base::TimeDelta::FromMicroseconds(delay_us)); | 53 base::TimeDelta::FromMicroseconds(delay_us)); |
54 task_deadline_ = deadline(); | 54 task_deadline_ = deadline(); |
55 } | 55 } |
56 | 56 |
57 virtual void CancelImpl() OVERRIDE { | 57 virtual void CancelImpl() override { |
58 DCHECK(!deadline().IsInitialized()); | 58 DCHECK(!deadline().IsInitialized()); |
59 // Since tasks can not be un-posted, OnAlarm will be invoked which | 59 // Since tasks can not be un-posted, OnAlarm will be invoked which |
60 // will notice that deadline is not Initialized and will do nothing. | 60 // will notice that deadline is not Initialized and will do nothing. |
61 } | 61 } |
62 | 62 |
63 private: | 63 private: |
64 void OnAlarm() { | 64 void OnAlarm() { |
65 DCHECK(task_deadline_.IsInitialized()); | 65 DCHECK(task_deadline_.IsInitialized()); |
66 task_deadline_ = QuicTime::Zero(); | 66 task_deadline_ = QuicTime::Zero(); |
67 // The alarm may have been cancelled. | 67 // The alarm may have been cancelled. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 QuicRandom* QuicConnectionHelper::GetRandomGenerator() { | 110 QuicRandom* QuicConnectionHelper::GetRandomGenerator() { |
111 return random_generator_; | 111 return random_generator_; |
112 } | 112 } |
113 | 113 |
114 QuicAlarm* QuicConnectionHelper::CreateAlarm(QuicAlarm::Delegate* delegate) { | 114 QuicAlarm* QuicConnectionHelper::CreateAlarm(QuicAlarm::Delegate* delegate) { |
115 return new QuicChromeAlarm(clock_, task_runner_, delegate); | 115 return new QuicChromeAlarm(clock_, task_runner_, delegate); |
116 } | 116 } |
117 | 117 |
118 } // namespace net | 118 } // namespace net |
OLD | NEW |