| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "CCTimer.h" | 7 #include "CCTimer.h" |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "CCThread.h" | 10 #include "CCThread.h" |
| 11 | 11 |
| 12 namespace cc { | 12 namespace cc { |
| 13 | 13 |
| 14 class CCTimerTask : public CCThread::Task { | 14 class TimerTask : public Thread::Task { |
| 15 public: | 15 public: |
| 16 explicit CCTimerTask(CCTimer* timer) | 16 explicit TimerTask(Timer* timer) |
| 17 : CCThread::Task(0) | 17 : Thread::Task(0) |
| 18 , m_timer(timer) | 18 , m_timer(timer) |
| 19 { | 19 { |
| 20 } | 20 } |
| 21 | 21 |
| 22 virtual ~CCTimerTask() | 22 virtual ~TimerTask() |
| 23 { | 23 { |
| 24 if (!m_timer) | 24 if (!m_timer) |
| 25 return; | 25 return; |
| 26 | 26 |
| 27 ASSERT(m_timer->m_task == this); | 27 ASSERT(m_timer->m_task == this); |
| 28 m_timer->stop(); | 28 m_timer->stop(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 virtual void performTask() OVERRIDE | 31 virtual void performTask() OVERRIDE |
| 32 { | 32 { |
| 33 if (!m_timer) | 33 if (!m_timer) |
| 34 return; | 34 return; |
| 35 | 35 |
| 36 CCTimerClient* client = m_timer->m_client; | 36 TimerClient* client = m_timer->m_client; |
| 37 | 37 |
| 38 m_timer->stop(); | 38 m_timer->stop(); |
| 39 if (client) | 39 if (client) |
| 40 client->onTimerFired(); | 40 client->onTimerFired(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 friend class CCTimer; | 44 friend class Timer; |
| 45 | 45 |
| 46 CCTimer* m_timer; // null if cancelled | 46 Timer* m_timer; // null if cancelled |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 CCTimer::CCTimer(CCThread* thread, CCTimerClient* client) | 49 Timer::Timer(Thread* thread, TimerClient* client) |
| 50 : m_client(client) | 50 : m_client(client) |
| 51 , m_thread(thread) | 51 , m_thread(thread) |
| 52 , m_task(0) | 52 , m_task(0) |
| 53 { | 53 { |
| 54 } | 54 } |
| 55 | 55 |
| 56 CCTimer::~CCTimer() | 56 Timer::~Timer() |
| 57 { | 57 { |
| 58 stop(); | 58 stop(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void CCTimer::startOneShot(double intervalSeconds) | 61 void Timer::startOneShot(double intervalSeconds) |
| 62 { | 62 { |
| 63 stop(); | 63 stop(); |
| 64 | 64 |
| 65 m_task = new CCTimerTask(this); | 65 m_task = new TimerTask(this); |
| 66 | 66 |
| 67 // The thread expects delays in milliseconds. | 67 // The thread expects delays in milliseconds. |
| 68 m_thread->postDelayedTask(adoptPtr(m_task), intervalSeconds * 1000.0); | 68 m_thread->postDelayedTask(adoptPtr(m_task), intervalSeconds * 1000.0); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void CCTimer::stop() | 71 void Timer::stop() |
| 72 { | 72 { |
| 73 if (!m_task) | 73 if (!m_task) |
| 74 return; | 74 return; |
| 75 | 75 |
| 76 m_task->m_timer = 0; | 76 m_task->m_timer = 0; |
| 77 m_task = 0; | 77 m_task = 0; |
| 78 } | 78 } |
| 79 | 79 |
| 80 } // namespace cc | 80 } // namespace cc |
| OLD | NEW |