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; | |
jochen (gone - plz use gerrit)
2014/09/11 12:45:08
you don't need the task synchronizer, the delete s
marja
2014/09/15 17:45:26
Hmm, looks like WebThreadImpl dtor indeed waits.
| |
37 s_sharedThread->postTask(new Task(WTF::bind(&ScriptStreamerThread::markA sCompleted, s_sharedThread, &taskSynchronizer))); | |
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 ASSERT(!m_runningTask); | |
53 m_runningTask = true; | |
54 platformThread().postTask(task); | |
55 } | |
56 | |
57 blink::WebThread& ScriptStreamerThread::platformThread() | |
58 { | |
59 if (!isRunning()) { | |
60 m_thread = adoptPtr(blink::Platform::current()->createThread("ScriptStre amerThread")); | |
61 } | |
62 return *m_thread; | |
63 } | |
64 | |
65 ScriptStreamingTask::ScriptStreamingTask(v8::ScriptCompiler::ScriptStreamingTask * task, ScriptStreamer* streamer) | |
66 : m_v8Task(adoptPtr(task)), m_streamer(streamer) { } | |
67 | |
68 void ScriptStreamingTask::run() | |
69 { | |
70 // Running the task can and will block: SourceStream::GetSomeData will get | |
71 // called and it will block and wait for data from the network. | |
72 m_v8Task->Run(); | |
73 // Post a task to the main thread to signal that V8 has completed the | |
74 // streaming. | |
75 callOnMainThread(&ScriptStreamerThread::taskDone, 0); | |
76 callOnMainThread(WTF::bind(&ScriptStreamer::streamingComplete, m_streamer)); | |
77 } | |
78 | |
79 } // namespace blink | |
OLD | NEW |