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 delete s_sharedThread; |
| 29 s_sharedThread = 0; |
| 30 } |
| 31 |
| 32 ScriptStreamerThread* ScriptStreamerThread::shared() |
| 33 { |
| 34 return s_sharedThread; |
| 35 } |
| 36 |
| 37 void ScriptStreamerThread::postTask(WebThread::Task* task) |
| 38 { |
| 39 ASSERT(isMainThread()); |
| 40 ASSERT(!m_runningTask); |
| 41 m_runningTask = true; |
| 42 platformThread().postTask(task); |
| 43 } |
| 44 |
| 45 blink::WebThread& ScriptStreamerThread::platformThread() |
| 46 { |
| 47 if (!isRunning()) |
| 48 m_thread = adoptPtr(blink::Platform::current()->createThread("ScriptStre
amerThread")); |
| 49 return *m_thread; |
| 50 } |
| 51 |
| 52 ScriptStreamingTask::ScriptStreamingTask(v8::ScriptCompiler::ScriptStreamingTask
* task, ScriptStreamer* streamer) |
| 53 : m_v8Task(adoptPtr(task)), m_streamer(streamer) { } |
| 54 |
| 55 void ScriptStreamingTask::run() |
| 56 { |
| 57 // Running the task can and will block: SourceStream::GetSomeData will get |
| 58 // called and it will block and wait for data from the network. |
| 59 m_v8Task->Run(); |
| 60 // Post a task to the main thread to signal that V8 has completed the |
| 61 // streaming. |
| 62 callOnMainThread(&ScriptStreamerThread::taskDone, 0); |
| 63 callOnMainThread(WTF::bind(&ScriptStreamer::streamingComplete, m_streamer)); |
| 64 } |
| 65 |
| 66 } // namespace blink |
OLD | NEW |