Don't consider a Bluetooth adapter present until it has an address.
[chromium-blink-merge.git] / cc / CCTimer.cpp
blob52222b71dda8a64179620d8a568af0b60e3358d1
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
3 // found in the LICENSE file.
5 #include "config.h"
7 #include "CCTimer.h"
9 #include "CCThread.h"
11 namespace WebCore {
13 class CCTimerTask : public CCThread::Task {
14 public:
15 explicit CCTimerTask(CCTimer* timer)
16 : CCThread::Task(0)
17 , m_timer(timer)
21 ~CCTimerTask()
23 if (!m_timer)
24 return;
26 ASSERT(m_timer->m_task == this);
27 m_timer->stop();
30 void performTask()
32 if (!m_timer)
33 return;
35 CCTimerClient* client = m_timer->m_client;
37 m_timer->stop();
38 if (client)
39 client->onTimerFired();
42 private:
43 friend class CCTimer;
45 CCTimer* m_timer; // null if cancelled
48 CCTimer::CCTimer(CCThread* thread, CCTimerClient* client)
49 : m_client(client)
50 , m_thread(thread)
51 , m_task(0)
55 CCTimer::~CCTimer()
57 stop();
60 void CCTimer::startOneShot(double intervalSeconds)
62 stop();
64 m_task = new CCTimerTask(this);
66 // The thread expects delays in milliseconds.
67 m_thread->postDelayedTask(adoptPtr(m_task), intervalSeconds * 1000.0);
70 void CCTimer::stop()
72 if (!m_task)
73 return;
75 m_task->m_timer = 0;
76 m_task = 0;
79 } // namespace WebCore