OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 #ifndef ScriptStreamerThread_h | |
6 #define ScriptStreamerThread_h | |
7 | |
8 #include "platform/TaskSynchronizer.h" | |
9 #include "public/platform/WebThread.h" | |
10 #include "wtf/OwnPtr.h" | |
11 | |
12 #include <v8.h> | |
13 | |
14 namespace blink { | |
15 | |
16 class ScriptStreamer; | |
17 | |
18 // A singleton thread for running background tasks for script streaming. | |
19 class ScriptStreamerThread { | |
20 public: | |
21 static void init(); | |
22 static void shutdown(); | |
23 static ScriptStreamerThread* shared(); | |
24 | |
25 void postTask(WebThread::Task*); | |
26 | |
27 bool isRunningTask() const | |
28 { | |
29 return m_runningTask; | |
30 } | |
31 | |
32 static void taskDone(void*) | |
33 { | |
34 shared()->m_runningTask = false; | |
haraken
2014/09/10 05:57:51
Shall we add ASSERT(shared()->m_runningTask) befor
marja
2014/09/11 09:15:37
Done.
| |
35 } | |
36 | |
37 private: | |
38 ScriptStreamerThread() | |
39 : m_runningTask(false) { } | |
40 | |
41 bool isRunning() | |
42 { | |
43 return !!m_thread; | |
44 } | |
45 | |
46 void markAsCompleted(TaskSynchronizer* taskSynchronizer) | |
47 { | |
48 taskSynchronizer->taskCompleted(); | |
49 } | |
50 | |
51 blink::WebThread& platformThread(); | |
52 | |
53 // At the moment, we only use one thread, so we can only stream one script | |
54 // at a time. FIXME: Use a thread pool and stream multiple scripts. | |
55 WTF::OwnPtr<blink::WebThread> m_thread; | |
56 bool m_runningTask; | |
57 }; | |
58 | |
59 class ScriptStreamingTask : public WebThread::Task { | |
60 public: | |
61 ScriptStreamingTask(v8::ScriptCompiler::ScriptStreamingTask*, ScriptStreamer *); | |
62 virtual void run() OVERRIDE; | |
63 | |
64 private: | |
65 WTF::OwnPtr<v8::ScriptCompiler::ScriptStreamingTask> m_v8Task; | |
66 ScriptStreamer* m_streamer; | |
haraken
2014/09/10 05:57:51
Doesn't this need to be a RefPtr?
marja
2014/09/11 09:15:37
No, the code is correct as is, afaics (see the man
| |
67 }; | |
68 | |
69 | |
70 } // namespace blink | |
71 | |
72 #endif // ScriptStreamerThread_h | |
OLD | NEW |