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_chromium_alarm_factory.h" | 5 #include "net/quic/quic_chromium_alarm_factory.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 // Since tasks can not be un-posted, OnAlarm will be invoked which | 34 // Since tasks can not be un-posted, OnAlarm will be invoked which |
35 // will notice that deadline has not yet been reached, and will set | 35 // will notice that deadline has not yet been reached, and will set |
36 // the alarm for the new deadline. | 36 // the alarm for the new deadline. |
37 return; | 37 return; |
38 } | 38 } |
39 // The scheduled task is after new deadline. Invalidate the weak ptrs | 39 // The scheduled task is after new deadline. Invalidate the weak ptrs |
40 // so that task does not execute when we're not expecting it. | 40 // so that task does not execute when we're not expecting it. |
41 weak_factory_.InvalidateWeakPtrs(); | 41 weak_factory_.InvalidateWeakPtrs(); |
42 } | 42 } |
43 | 43 |
44 int64_t delay_us = deadline().Subtract(clock_->Now()).ToMicroseconds(); | 44 int64_t delay_us = (deadline() - (clock_->Now())).ToMicroseconds(); |
45 if (delay_us < 0) { | 45 if (delay_us < 0) { |
46 delay_us = 0; | 46 delay_us = 0; |
47 } | 47 } |
48 task_runner_->PostDelayedTask( | 48 task_runner_->PostDelayedTask( |
49 FROM_HERE, | 49 FROM_HERE, |
50 base::Bind(&QuicChromeAlarm::OnAlarm, weak_factory_.GetWeakPtr()), | 50 base::Bind(&QuicChromeAlarm::OnAlarm, weak_factory_.GetWeakPtr()), |
51 base::TimeDelta::FromMicroseconds(delay_us)); | 51 base::TimeDelta::FromMicroseconds(delay_us)); |
52 task_deadline_ = deadline(); | 52 task_deadline_ = deadline(); |
53 } | 53 } |
54 | 54 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 QuicAlarm* QuicChromiumAlarmFactory::CreateAlarm( | 111 QuicAlarm* QuicChromiumAlarmFactory::CreateAlarm( |
112 QuicAlarm::Delegate* delegate) { | 112 QuicAlarm::Delegate* delegate) { |
113 return new QuicChromeAlarm(clock_, task_runner_, | 113 return new QuicChromeAlarm(clock_, task_runner_, |
114 QuicArenaScopedPtr<QuicAlarm::Delegate>(delegate)); | 114 QuicArenaScopedPtr<QuicAlarm::Delegate>(delegate)); |
115 } | 115 } |
116 | 116 |
117 } // namespace net | 117 } // namespace net |
OLD | NEW |