Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(746)

Unified Diff: Source/core/workers/WorkerScript.cpp

Issue 1115923002: workers: Rename WorkerThread to WorkerScript. Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/workers/WorkerScript.cpp
diff --git a/Source/core/workers/WorkerThread.cpp b/Source/core/workers/WorkerScript.cpp
similarity index 74%
rename from Source/core/workers/WorkerThread.cpp
rename to Source/core/workers/WorkerScript.cpp
index d8f75cc105c1285c6f3df3d80327ff396782a07a..c4cceccaf18ed32fe94b1ec77a7f892018db68be 100644
--- a/Source/core/workers/WorkerThread.cpp
+++ b/Source/core/workers/WorkerScript.cpp
@@ -26,7 +26,7 @@
#include "config.h"
-#include "core/workers/WorkerThread.h"
+#include "core/workers/WorkerScript.h"
#include "bindings/core/v8/ScriptSourceCode.h"
#include "bindings/core/v8/V8GCController.h"
@@ -37,7 +37,7 @@
#include "core/workers/DedicatedWorkerGlobalScope.h"
#include "core/workers/WorkerClients.h"
#include "core/workers/WorkerReportingProxy.h"
-#include "core/workers/WorkerThreadStartupData.h"
+#include "core/workers/WorkerScriptStartupData.h"
#include "platform/PlatformThreadData.h"
#include "platform/Task.h"
#include "platform/ThreadSafeFunctional.h"
@@ -60,8 +60,8 @@ const int64_t kLongIdleHandlerDelayMs = 10*1000;
class MicrotaskRunner : public WebThread::TaskObserver {
public:
- explicit MicrotaskRunner(WorkerThread* workerThread)
- : m_workerThread(workerThread)
+ explicit MicrotaskRunner(WorkerScript* workerScript)
+ : m_workerScript(workerScript)
{
}
@@ -69,8 +69,8 @@ public:
virtual void didProcessTask() override
{
Microtask::performCheckpoint();
- if (WorkerGlobalScope* globalScope = m_workerThread->workerGlobalScope()) {
- if (WorkerScriptController* scriptController = globalScope->script())
+ if (WorkerGlobalScope* globalScope = m_workerScript->workerGlobalScope()) {
+ if (WorkerScriptController* scriptController = globalScope->scriptController())
scriptController->rejectedPromises()->processQueue();
}
}
@@ -78,7 +78,7 @@ public:
private:
// Thread owns the microtask runner; reference remains
// valid for the lifetime of this object.
- WorkerThread* m_workerThread;
+ WorkerScript* m_workerScript;
};
} // namespace
@@ -89,27 +89,27 @@ static Mutex& threadSetMutex()
return mutex;
}
-static HashSet<WorkerThread*>& workerThreads()
+static HashSet<WorkerScript*>& workerScripts()
{
- DEFINE_STATIC_LOCAL(HashSet<WorkerThread*>, threads, ());
+ DEFINE_STATIC_LOCAL(HashSet<WorkerScript*>, threads, ());
return threads;
}
-unsigned WorkerThread::workerThreadCount()
+unsigned WorkerScript::workerScriptCount()
{
MutexLocker lock(threadSetMutex());
- return workerThreads().size();
+ return workerScripts().size();
}
-class WorkerThreadCancelableTask final : public ExecutionContextTask {
- WTF_MAKE_NONCOPYABLE(WorkerThreadCancelableTask); WTF_MAKE_FAST_ALLOCATED(WorkerThreadCancelableTask);
+class WorkerScriptCancelableTask final : public ExecutionContextTask {
+ WTF_MAKE_NONCOPYABLE(WorkerScriptCancelableTask); WTF_MAKE_FAST_ALLOCATED(WorkerScriptCancelableTask);
public:
- static PassOwnPtr<WorkerThreadCancelableTask> create(PassOwnPtr<Closure> closure)
+ static PassOwnPtr<WorkerScriptCancelableTask> create(PassOwnPtr<Closure> closure)
{
- return adoptPtr(new WorkerThreadCancelableTask(closure));
+ return adoptPtr(new WorkerScriptCancelableTask(closure));
}
- virtual ~WorkerThreadCancelableTask() { }
+ virtual ~WorkerScriptCancelableTask() { }
virtual void performTask(ExecutionContext*) override
{
@@ -117,25 +117,25 @@ public:
(*m_closure)();
}
- WeakPtr<WorkerThreadCancelableTask> createWeakPtr() { return m_weakFactory.createWeakPtr(); }
+ WeakPtr<WorkerScriptCancelableTask> createWeakPtr() { return m_weakFactory.createWeakPtr(); }
void cancelTask() { m_taskCanceled = true; }
private:
- explicit WorkerThreadCancelableTask(PassOwnPtr<Closure> closure)
+ explicit WorkerScriptCancelableTask(PassOwnPtr<Closure> closure)
: m_closure(closure)
, m_weakFactory(this)
, m_taskCanceled(false)
{ }
OwnPtr<Closure> m_closure;
- WeakPtrFactory<WorkerThreadCancelableTask> m_weakFactory;
+ WeakPtrFactory<WorkerScriptCancelableTask> m_weakFactory;
bool m_taskCanceled;
};
class WorkerSharedTimer : public SharedTimer {
public:
- explicit WorkerSharedTimer(WorkerThread* workerThread)
- : m_workerThread(workerThread)
+ explicit WorkerSharedTimer(WorkerScript* workerScript)
+ : m_workerScript(workerScript)
, m_running(false)
{ }
@@ -163,9 +163,9 @@ public:
m_lastQueuedTask->cancelTask();
// Now queue the task as a cancellable one.
- OwnPtr<WorkerThreadCancelableTask> task = WorkerThreadCancelableTask::create(bind(&WorkerSharedTimer::OnTimeout, this));
+ OwnPtr<WorkerScriptCancelableTask> task = WorkerScriptCancelableTask::create(bind(&WorkerSharedTimer::OnTimeout, this));
m_lastQueuedTask = task->createWeakPtr();
- m_workerThread->postDelayedTask(FROM_HERE, task.release(), delay);
+ m_workerScript->postDelayedTask(FROM_HERE, task.release(), delay);
}
virtual void stop()
@@ -177,37 +177,37 @@ public:
private:
void OnTimeout()
{
- ASSERT(m_workerThread->workerGlobalScope());
+ ASSERT(m_workerScript->workerGlobalScope());
m_lastQueuedTask = nullptr;
- if (m_sharedTimerFunction && m_running && !m_workerThread->workerGlobalScope()->isClosing())
+ if (m_sharedTimerFunction && m_running && !m_workerScript->workerGlobalScope()->isClosing())
m_sharedTimerFunction();
}
- WorkerThread* m_workerThread;
+ WorkerScript* m_workerScript;
SharedTimerFunction m_sharedTimerFunction;
bool m_running;
// The task to run OnTimeout, if any. While OnTimeout resets
// m_lastQueuedTask, this must be a weak pointer because the
// worker runloop may delete the task as it is shutting down.
- WeakPtr<WorkerThreadCancelableTask> m_lastQueuedTask;
+ WeakPtr<WorkerScriptCancelableTask> m_lastQueuedTask;
};
-class WorkerThreadTask : public WebThread::Task {
- WTF_MAKE_NONCOPYABLE(WorkerThreadTask); WTF_MAKE_FAST_ALLOCATED(WorkerThreadTask);
+class WorkerScriptTask : public WebThread::Task {
+ WTF_MAKE_NONCOPYABLE(WorkerScriptTask); WTF_MAKE_FAST_ALLOCATED(WorkerScriptTask);
public:
- static PassOwnPtr<WorkerThreadTask> create(WorkerThread& workerThread, PassOwnPtr<ExecutionContextTask> task, bool isInstrumented)
+ static PassOwnPtr<WorkerScriptTask> create(WorkerScript& workerScript, PassOwnPtr<ExecutionContextTask> task, bool isInstrumented)
{
- return adoptPtr(new WorkerThreadTask(workerThread, task, isInstrumented));
+ return adoptPtr(new WorkerScriptTask(workerScript, task, isInstrumented));
}
- virtual ~WorkerThreadTask() { }
+ virtual ~WorkerScriptTask() { }
virtual void run() override
{
- WorkerGlobalScope* workerGlobalScope = m_workerThread.workerGlobalScope();
+ WorkerGlobalScope* workerGlobalScope = m_workerScript.workerGlobalScope();
// Tasks could be put on the message loop after the cleanup task,
// ensure none of those are ran.
if (!workerGlobalScope)
@@ -215,48 +215,48 @@ public:
if (m_isInstrumented)
InspectorInstrumentation::willPerformExecutionContextTask(workerGlobalScope, m_task.get());
- if ((!workerGlobalScope->isClosing() && !m_workerThread.terminated()) || m_task->isCleanupTask())
+ if ((!workerGlobalScope->isClosing() && !m_workerScript.terminated()) || m_task->isCleanupTask())
m_task->performTask(workerGlobalScope);
if (m_isInstrumented)
InspectorInstrumentation::didPerformExecutionContextTask(workerGlobalScope);
}
private:
- WorkerThreadTask(WorkerThread& workerThread, PassOwnPtr<ExecutionContextTask> task, bool isInstrumented)
- : m_workerThread(workerThread)
+ WorkerScriptTask(WorkerScript& workerScript, PassOwnPtr<ExecutionContextTask> task, bool isInstrumented)
+ : m_workerScript(workerScript)
, m_task(task)
, m_isInstrumented(isInstrumented)
{
if (m_isInstrumented)
m_isInstrumented = !m_task->taskNameForInstrumentation().isEmpty();
if (m_isInstrumented)
- InspectorInstrumentation::didPostExecutionContextTask(m_workerThread.workerGlobalScope(), m_task.get());
+ InspectorInstrumentation::didPostExecutionContextTask(m_workerScript.workerGlobalScope(), m_task.get());
}
- WorkerThread& m_workerThread;
+ WorkerScript& m_workerScript;
OwnPtr<ExecutionContextTask> m_task;
bool m_isInstrumented;
};
class RunDebuggerQueueTask final : public ExecutionContextTask {
public:
- static PassOwnPtr<RunDebuggerQueueTask> create(WorkerThread* thread)
+ static PassOwnPtr<RunDebuggerQueueTask> create(WorkerScript* thread)
{
return adoptPtr(new RunDebuggerQueueTask(thread));
}
virtual void performTask(ExecutionContext* context) override
{
ASSERT(context->isWorkerGlobalScope());
- m_thread->runDebuggerTask(WorkerThread::DontWaitForMessage);
+ m_thread->runDebuggerTask(WorkerScript::DontWaitForMessage);
}
private:
- explicit RunDebuggerQueueTask(WorkerThread* thread) : m_thread(thread) { }
+ explicit RunDebuggerQueueTask(WorkerScript* thread) : m_thread(thread) { }
- WorkerThread* m_thread;
+ WorkerScript* m_thread;
};
-WorkerThread::WorkerThread(PassRefPtr<WorkerLoaderProxy> workerLoaderProxy, WorkerReportingProxy& workerReportingProxy, PassOwnPtr<WorkerThreadStartupData> startupData)
+WorkerScript::WorkerScript(PassRefPtr<WorkerLoaderProxy> workerLoaderProxy, WorkerReportingProxy& workerReportingProxy, PassOwnPtr<WorkerScriptStartupData> startupData)
: m_started(false)
, m_terminated(false)
, m_workerLoaderProxy(workerLoaderProxy)
@@ -267,40 +267,40 @@ WorkerThread::WorkerThread(PassRefPtr<WorkerLoaderProxy> workerLoaderProxy, Work
, m_terminationEvent(adoptPtr(Platform::current()->createWaitableEvent()))
{
MutexLocker lock(threadSetMutex());
- workerThreads().add(this);
+ workerScripts().add(this);
}
-WorkerThread::~WorkerThread()
+WorkerScript::~WorkerScript()
{
MutexLocker lock(threadSetMutex());
- ASSERT(workerThreads().contains(this));
- workerThreads().remove(this);
+ ASSERT(workerScripts().contains(this));
+ workerScripts().remove(this);
}
-void WorkerThread::start()
+void WorkerScript::start()
{
if (m_started)
return;
m_started = true;
- backingThread().postTask(FROM_HERE, new Task(threadSafeBind(&WorkerThread::initialize, AllowCrossThreadAccess(this))));
+ backingThread().postTask(FROM_HERE, new Task(threadSafeBind(&WorkerScript::initialize, AllowCrossThreadAccess(this))));
}
-void WorkerThread::interruptAndDispatchInspectorCommands()
+void WorkerScript::interruptAndDispatchInspectorCommands()
{
MutexLocker locker(m_workerInspectorControllerMutex);
if (m_workerInspectorController)
m_workerInspectorController->interruptAndDispatchInspectorCommands();
}
-PlatformThreadId WorkerThread::platformThreadId()
+PlatformThreadId WorkerScript::platformThreadId()
{
if (!m_started)
return 0;
return backingThread().platformThread().threadId();
}
-void WorkerThread::initialize()
+void WorkerScript::initialize()
{
KURL scriptURL = m_startupData->m_scriptURL;
String sourceCode = m_startupData->m_sourceCode;
@@ -315,7 +315,7 @@ void WorkerThread::initialize()
if (m_terminated) {
// Notify the proxy that the WorkerGlobalScope has been disposed of.
// This can free this thread object, hence it must not be touched afterwards.
- m_workerReportingProxy.workerThreadTerminated();
+ m_workerReportingProxy.workerScriptTerminated();
return;
}
@@ -336,7 +336,7 @@ void WorkerThread::initialize()
// Notify proxy that a new WorkerGlobalScope has been created and started.
m_workerReportingProxy.workerGlobalScopeStarted(m_workerGlobalScope.get());
- WorkerScriptController* script = m_workerGlobalScope->script();
+ WorkerScriptController* script = m_workerGlobalScope->scriptController();
if (!script->isExecutionForbidden())
script->initializeContextIfNeeded();
if (startMode == PauseWorkerGlobalScopeOnStart)
@@ -349,10 +349,10 @@ void WorkerThread::initialize()
postInitialize();
- postDelayedTask(FROM_HERE, createSameThreadTask(&WorkerThread::idleHandler, this), kShortIdleHandlerDelayMs);
+ postDelayedTask(FROM_HERE, createSameThreadTask(&WorkerScript::idleHandler, this), kShortIdleHandlerDelayMs);
}
-void WorkerThread::cleanup()
+void WorkerScript::cleanup()
{
// This should be called before we start the shutdown procedure.
workerReportingProxy().willDestroyWorkerGlobalScope();
@@ -374,7 +374,7 @@ void WorkerThread::cleanup()
// Notify the proxy that the WorkerGlobalScope has been disposed of.
// This can free this thread object, hence it must not be touched afterwards.
- workerReportingProxy().workerThreadTerminated();
+ workerReportingProxy().workerScriptTerminated();
m_terminationEvent->signal();
@@ -382,11 +382,11 @@ void WorkerThread::cleanup()
PlatformThreadData::current().destroy();
}
-class WorkerThreadShutdownFinishTask : public ExecutionContextTask {
+class WorkerScriptShutdownFinishTask : public ExecutionContextTask {
public:
- static PassOwnPtr<WorkerThreadShutdownFinishTask> create()
+ static PassOwnPtr<WorkerScriptShutdownFinishTask> create()
{
- return adoptPtr(new WorkerThreadShutdownFinishTask());
+ return adoptPtr(new WorkerScriptShutdownFinishTask());
}
virtual void performTask(ExecutionContext *context)
@@ -394,19 +394,19 @@ public:
WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context);
workerGlobalScope->dispose();
- WorkerThread* workerThread = workerGlobalScope->thread();
- workerThread->willDestroyIsolate();
- workerThread->backingThread().postTask(FROM_HERE, new Task(WTF::bind(&WorkerThread::cleanup, workerThread)));
+ WorkerScript* workerScript = workerGlobalScope->script();
+ workerScript->willDestroyIsolate();
+ workerScript->backingThread().postTask(FROM_HERE, new Task(WTF::bind(&WorkerScript::cleanup, workerScript)));
}
virtual bool isCleanupTask() const { return true; }
};
-class WorkerThreadShutdownStartTask : public ExecutionContextTask {
+class WorkerScriptShutdownStartTask : public ExecutionContextTask {
public:
- static PassOwnPtr<WorkerThreadShutdownStartTask> create()
+ static PassOwnPtr<WorkerScriptShutdownStartTask> create()
{
- return adoptPtr(new WorkerThreadShutdownStartTask());
+ return adoptPtr(new WorkerScriptShutdownStartTask());
}
virtual void performTask(ExecutionContext *context)
@@ -421,37 +421,37 @@ public:
// Stick a shutdown command at the end of the queue, so that we deal
// with all the cleanup tasks the databases post first.
- workerGlobalScope->postTask(FROM_HERE, WorkerThreadShutdownFinishTask::create());
+ workerGlobalScope->postTask(FROM_HERE, WorkerScriptShutdownFinishTask::create());
}
virtual bool isCleanupTask() const { return true; }
};
-void WorkerThread::stop()
+void WorkerScript::stop()
{
// Prevent the deadlock between GC and an attempt to stop a thread.
SafePointScope safePointScope(ThreadState::HeapPointersOnStack);
stopInternal();
}
-void WorkerThread::stopInShutdownSequence()
+void WorkerScript::stopInShutdownSequence()
{
stopInternal();
}
-void WorkerThread::terminateAndWait()
+void WorkerScript::terminateAndWait()
{
stop();
m_terminationEvent->wait();
}
-bool WorkerThread::terminated()
+bool WorkerScript::terminated()
{
MutexLocker lock(m_threadCreationMutex);
return m_terminated;
}
-void WorkerThread::stopInternal()
+void WorkerScript::stopInternal()
{
// Protect against this method and initialize() racing each other.
MutexLocker lock(m_threadCreationMutex);
@@ -473,39 +473,39 @@ void WorkerThread::stopInternal()
InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScope.get());
m_debuggerMessageQueue.kill();
- postTask(FROM_HERE, WorkerThreadShutdownStartTask::create());
+ postTask(FROM_HERE, WorkerScriptShutdownStartTask::create());
}
-void WorkerThread::didStartRunLoop()
+void WorkerScript::didStartRunLoop()
{
ASSERT(isCurrentThread());
Platform::current()->didStartWorkerRunLoop();
}
-void WorkerThread::didStopRunLoop()
+void WorkerScript::didStopRunLoop()
{
ASSERT(isCurrentThread());
Platform::current()->didStopWorkerRunLoop();
}
-void WorkerThread::terminateAndWaitForAllWorkers()
+void WorkerScript::terminateAndWaitForAllWorkers()
{
- // Keep this lock to prevent WorkerThread instances from being destroyed.
+ // Keep this lock to prevent WorkerScript instances from being destroyed.
MutexLocker lock(threadSetMutex());
- HashSet<WorkerThread*> threads = workerThreads();
- for (WorkerThread* thread : threads)
+ HashSet<WorkerScript*> threads = workerScripts();
+ for (WorkerScript* thread : threads)
thread->stopInShutdownSequence();
- for (WorkerThread* thread : threads)
+ for (WorkerScript* thread : threads)
thread->terminationEvent()->wait();
}
-bool WorkerThread::isCurrentThread()
+bool WorkerScript::isCurrentThread()
{
return m_started && backingThread().isCurrentThread();
}
-void WorkerThread::idleHandler()
+void WorkerScript::idleHandler()
{
ASSERT(m_workerGlobalScope.get());
int64_t delay = kLongIdleHandlerDelayMs;
@@ -519,20 +519,20 @@ void WorkerThread::idleHandler()
delay = kShortIdleHandlerDelayMs;
}
- postDelayedTask(FROM_HERE, createSameThreadTask(&WorkerThread::idleHandler, this), delay);
+ postDelayedTask(FROM_HERE, createSameThreadTask(&WorkerScript::idleHandler, this), delay);
}
-void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<ExecutionContextTask> task)
+void WorkerScript::postTask(const WebTraceLocation& location, PassOwnPtr<ExecutionContextTask> task)
{
- backingThread().postTask(location, WorkerThreadTask::create(*this, task, true).leakPtr());
+ backingThread().postTask(location, WorkerScriptTask::create(*this, task, true).leakPtr());
}
-void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr<ExecutionContextTask> task, long long delayMs)
+void WorkerScript::postDelayedTask(const WebTraceLocation& location, PassOwnPtr<ExecutionContextTask> task, long long delayMs)
{
- backingThread().postDelayedTask(location, WorkerThreadTask::create(*this, task, true).leakPtr(), delayMs);
+ backingThread().postDelayedTask(location, WorkerScriptTask::create(*this, task, true).leakPtr(), delayMs);
}
-v8::Isolate* WorkerThread::initializeIsolate()
+v8::Isolate* WorkerScript::initializeIsolate()
{
ASSERT(isCurrentThread());
ASSERT(!m_isolate);
@@ -546,7 +546,7 @@ v8::Isolate* WorkerThread::initializeIsolate()
return isolate;
}
-void WorkerThread::willDestroyIsolate()
+void WorkerScript::willDestroyIsolate()
{
ASSERT(isCurrentThread());
ASSERT(m_isolate);
@@ -554,27 +554,27 @@ void WorkerThread::willDestroyIsolate()
ThreadState::current()->removeInterruptor(m_interruptor.get());
}
-void WorkerThread::destroyIsolate()
+void WorkerScript::destroyIsolate()
{
ASSERT(isCurrentThread());
V8PerIsolateData::destroy(m_isolate);
m_isolate = nullptr;
}
-void WorkerThread::terminateV8Execution()
+void WorkerScript::terminateV8Execution()
{
ASSERT(isMainThread());
- m_workerGlobalScope->script()->willScheduleExecutionTermination();
+ m_workerGlobalScope->scriptController()->willScheduleExecutionTermination();
v8::V8::TerminateExecution(m_isolate);
}
-void WorkerThread::postDebuggerTask(const WebTraceLocation& location, PassOwnPtr<ExecutionContextTask> task)
+void WorkerScript::postDebuggerTask(const WebTraceLocation& location, PassOwnPtr<ExecutionContextTask> task)
{
- m_debuggerMessageQueue.append(WorkerThreadTask::create(*this, task, false));
+ m_debuggerMessageQueue.append(WorkerScriptTask::create(*this, task, false));
postTask(location, RunDebuggerQueueTask::create(this));
}
-MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode)
+MessageQueueWaitResult WorkerScript::runDebuggerTask(WaitMode waitMode)
{
ASSERT(isCurrentThread());
MessageQueueWaitResult result;
@@ -596,17 +596,17 @@ MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode)
return result;
}
-void WorkerThread::willEnterNestedLoop()
+void WorkerScript::willEnterNestedLoop()
{
InspectorInstrumentation::willEnterNestedRunLoop(m_workerGlobalScope.get());
}
-void WorkerThread::didLeaveNestedLoop()
+void WorkerScript::didLeaveNestedLoop()
{
InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get());
}
-void WorkerThread::setWorkerInspectorController(WorkerInspectorController* workerInspectorController)
+void WorkerScript::setWorkerInspectorController(WorkerInspectorController* workerInspectorController)
{
MutexLocker locker(m_workerInspectorControllerMutex);
m_workerInspectorController = workerInspectorController;

Powered by Google App Engine
This is Rietveld 408576698