Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: cc/timer.cc

Issue 11344004: Remove WebKit::Platform dependencies from cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix webkit_compositor_bindings_unittests Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/timer.h ('k') | cc/timer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "config.h"
6
7 #include "cc/timer.h"
8
9 #include "base/compiler_specific.h"
10 #include "base/logging.h"
11 #include "cc/thread.h"
12
13 namespace cc {
14
15 class TimerTask : public Thread::Task {
16 public:
17 explicit TimerTask(Timer* timer)
18 : Thread::Task(0)
19 , m_timer(timer)
20 {
21 }
22
23 virtual ~TimerTask()
24 {
25 if (!m_timer)
26 return;
27
28 DCHECK(m_timer->m_task == this);
29 m_timer->stop();
30 }
31
32 virtual void performTask() OVERRIDE
33 {
34 if (!m_timer)
35 return;
36
37 TimerClient* client = m_timer->m_client;
38
39 m_timer->stop();
40 if (client)
41 client->onTimerFired();
42 }
43
44 private:
45 friend class Timer;
46
47 Timer* m_timer; // null if cancelled
48 };
49
50 Timer::Timer(Thread* thread, TimerClient* client)
51 : m_client(client)
52 , m_thread(thread)
53 , m_task(0)
54 {
55 }
56
57 Timer::~Timer()
58 {
59 stop();
60 }
61
62 void Timer::startOneShot(double intervalSeconds)
63 {
64 stop();
65
66 m_task = new TimerTask(this);
67
68 // The thread expects delays in milliseconds.
69 m_thread->postDelayedTask(adoptPtr(m_task), intervalSeconds * 1000.0);
70 }
71
72 void Timer::stop()
73 {
74 if (!m_task)
75 return;
76
77 m_task->m_timer = 0;
78 m_task = 0;
79 }
80
81 } // namespace cc
OLDNEW
« no previous file with comments | « cc/timer.h ('k') | cc/timer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698