| 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 #ifndef ScriptStreamerThread_h | 5 #ifndef ScriptStreamerThread_h |
| 6 #define ScriptStreamerThread_h | 6 #define ScriptStreamerThread_h |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "core/CoreExport.h" | 10 #include "core/CoreExport.h" |
| 11 #include "platform/wtf/Functional.h" | 11 #include "platform/wtf/Functional.h" |
| 12 #include "platform/wtf/ThreadingPrimitives.h" | 12 #include "platform/wtf/ThreadingPrimitives.h" |
| 13 #include "public/platform/WebThread.h" | 13 #include "public/platform/WebThread.h" |
| 14 #include "v8/include/v8.h" | 14 #include "v8/include/v8.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 class ScriptStreamer; | 18 class ScriptStreamerImpl; |
| 19 | 19 |
| 20 // A singleton thread for running background tasks for script streaming. | 20 // A singleton thread for running background tasks for script streaming. |
| 21 class CORE_EXPORT ScriptStreamerThread { | 21 class CORE_EXPORT ScriptStreamerThread { |
| 22 USING_FAST_MALLOC(ScriptStreamerThread); | 22 USING_FAST_MALLOC(ScriptStreamerThread); |
| 23 WTF_MAKE_NONCOPYABLE(ScriptStreamerThread); | 23 WTF_MAKE_NONCOPYABLE(ScriptStreamerThread); |
| 24 | 24 |
| 25 public: | 25 public: |
| 26 static void Init(); | 26 static void Init(); |
| 27 static ScriptStreamerThread* Shared(); | 27 static ScriptStreamerThread* Shared(); |
| 28 | 28 |
| 29 void PostTask(std::unique_ptr<CrossThreadClosure>); | 29 void PostTask(std::unique_ptr<CrossThreadClosure>); |
| 30 | 30 |
| 31 bool IsRunningTask() const { | 31 bool IsRunningTask() const { |
| 32 MutexLocker locker(mutex_); | 32 MutexLocker locker(mutex_); |
| 33 return running_task_; | 33 return running_task_; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void TaskDone(); | 36 void TaskDone(); |
| 37 | 37 |
| 38 static void RunScriptStreamingTask( | 38 static void RunScriptStreamingTask( |
| 39 std::unique_ptr<v8::ScriptCompiler::ScriptStreamingTask>, | 39 std::unique_ptr<v8::ScriptCompiler::ScriptStreamingTask>, |
| 40 ScriptStreamer*); | 40 ScriptStreamerImpl*); |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 ScriptStreamerThread() : running_task_(false) {} | 43 ScriptStreamerThread() : running_task_(false) {} |
| 44 | 44 |
| 45 bool IsRunning() const { return !!thread_; } | 45 bool IsRunning() const { return !!thread_; } |
| 46 | 46 |
| 47 WebThread& PlatformThread(); | 47 WebThread& PlatformThread(); |
| 48 | 48 |
| 49 // At the moment, we only use one thread, so we can only stream one script | 49 // At the moment, we only use one thread, so we can only stream one script |
| 50 // at a time. FIXME: Use a thread pool and stream multiple scripts. | 50 // at a time. FIXME: Use a thread pool and stream multiple scripts. |
| 51 std::unique_ptr<WebThread> thread_; | 51 std::unique_ptr<WebThread> thread_; |
| 52 bool running_task_; | 52 bool running_task_; |
| 53 mutable Mutex mutex_; // Guards m_runningTask. | 53 mutable Mutex mutex_; // Guards m_runningTask. |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 } // namespace blink | 56 } // namespace blink |
| 57 | 57 |
| 58 #endif // ScriptStreamerThread_h | 58 #endif // ScriptStreamerThread_h |
| OLD | NEW |