OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009 Google Inc. All rights reserved. | 3 * Copyright (C) 2009 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 double TimerBase::nextFireInterval() const | 78 double TimerBase::nextFireInterval() const |
79 { | 79 { |
80 ASSERT(isActive()); | 80 ASSERT(isActive()); |
81 double current = monotonicallyIncreasingTime(); | 81 double current = monotonicallyIncreasingTime(); |
82 if (m_nextFireTime < current) | 82 if (m_nextFireTime < current) |
83 return 0; | 83 return 0; |
84 return m_nextFireTime - current; | 84 return m_nextFireTime - current; |
85 } | 85 } |
86 | 86 |
87 NO_LAZY_SWEEP_SANITIZE_ADDRESS | |
88 void TimerBase::setNextFireTime(double now, double delay) | 87 void TimerBase::setNextFireTime(double now, double delay) |
89 { | 88 { |
90 ASSERT(m_thread == currentThread()); | 89 ASSERT(m_thread == currentThread()); |
91 | 90 |
92 m_unalignedNextFireTime = now + delay; | 91 m_unalignedNextFireTime = now + delay; |
93 | 92 |
94 double newTime = alignedFireTime(m_unalignedNextFireTime); | 93 double newTime = alignedFireTime(m_unalignedNextFireTime); |
95 if (m_nextFireTime != newTime) { | 94 if (m_nextFireTime != newTime) { |
96 m_nextFireTime = newTime; | 95 m_nextFireTime = newTime; |
97 // Round the delay up to the nearest millisecond to be consistant with t
he | 96 // Round the delay up to the nearest millisecond to be consistant with t
he |
98 // previous behavior of BlinkPlatformImpl::setSharedTimerFireInterval. | 97 // previous behavior of BlinkPlatformImpl::setSharedTimerFireInterval. |
99 long long delayMs = static_cast<long long>(ceil((newTime - now) * 1000.0
)); | 98 long long delayMs = static_cast<long long>(ceil((newTime - now) * 1000.0
)); |
100 if (delayMs < 0) | 99 if (delayMs < 0) |
101 delayMs = 0; | 100 delayMs = 0; |
102 m_webScheduler->postTimerTask(m_location, m_cancellableTaskFactory.cance
lAndCreate(), delayMs); | 101 m_webScheduler->postTimerTask(m_location, m_cancellableTaskFactory.cance
lAndCreate(), delayMs); |
103 } | 102 } |
104 } | 103 } |
105 | 104 |
| 105 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
106 void TimerBase::run() | 106 void TimerBase::run() |
107 { | 107 { |
| 108 if (!canFire()) |
| 109 return; |
| 110 |
108 TRACE_EVENT0("blink", "TimerBase::run"); | 111 TRACE_EVENT0("blink", "TimerBase::run"); |
109 ASSERT_WITH_MESSAGE(m_thread == currentThread(), "Timer posted by %s %s was
run on a different thread", m_location.functionName(), m_location.fileName()); | 112 ASSERT_WITH_MESSAGE(m_thread == currentThread(), "Timer posted by %s %s was
run on a different thread", m_location.functionName(), m_location.fileName()); |
110 TRACE_EVENT_SET_SAMPLING_STATE("blink", "BlinkInternal"); | 113 TRACE_EVENT_SET_SAMPLING_STATE("blink", "BlinkInternal"); |
111 | 114 |
112 m_nextFireTime = 0; | 115 m_nextFireTime = 0; |
113 // Note: repeating timers drift, but this is preserving the functionality of
the old timer heap. | 116 // Note: repeating timers drift, but this is preserving the functionality of
the old timer heap. |
114 // See crbug.com/328700. | 117 // See crbug.com/328700. |
115 if (m_repeatInterval) | 118 if (m_repeatInterval) |
116 setNextFireTime(monotonicallyIncreasingTime(), m_repeatInterval); | 119 setNextFireTime(monotonicallyIncreasingTime(), m_repeatInterval); |
117 fired(); | 120 fired(); |
118 TRACE_EVENT_SET_SAMPLING_STATE("blink", "Sleeping"); | 121 TRACE_EVENT_SET_SAMPLING_STATE("blink", "Sleeping"); |
119 } | 122 } |
120 | 123 |
121 void TimerBase::didChangeAlignmentInterval(double now) | 124 void TimerBase::didChangeAlignmentInterval(double now) |
122 { | 125 { |
123 setNextFireTime(now, m_unalignedNextFireTime - now); | 126 setNextFireTime(now, m_unalignedNextFireTime - now); |
124 } | 127 } |
125 | 128 |
126 double TimerBase::nextUnalignedFireInterval() const | 129 double TimerBase::nextUnalignedFireInterval() const |
127 { | 130 { |
128 ASSERT(isActive()); | 131 ASSERT(isActive()); |
129 return std::max(m_unalignedNextFireTime - monotonicallyIncreasingTime(), 0.0
); | 132 return std::max(m_unalignedNextFireTime - monotonicallyIncreasingTime(), 0.0
); |
130 } | 133 } |
131 | 134 |
132 } // namespace blink | 135 } // namespace blink |
OLD | NEW |