Chromium Code Reviews| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 ASSERT(m_webTaskRunner); | 51 ASSERT(m_webTaskRunner); |
| 52 } | 52 } |
| 53 | 53 |
| 54 TimerBase::~TimerBase() { | 54 TimerBase::~TimerBase() { |
| 55 stop(); | 55 stop(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void TimerBase::start(double nextFireInterval, | 58 void TimerBase::start(double nextFireInterval, |
| 59 double repeatInterval, | 59 double repeatInterval, |
| 60 const WebTraceLocation& caller) { | 60 const WebTraceLocation& caller) { |
| 61 ASSERT(m_thread == currentThread()); | 61 #if DCHECK_IS_ON() |
| 62 DCHECK(m_thread == currentThread()); | |
|
Yuta Kitamura
2016/11/21 09:26:12
Ditto for this file.
Alexander Alekseev
2016/11/23 09:20:30
Done.
| |
| 63 #endif | |
| 62 | 64 |
| 63 m_location = caller; | 65 m_location = caller; |
| 64 m_repeatInterval = repeatInterval; | 66 m_repeatInterval = repeatInterval; |
| 65 setNextFireTime(timerMonotonicallyIncreasingTime(), nextFireInterval); | 67 setNextFireTime(timerMonotonicallyIncreasingTime(), nextFireInterval); |
| 66 } | 68 } |
| 67 | 69 |
| 68 void TimerBase::stop() { | 70 void TimerBase::stop() { |
| 69 ASSERT(m_thread == currentThread()); | 71 #if DCHECK_IS_ON() |
| 72 DCHECK(m_thread == currentThread()); | |
| 73 #endif | |
| 70 | 74 |
| 71 m_repeatInterval = 0; | 75 m_repeatInterval = 0; |
| 72 m_nextFireTime = 0; | 76 m_nextFireTime = 0; |
| 73 m_weakPtrFactory.revokeAll(); | 77 m_weakPtrFactory.revokeAll(); |
| 74 } | 78 } |
| 75 | 79 |
| 76 double TimerBase::nextFireInterval() const { | 80 double TimerBase::nextFireInterval() const { |
| 77 ASSERT(isActive()); | 81 ASSERT(isActive()); |
| 78 double current = timerMonotonicallyIncreasingTime(); | 82 double current = timerMonotonicallyIncreasingTime(); |
| 79 if (m_nextFireTime < current) | 83 if (m_nextFireTime < current) |
| 80 return 0; | 84 return 0; |
| 81 return m_nextFireTime - current; | 85 return m_nextFireTime - current; |
| 82 } | 86 } |
| 83 | 87 |
| 84 // static | 88 // static |
| 85 WebTaskRunner* TimerBase::getTimerTaskRunner() { | 89 WebTaskRunner* TimerBase::getTimerTaskRunner() { |
| 86 return Platform::current()->currentThread()->scheduler()->timerTaskRunner(); | 90 return Platform::current()->currentThread()->scheduler()->timerTaskRunner(); |
| 87 } | 91 } |
| 88 | 92 |
| 89 // static | 93 // static |
| 90 WebTaskRunner* TimerBase::getUnthrottledTaskRunner() { | 94 WebTaskRunner* TimerBase::getUnthrottledTaskRunner() { |
| 91 return Platform::current()->currentThread()->getWebTaskRunner(); | 95 return Platform::current()->currentThread()->getWebTaskRunner(); |
| 92 } | 96 } |
| 93 | 97 |
| 94 WebTaskRunner* TimerBase::timerTaskRunner() const { | 98 WebTaskRunner* TimerBase::timerTaskRunner() const { |
| 95 return m_webTaskRunner.get(); | 99 return m_webTaskRunner.get(); |
| 96 } | 100 } |
| 97 | 101 |
| 98 void TimerBase::setNextFireTime(double now, double delay) { | 102 void TimerBase::setNextFireTime(double now, double delay) { |
| 99 ASSERT(m_thread == currentThread()); | 103 #if DCHECK_IS_ON() |
| 104 DCHECK(m_thread == currentThread()); | |
| 105 #endif | |
| 100 | 106 |
| 101 double newTime = now + delay; | 107 double newTime = now + delay; |
| 102 | 108 |
| 103 if (m_nextFireTime != newTime) { | 109 if (m_nextFireTime != newTime) { |
| 104 m_nextFireTime = newTime; | 110 m_nextFireTime = newTime; |
| 105 | 111 |
| 106 // Cancel any previously posted task. | 112 // Cancel any previously posted task. |
| 107 m_weakPtrFactory.revokeAll(); | 113 m_weakPtrFactory.revokeAll(); |
| 108 | 114 |
| 109 double delayMs = 1000.0 * (newTime - now); | 115 double delayMs = 1000.0 * (newTime - now); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 const TimerBase* b) const { | 153 const TimerBase* b) const { |
| 148 return a->m_nextFireTime < b->m_nextFireTime; | 154 return a->m_nextFireTime < b->m_nextFireTime; |
| 149 } | 155 } |
| 150 | 156 |
| 151 // static | 157 // static |
| 152 double TimerBase::timerMonotonicallyIncreasingTime() const { | 158 double TimerBase::timerMonotonicallyIncreasingTime() const { |
| 153 return timerTaskRunner()->monotonicallyIncreasingVirtualTimeSeconds(); | 159 return timerTaskRunner()->monotonicallyIncreasingVirtualTimeSeconds(); |
| 154 } | 160 } |
| 155 | 161 |
| 156 } // namespace blink | 162 } // namespace blink |
| OLD | NEW |