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
3 // found in the LICENSE file.
5 #ifndef ScriptStreamerThread_h
6 #define ScriptStreamerThread_h
8 #include "platform/TaskSynchronizer.h"
9 #include "public/platform/WebThread.h"
10 #include "wtf/OwnPtr.h"
18 // A singleton thread for running background tasks for script streaming.
19 class ScriptStreamerThread {
20 WTF_MAKE_NONCOPYABLE(ScriptStreamerThread);
23 static void shutdown();
24 static ScriptStreamerThread* shared();
26 void postTask(WebThread::Task*);
28 bool isRunningTask() const
30 MutexLocker locker(m_mutex);
37 ScriptStreamerThread()
38 : m_runningTask(false) { }
40 bool isRunning() const
45 blink::WebThread& platformThread();
47 // At the moment, we only use one thread, so we can only stream one script
48 // at a time. FIXME: Use a thread pool and stream multiple scripts.
49 WTF::OwnPtr<blink::WebThread> m_thread;
51 mutable Mutex m_mutex; // Guards m_runningTask.
54 class ScriptStreamingTask : public WebThread::Task {
55 WTF_MAKE_NONCOPYABLE(ScriptStreamingTask);
57 ScriptStreamingTask(WTF::PassOwnPtr<v8::ScriptCompiler::ScriptStreamingTask>, ScriptStreamer*);
58 virtual void run() override;
61 WTF::OwnPtr<v8::ScriptCompiler::ScriptStreamingTask> m_v8Task;
62 ScriptStreamer* m_streamer;
68 #endif // ScriptStreamerThread_h