OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 #include "public/platform/WebScheduler.h" | |
7 | |
8 #include "public/platform/WebTraceLocation.h" | |
9 #include "wtf/Assertions.h" | |
10 #include "wtf/OwnPtr.h" | |
11 | |
12 #if OS(WIN) | |
13 #include <windows.h> | |
14 #elif OS(POSIX) | |
15 #include <unistd.h> | |
16 #endif | |
17 | |
18 namespace blink { | |
19 | |
20 namespace { | |
21 #if OS(WIN) | |
22 static_assert(sizeof(blink::PlatformThreadId) >= sizeof(DWORD), "size of platfor m thread id is too small"); | |
Sami
2015/04/16 11:22:22
What's this for?
alex clarke (OOO till 29th)
2015/04/16 13:41:36
I copied that. I think we can drop it though :)
| |
23 #elif OS(POSIX) | |
24 static_assert(sizeof(blink::PlatformThreadId) >= sizeof(pid_t), "size of platfor m thread id is too small"); | |
25 #else | |
26 #error Unexpected platform | |
27 #endif | |
28 | |
29 class TaskRunner : public WebThread::Task { | |
30 WTF_MAKE_NONCOPYABLE(TaskRunner); | |
31 | |
32 public: | |
33 explicit TaskRunner(PassOwnPtr<WebScheduler::Task> task) | |
34 : m_task(task) | |
35 { | |
36 } | |
37 | |
38 ~TaskRunner() override | |
39 { | |
40 } | |
41 | |
42 // WebThread::Task implementation. | |
43 void run() override | |
44 { | |
45 (*m_task)(); | |
46 } | |
47 private: | |
48 OwnPtr<WebScheduler::Task> m_task; | |
49 }; | |
50 | |
51 class IdleTaskRunner : public WebThread::IdleTask { | |
52 WTF_MAKE_NONCOPYABLE(IdleTaskRunner); | |
53 | |
54 public: | |
55 explicit IdleTaskRunner(PassOwnPtr<WebScheduler::IdleTask> task) | |
56 : m_task(task) | |
57 { | |
58 } | |
59 | |
60 ~IdleTaskRunner() override | |
61 { | |
62 } | |
63 | |
64 // WebThread::IdleTask implementation. | |
65 void run(double deadlineSeconds) override | |
66 { | |
67 (*m_task)(deadlineSeconds); | |
68 } | |
69 private: | |
70 OwnPtr<WebScheduler::IdleTask> m_task; | |
71 }; | |
72 | |
73 } // namespace | |
74 | |
75 void WebScheduler::postIdleTask(const WebTraceLocation& location, PassOwnPtr<Idl eTask> idleTask) | |
76 { | |
77 postIdleTask(location, new IdleTaskRunner(idleTask)); | |
78 } | |
79 | |
80 void WebScheduler::postNonNestableIdleTask(const WebTraceLocation& location, Pas sOwnPtr<IdleTask> idleTask) | |
81 { | |
82 postNonNestableIdleTask(location, new IdleTaskRunner(idleTask)); | |
83 } | |
84 | |
85 void WebScheduler::postIdleTaskAfterWakeup(const WebTraceLocation& location, Pas sOwnPtr<IdleTask> idleTask) | |
86 { | |
87 postIdleTaskAfterWakeup(location, new IdleTaskRunner(idleTask)); | |
88 } | |
89 | |
90 void WebScheduler::postLoadingTask(const WebTraceLocation& location, PassOwnPtr< Task> task) | |
91 { | |
92 postLoadingTask(location, new TaskRunner(task)); | |
93 } | |
94 | |
95 } // namespace blink | |
OLD | NEW |