Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | |
|
haraken
2014/08/17 16:05:27
Nit: Use the 3-line copyright.
marja
2014/08/20 11:45:56
Done.
| |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | |
| 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
| 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | |
| 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
| 23 * THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #include "config.h" | |
| 27 #include "bindings/core/v8/V8ScriptStreamerThread.h" | |
| 28 | |
| 29 #include "bindings/core/v8/V8ScriptStreamer.h" | |
| 30 #include "platform/Task.h" | |
| 31 #include "public/platform/Platform.h" | |
| 32 #include "wtf/MainThread.h" | |
| 33 #include "wtf/PassOwnPtr.h" | |
| 34 | |
| 35 namespace blink { | |
| 36 | |
| 37 static V8ScriptStreamerThread* s_sharedThread = 0; | |
| 38 | |
| 39 void V8ScriptStreamerThread::init() | |
| 40 { | |
| 41 ASSERT(!s_sharedThread); | |
|
haraken
2014/08/17 16:05:27
Add ASSERT(isMainThread()).
marja
2014/08/20 11:45:56
Done.
| |
| 42 s_sharedThread = new V8ScriptStreamerThread(); | |
| 43 } | |
| 44 | |
| 45 void V8ScriptStreamerThread::shutdown() | |
| 46 { | |
| 47 ASSERT(s_sharedThread); | |
|
haraken
2014/08/17 16:05:27
Add ASSERT(isMainThread()).
marja
2014/08/20 11:45:56
That doesn't seem to be true. :/ It's not true in
haraken
2014/08/20 15:00:18
OK :)
| |
| 48 // currentThread will always be non-null in production, but can be null in | |
| 49 // Chromium unit tests. | |
| 50 if (blink::Platform::current()->currentThread() && s_sharedThread->isRunning () | |
| 51 && s_sharedThread->isRunningTask()) { | |
|
haraken
2014/08/17 16:05:27
Why is the s_sharedThread->isRunningTask() check n
marja
2014/08/20 11:45:56
Can't it be that Blink is ramping down but the V8
haraken
2014/08/20 15:00:18
I agree that it's possible that the streaming thre
marja
2014/09/09 17:00:26
Yes, I don't think it's safe either, and that's wh
| |
| 52 // The streaming task should exit soon, because the corresponding | |
| 53 // PendingScript should already be destroyed, and it has cancelled the | |
| 54 // streaming. However, the V8 side operations might still be ongoing. | |
| 55 // When V8 asks for more data the next time, the cancelling will take | |
| 56 // effect. | |
| 57 TaskSynchronizer taskSynchronizer; | |
| 58 s_sharedThread->postTask(new Task(WTF::bind(&V8ScriptStreamerThread::mar kAsCompleted, s_sharedThread, &taskSynchronizer))); | |
| 59 taskSynchronizer.waitForTaskCompletion(); | |
| 60 } | |
| 61 delete s_sharedThread; | |
| 62 s_sharedThread = 0; | |
| 63 } | |
| 64 | |
| 65 V8ScriptStreamerThread* V8ScriptStreamerThread::shared() | |
| 66 { | |
| 67 return s_sharedThread; | |
| 68 } | |
| 69 | |
| 70 void V8ScriptStreamerThread::postTask(WebThread::Task* task) | |
| 71 { | |
| 72 m_runningTask = true; | |
|
haraken
2014/08/17 16:05:27
Add ASSERT(isMainThread()).
marja
2014/08/20 11:45:56
Done.
| |
| 73 platformThread().postTask(task); | |
| 74 } | |
| 75 | |
| 76 blink::WebThread& V8ScriptStreamerThread::platformThread() | |
| 77 { | |
| 78 if (!isRunning()) { | |
| 79 m_thread = adoptPtr(blink::Platform::current()->createThread("V8ScriptSt reamerThread")); | |
| 80 } | |
| 81 return *m_thread; | |
| 82 } | |
| 83 | |
| 84 ScriptStreamingTask::ScriptStreamingTask(v8::ScriptCompiler::ScriptStreamingTask * task, V8ScriptStreamer* streamer) | |
| 85 : m_v8Task(adoptPtr(task)), m_streamer(streamer) { } | |
| 86 | |
| 87 void ScriptStreamingTask::run() | |
| 88 { | |
| 89 // Running the task can and will block: SourceStream::GetSomeData will get | |
| 90 // called and it will block and wait for data from the network. | |
| 91 m_v8Task->Run(); | |
| 92 // Post a task to the main thread to signal that V8 has completed the | |
| 93 // streaming. | |
| 94 callOnMainThread(&V8ScriptStreamerThread::taskDone, 0); | |
| 95 callOnMainThread(WTF::bind(&V8ScriptStreamer::streamingComplete, m_streamer) ); | |
| 96 } | |
| 97 | |
| 98 } // namespace blink | |
| OLD | NEW |