| 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 "platform/Task.h" | |
| 9 #include "platform/TraceEvent.h" | 8 #include "platform/TraceEvent.h" |
| 10 #include "public/platform/Platform.h" | 9 #include "public/platform/Platform.h" |
| 10 #include "public/platform/WebTaskRunner.h" |
| 11 #include "public/platform/WebTraceLocation.h" | 11 #include "public/platform/WebTraceLocation.h" |
| 12 #include "wtf/MainThread.h" | 12 #include "wtf/MainThread.h" |
| 13 #include "wtf/PassOwnPtr.h" | |
| 14 | 13 |
| 15 namespace blink { | 14 namespace blink { |
| 16 | 15 |
| 17 static ScriptStreamerThread* s_sharedThread = 0; | 16 static ScriptStreamerThread* s_sharedThread = 0; |
| 18 // 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 |
| 19 // 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 |
| 20 // shutdown. | 19 // shutdown. |
| 21 static Mutex* s_mutex = 0; | 20 static Mutex* s_mutex = 0; |
| 22 | 21 |
| 23 void ScriptStreamerThread::init() | 22 void ScriptStreamerThread::init() |
| (...skipping 23 matching lines...) Expand all Loading... |
| 47 // Now it's safe to delete s_mutex, since there are no tasks that could | 46 // Now it's safe to delete s_mutex, since there are no tasks that could |
| 48 // access it later. | 47 // access it later. |
| 49 delete s_mutex; | 48 delete s_mutex; |
| 50 } | 49 } |
| 51 | 50 |
| 52 ScriptStreamerThread* ScriptStreamerThread::shared() | 51 ScriptStreamerThread* ScriptStreamerThread::shared() |
| 53 { | 52 { |
| 54 return s_sharedThread; | 53 return s_sharedThread; |
| 55 } | 54 } |
| 56 | 55 |
| 57 void ScriptStreamerThread::postTask(WebTaskRunner::Task* task) | 56 void ScriptStreamerThread::postTask(PassOwnPtr<Closure> task) |
| 58 { | 57 { |
| 59 ASSERT(isMainThread()); | 58 ASSERT(isMainThread()); |
| 60 MutexLocker locker(m_mutex); | 59 MutexLocker locker(m_mutex); |
| 61 ASSERT(!m_runningTask); | 60 ASSERT(!m_runningTask); |
| 62 m_runningTask = true; | 61 m_runningTask = true; |
| 63 platformThread().taskRunner()->postTask(BLINK_FROM_HERE, task); | 62 platformThread().taskRunner()->postTask(BLINK_FROM_HERE, task); |
| 64 } | 63 } |
| 65 | 64 |
| 66 void ScriptStreamerThread::taskDone() | 65 void ScriptStreamerThread::taskDone() |
| 67 { | 66 { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 85 task->Run(); | 84 task->Run(); |
| 86 streamer->streamingCompleteOnBackgroundThread(); | 85 streamer->streamingCompleteOnBackgroundThread(); |
| 87 MutexLocker locker(*s_mutex); | 86 MutexLocker locker(*s_mutex); |
| 88 ScriptStreamerThread* thread = shared(); | 87 ScriptStreamerThread* thread = shared(); |
| 89 if (thread) | 88 if (thread) |
| 90 thread->taskDone(); | 89 thread->taskDone(); |
| 91 // If thread is 0, we're shutting down. | 90 // If thread is 0, we're shutting down. |
| 92 } | 91 } |
| 93 | 92 |
| 94 } // namespace blink | 93 } // namespace blink |
| OLD | NEW |