| 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 22 matching lines...) Expand all Loading... |
| 33 #include "wtf/Atomics.h" | 33 #include "wtf/Atomics.h" |
| 34 #include "wtf/CurrentTime.h" | 34 #include "wtf/CurrentTime.h" |
| 35 #include "wtf/HashSet.h" | 35 #include "wtf/HashSet.h" |
| 36 #include <algorithm> | 36 #include <algorithm> |
| 37 #include <limits.h> | 37 #include <limits.h> |
| 38 #include <limits> | 38 #include <limits> |
| 39 #include <math.h> | 39 #include <math.h> |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 TimerBase::TimerBase(WebTaskRunner* webTaskRunner) | 43 TimerBase::TimerBase(RefPtr<WebTaskRunner> webTaskRunner) |
| 44 : m_nextFireTime(0), | 44 : m_nextFireTime(0), |
| 45 m_repeatInterval(0), | 45 m_repeatInterval(0), |
| 46 m_webTaskRunner(webTaskRunner->clone()), | 46 m_webTaskRunner(std::move(webTaskRunner)), |
| 47 #if DCHECK_IS_ON() | 47 #if DCHECK_IS_ON() |
| 48 m_thread(currentThread()), | 48 m_thread(currentThread()), |
| 49 #endif | 49 #endif |
| 50 m_weakPtrFactory(this) { | 50 m_weakPtrFactory(this) { |
| 51 ASSERT(m_webTaskRunner); | 51 ASSERT(m_webTaskRunner); |
| 52 } | 52 } |
| 53 | 53 |
| 54 TimerBase::~TimerBase() { | 54 TimerBase::~TimerBase() { |
| 55 stop(); | 55 stop(); |
| 56 } | 56 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 78 } | 78 } |
| 79 | 79 |
| 80 double TimerBase::nextFireInterval() const { | 80 double TimerBase::nextFireInterval() const { |
| 81 ASSERT(isActive()); | 81 ASSERT(isActive()); |
| 82 double current = timerMonotonicallyIncreasingTime(); | 82 double current = timerMonotonicallyIncreasingTime(); |
| 83 if (m_nextFireTime < current) | 83 if (m_nextFireTime < current) |
| 84 return 0; | 84 return 0; |
| 85 return m_nextFireTime - current; | 85 return m_nextFireTime - current; |
| 86 } | 86 } |
| 87 | 87 |
| 88 void TimerBase::moveToNewTaskRunner(WebTaskRunner* taskRunner) { | 88 void TimerBase::moveToNewTaskRunner(RefPtr<WebTaskRunner> taskRunner) { |
| 89 #if DCHECK_IS_ON() | 89 #if DCHECK_IS_ON() |
| 90 DCHECK_EQ(m_thread, currentThread()); | 90 DCHECK_EQ(m_thread, currentThread()); |
| 91 DCHECK(taskRunner->runsTasksOnCurrentThread()); | 91 DCHECK(taskRunner->runsTasksOnCurrentThread()); |
| 92 #endif | 92 #endif |
| 93 // If the underlying task runner stays the same, ignore it. | 93 // If the underlying task runner stays the same, ignore it. |
| 94 if (m_webTaskRunner->toSingleThreadTaskRunner() == | 94 if (m_webTaskRunner->toSingleThreadTaskRunner() == |
| 95 taskRunner->toSingleThreadTaskRunner()) { | 95 taskRunner->toSingleThreadTaskRunner()) { |
| 96 return; | 96 return; |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool active = isActive(); | 99 bool active = isActive(); |
| 100 m_weakPtrFactory.revokeAll(); | 100 m_weakPtrFactory.revokeAll(); |
| 101 m_webTaskRunner = taskRunner->clone(); | 101 m_webTaskRunner = std::move(taskRunner); |
| 102 | 102 |
| 103 if (!active) | 103 if (!active) |
| 104 return; | 104 return; |
| 105 | 105 |
| 106 double now = timerMonotonicallyIncreasingTime(); | 106 double now = timerMonotonicallyIncreasingTime(); |
| 107 double nextFireTime = std::max(m_nextFireTime, now); | 107 double nextFireTime = std::max(m_nextFireTime, now); |
| 108 m_nextFireTime = 0; | 108 m_nextFireTime = 0; |
| 109 | 109 |
| 110 setNextFireTime(now, nextFireTime - now); | 110 setNextFireTime(now, nextFireTime - now); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // static | 113 // static |
| 114 WebTaskRunner* TimerBase::getTimerTaskRunner() { | 114 RefPtr<WebTaskRunner> TimerBase::getTimerTaskRunner() { |
| 115 return Platform::current()->currentThread()->scheduler()->timerTaskRunner(); | 115 return Platform::current()->currentThread()->scheduler()->timerTaskRunner(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 // static | 118 // static |
| 119 WebTaskRunner* TimerBase::getUnthrottledTaskRunner() { | 119 RefPtr<WebTaskRunner> TimerBase::getUnthrottledTaskRunner() { |
| 120 return Platform::current()->currentThread()->getWebTaskRunner(); | 120 return Platform::current()->currentThread()->getWebTaskRunner(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 WebTaskRunner* TimerBase::timerTaskRunner() const { | 123 RefPtr<WebTaskRunner> TimerBase::timerTaskRunner() const { |
| 124 return m_webTaskRunner.get(); | 124 return m_webTaskRunner; |
| 125 } | 125 } |
| 126 | 126 |
| 127 void TimerBase::setNextFireTime(double now, double delay) { | 127 void TimerBase::setNextFireTime(double now, double delay) { |
| 128 #if DCHECK_IS_ON() | 128 #if DCHECK_IS_ON() |
| 129 DCHECK_EQ(m_thread, currentThread()); | 129 DCHECK_EQ(m_thread, currentThread()); |
| 130 #endif | 130 #endif |
| 131 | 131 |
| 132 double newTime = now + delay; | 132 double newTime = now + delay; |
| 133 | 133 |
| 134 if (m_nextFireTime != newTime) { | 134 if (m_nextFireTime != newTime) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 const TimerBase* b) const { | 178 const TimerBase* b) const { |
| 179 return a->m_nextFireTime < b->m_nextFireTime; | 179 return a->m_nextFireTime < b->m_nextFireTime; |
| 180 } | 180 } |
| 181 | 181 |
| 182 // static | 182 // static |
| 183 double TimerBase::timerMonotonicallyIncreasingTime() const { | 183 double TimerBase::timerMonotonicallyIncreasingTime() const { |
| 184 return timerTaskRunner()->monotonicallyIncreasingVirtualTimeSeconds(); | 184 return timerTaskRunner()->monotonicallyIncreasingVirtualTimeSeconds(); |
| 185 } | 185 } |
| 186 | 186 |
| 187 } // namespace blink | 187 } // namespace blink |
| OLD | NEW |