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 "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "platform/TaskSynchronizer.h" | 9 #include "platform/TaskSynchronizer.h" |
10 #include "public/platform/WebThread.h" | 10 #include "public/platform/WebThread.h" |
11 #include "wtf/Functional.h" | 11 #include "wtf/Functional.h" |
12 #include <memory> | 12 #include "wtf/OwnPtr.h" |
| 13 #include "wtf/PassOwnPtr.h" |
| 14 |
13 #include <v8.h> | 15 #include <v8.h> |
14 | 16 |
15 namespace blink { | 17 namespace blink { |
16 | 18 |
17 class ScriptStreamer; | 19 class ScriptStreamer; |
18 | 20 |
19 // A singleton thread for running background tasks for script streaming. | 21 // A singleton thread for running background tasks for script streaming. |
20 class CORE_EXPORT ScriptStreamerThread { | 22 class CORE_EXPORT ScriptStreamerThread { |
21 USING_FAST_MALLOC(ScriptStreamerThread); | 23 USING_FAST_MALLOC(ScriptStreamerThread); |
22 WTF_MAKE_NONCOPYABLE(ScriptStreamerThread); | 24 WTF_MAKE_NONCOPYABLE(ScriptStreamerThread); |
23 public: | 25 public: |
24 static void init(); | 26 static void init(); |
25 static void shutdown(); | 27 static void shutdown(); |
26 static ScriptStreamerThread* shared(); | 28 static ScriptStreamerThread* shared(); |
27 | 29 |
28 void postTask(std::unique_ptr<CrossThreadClosure>); | 30 void postTask(std::unique_ptr<CrossThreadClosure>); |
29 | 31 |
30 bool isRunningTask() const | 32 bool isRunningTask() const |
31 { | 33 { |
32 MutexLocker locker(m_mutex); | 34 MutexLocker locker(m_mutex); |
33 return m_runningTask; | 35 return m_runningTask; |
34 } | 36 } |
35 | 37 |
36 void taskDone(); | 38 void taskDone(); |
37 | 39 |
38 static void runScriptStreamingTask(std::unique_ptr<v8::ScriptCompiler::Scrip
tStreamingTask>, ScriptStreamer*); | 40 static void runScriptStreamingTask(PassOwnPtr<v8::ScriptCompiler::ScriptStre
amingTask>, ScriptStreamer*); |
39 | 41 |
40 private: | 42 private: |
41 ScriptStreamerThread() | 43 ScriptStreamerThread() |
42 : m_runningTask(false) { } | 44 : m_runningTask(false) { } |
43 | 45 |
44 bool isRunning() const | 46 bool isRunning() const |
45 { | 47 { |
46 return !!m_thread; | 48 return !!m_thread; |
47 } | 49 } |
48 | 50 |
49 WebThread& platformThread(); | 51 WebThread& platformThread(); |
50 | 52 |
51 // At the moment, we only use one thread, so we can only stream one script | 53 // At the moment, we only use one thread, so we can only stream one script |
52 // at a time. FIXME: Use a thread pool and stream multiple scripts. | 54 // at a time. FIXME: Use a thread pool and stream multiple scripts. |
53 std::unique_ptr<WebThread> m_thread; | 55 OwnPtr<WebThread> m_thread; |
54 bool m_runningTask; | 56 bool m_runningTask; |
55 mutable Mutex m_mutex; // Guards m_runningTask. | 57 mutable Mutex m_mutex; // Guards m_runningTask. |
56 }; | 58 }; |
57 | 59 |
58 } // namespace blink | 60 } // namespace blink |
59 | 61 |
60 #endif // ScriptStreamerThread_h | 62 #endif // ScriptStreamerThread_h |
OLD | NEW |