OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "bindings/core/v8/ScriptStreamerThread.h" | 5 #include "bindings/core/v8/ScriptStreamerThread.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptStreamer.h" | 7 #include "bindings/core/v8/ScriptStreamer.h" |
8 #include "core/inspector/InspectorTraceEvents.h" | 8 #include "core/inspector/InspectorTraceEvents.h" |
9 #include "platform/TraceEvent.h" | 9 #include "platform/TraceEvent.h" |
10 #include "public/platform/Platform.h" | 10 #include "public/platform/Platform.h" |
11 #include "public/platform/WebTaskRunner.h" | 11 #include "public/platform/WebTaskRunner.h" |
12 #include "public/platform/WebTraceLocation.h" | 12 #include "public/platform/WebTraceLocation.h" |
13 #include "wtf/PtrUtil.h" | |
14 #include <memory> | |
15 | 13 |
16 namespace blink { | 14 namespace blink { |
17 | 15 |
18 static ScriptStreamerThread* s_sharedThread = 0; | 16 static ScriptStreamerThread* s_sharedThread = 0; |
19 // Guards s_sharedThread. s_sharedThread is initialized and deleted in the main | 17 // Guards s_sharedThread. s_sharedThread is initialized and deleted in the main |
20 // thread, but also used by the streamer thread. Races can occur during | 18 // thread, but also used by the streamer thread. Races can occur during |
21 // shutdown. | 19 // shutdown. |
22 static Mutex* s_mutex = 0; | 20 static Mutex* s_mutex = 0; |
23 | 21 |
24 void ScriptStreamerThread::init() | 22 void ScriptStreamerThread::init() |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 void ScriptStreamerThread::taskDone() | 65 void ScriptStreamerThread::taskDone() |
68 { | 66 { |
69 MutexLocker locker(m_mutex); | 67 MutexLocker locker(m_mutex); |
70 ASSERT(m_runningTask); | 68 ASSERT(m_runningTask); |
71 m_runningTask = false; | 69 m_runningTask = false; |
72 } | 70 } |
73 | 71 |
74 WebThread& ScriptStreamerThread::platformThread() | 72 WebThread& ScriptStreamerThread::platformThread() |
75 { | 73 { |
76 if (!isRunning()) | 74 if (!isRunning()) |
77 m_thread = wrapUnique(Platform::current()->createThread("ScriptStreamerT
hread")); | 75 m_thread = adoptPtr(Platform::current()->createThread("ScriptStreamerThr
ead")); |
78 return *m_thread; | 76 return *m_thread; |
79 } | 77 } |
80 | 78 |
81 void ScriptStreamerThread::runScriptStreamingTask(std::unique_ptr<v8::ScriptComp
iler::ScriptStreamingTask> task, ScriptStreamer* streamer) | 79 void ScriptStreamerThread::runScriptStreamingTask(PassOwnPtr<v8::ScriptCompiler:
:ScriptStreamingTask> task, ScriptStreamer* streamer) |
82 { | 80 { |
83 TRACE_EVENT1("v8,devtools.timeline", "v8.parseOnBackground", "data", Inspect
orParseScriptEvent::data(streamer->scriptResourceIdentifier(), streamer->scriptU
RLString())); | 81 TRACE_EVENT1("v8,devtools.timeline", "v8.parseOnBackground", "data", Inspect
orParseScriptEvent::data(streamer->scriptResourceIdentifier(), streamer->scriptU
RLString())); |
84 // Running the task can and will block: SourceStream::GetSomeData will get | 82 // Running the task can and will block: SourceStream::GetSomeData will get |
85 // called and it will block and wait for data from the network. | 83 // called and it will block and wait for data from the network. |
86 task->Run(); | 84 task->Run(); |
87 streamer->streamingCompleteOnBackgroundThread(); | 85 streamer->streamingCompleteOnBackgroundThread(); |
88 MutexLocker locker(*s_mutex); | 86 MutexLocker locker(*s_mutex); |
89 ScriptStreamerThread* thread = shared(); | 87 ScriptStreamerThread* thread = shared(); |
90 if (thread) | 88 if (thread) |
91 thread->taskDone(); | 89 thread->taskDone(); |
92 // If thread is 0, we're shutting down. | 90 // If thread is 0, we're shutting down. |
93 } | 91 } |
94 | 92 |
95 } // namespace blink | 93 } // namespace blink |
OLD | NEW |