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 #include "config.h" | |
6 #include "bindings/core/v8/ScriptStreamerThread.h" | |
7 | |
8 #include "bindings/core/v8/ScriptStreamer.h" | |
9 #include "platform/Task.h" | |
10 #include "public/platform/Platform.h" | |
11 #include "wtf/MainThread.h" | |
12 #include "wtf/PassOwnPtr.h" | |
13 | |
14 namespace blink { | |
15 | |
16 static ScriptStreamerThread* s_sharedThread = 0; | |
17 | |
18 void ScriptStreamerThread::init() | |
19 { | |
20 ASSERT(!s_sharedThread); | |
21 ASSERT(isMainThread()); | |
22 s_sharedThread = new ScriptStreamerThread(); | |
23 } | |
24 | |
25 void ScriptStreamerThread::shutdown() | |
26 { | |
27 ASSERT(s_sharedThread); | |
28 // currentThread will always be non-null in production, but can be null in | |
29 // Chromium unit tests. | |
30 if (blink::Platform::current()->currentThread() && s_sharedThread->isRunning ()) { | |
31 // The streaming task should exit soon, because the corresponding | |
32 // PendingScript should already be destroyed, and it has cancelled the | |
33 // streaming. However, the V8 side operations might still be ongoing. | |
34 // When V8 asks for more data the next time, the cancelling will take | |
35 // effect. | |
36 TaskSynchronizer taskSynchronizer; | |
37 s_sharedThread->postTask(new Task(WTF::bind(&ScriptStreamerThread::markA sCompleted, s_sharedThread, &taskSynchronizer))); | |
haraken
2014/09/10 05:57:51
It's not nice to block the shutdown sequence by wa
marja
2014/09/11 09:15:37
It doesn't make the situation worse than now: prev
| |
38 taskSynchronizer.waitForTaskCompletion(); | |
39 } | |
40 delete s_sharedThread; | |
41 s_sharedThread = 0; | |
42 } | |
43 | |
44 ScriptStreamerThread* ScriptStreamerThread::shared() | |
45 { | |
46 return s_sharedThread; | |
47 } | |
48 | |
49 void ScriptStreamerThread::postTask(WebThread::Task* task) | |
50 { | |
51 ASSERT(isMainThread()); | |
52 m_runningTask = true; | |
haraken
2014/09/10 05:57:51
Shall we add ASSERT(!m_runningTask) before this li
marja
2014/09/11 09:15:37
Done.
| |
53 platformThread().postTask(task); | |
54 } | |
55 | |
56 blink::WebThread& ScriptStreamerThread::platformThread() | |
57 { | |
58 if (!isRunning()) { | |
59 m_thread = adoptPtr(blink::Platform::current()->createThread("ScriptStre amerThread")); | |
60 } | |
61 return *m_thread; | |
62 } | |
63 | |
64 ScriptStreamingTask::ScriptStreamingTask(v8::ScriptCompiler::ScriptStreamingTask * task, ScriptStreamer* streamer) | |
65 : m_v8Task(adoptPtr(task)), m_streamer(streamer) { } | |
66 | |
67 void ScriptStreamingTask::run() | |
68 { | |
69 // Running the task can and will block: SourceStream::GetSomeData will get | |
70 // called and it will block and wait for data from the network. | |
71 m_v8Task->Run(); | |
72 // Post a task to the main thread to signal that V8 has completed the | |
73 // streaming. | |
74 callOnMainThread(&ScriptStreamerThread::taskDone, 0); | |
75 callOnMainThread(WTF::bind(&ScriptStreamer::streamingComplete, m_streamer)); | |
76 } | |
77 | |
78 } // namespace blink | |
OLD | NEW |