| Index: third_party/WebKit/Source/core/workers/WorkerScript.cpp
|
| diff --git a/third_party/WebKit/Source/core/workers/WorkerThread.cpp b/third_party/WebKit/Source/core/workers/WorkerScript.cpp
|
| similarity index 81%
|
| rename from third_party/WebKit/Source/core/workers/WorkerThread.cpp
|
| rename to third_party/WebKit/Source/core/workers/WorkerScript.cpp
|
| index 7531f85f8fd3380bb9d78c4486aa3c0272634be2..1eeb726b90b212adbd8335ce70ba11bd5b5c18b3 100644
|
| --- a/third_party/WebKit/Source/core/workers/WorkerThread.cpp
|
| +++ b/third_party/WebKit/Source/core/workers/WorkerScript.cpp
|
| @@ -24,7 +24,7 @@
|
| *
|
| */
|
|
|
| -#include "core/workers/WorkerThread.h"
|
| +#include "core/workers/WorkerScript.h"
|
|
|
| #include "bindings/core/v8/ScriptSourceCode.h"
|
| #include "bindings/core/v8/V8GCController.h"
|
| @@ -36,7 +36,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/Task.h"
|
| #include "platform/ThreadSafeFunctional.h"
|
| #include "platform/WaitableEvent.h"
|
| @@ -55,27 +55,27 @@ namespace blink {
|
|
|
| class WorkerMicrotaskRunner : public WebThread::TaskObserver {
|
| public:
|
| - explicit WorkerMicrotaskRunner(WorkerThread* workerThread)
|
| - : m_workerThread(workerThread)
|
| + explicit WorkerMicrotaskRunner(WorkerScript* workerScript)
|
| + : m_workerScript(workerScript)
|
| {
|
| }
|
|
|
| void willProcessTask() override
|
| {
|
| // No tasks should get executed after we have closed.
|
| - WorkerGlobalScope* globalScope = m_workerThread->workerGlobalScope();
|
| + WorkerGlobalScope* globalScope = m_workerScript->workerGlobalScope();
|
| ASSERT_UNUSED(globalScope, !globalScope || !globalScope->isClosing());
|
| }
|
|
|
| void didProcessTask() override
|
| {
|
| - Microtask::performCheckpoint(m_workerThread->isolate());
|
| - if (WorkerGlobalScope* globalScope = m_workerThread->workerGlobalScope()) {
|
| + Microtask::performCheckpoint(m_workerScript->isolate());
|
| + if (WorkerGlobalScope* globalScope = m_workerScript->workerGlobalScope()) {
|
| if (WorkerOrWorkletScriptController* scriptController = globalScope->scriptController())
|
| scriptController->rejectedPromises()->processQueue();
|
| if (globalScope->isClosing()) {
|
| - m_workerThread->workerReportingProxy().workerGlobalScopeClosed();
|
| - m_workerThread->shutdown();
|
| + m_workerScript->workerReportingProxy().workerGlobalScopeClosed();
|
| + m_workerScript->shutdown();
|
| }
|
| }
|
| }
|
| @@ -83,7 +83,7 @@ public:
|
| private:
|
| // Thread owns the microtask runner; reference remains
|
| // valid for the lifetime of this object.
|
| - WorkerThread* m_workerThread;
|
| + WorkerScript* m_workerScript;
|
| };
|
|
|
| static Mutex& threadSetMutex()
|
| @@ -92,24 +92,24 @@ static Mutex& threadSetMutex()
|
| return mutex;
|
| }
|
|
|
| -static HashSet<WorkerThread*>& workerThreads()
|
| +static HashSet<WorkerScript*>& workerScripts()
|
| {
|
| - DEFINE_STATIC_LOCAL(HashSet<WorkerThread*>, threads, ());
|
| - return threads;
|
| + DEFINE_STATIC_LOCAL(HashSet<WorkerScript*>, workerScripts, ());
|
| + return workerScripts;
|
| }
|
|
|
| -unsigned WorkerThread::workerThreadCount()
|
| +unsigned WorkerScript::workerScriptCount()
|
| {
|
| MutexLocker lock(threadSetMutex());
|
| - return workerThreads().size();
|
| + return workerScripts().size();
|
| }
|
|
|
| -void WorkerThread::performTask(PassOwnPtr<ExecutionContextTask> task, bool isInstrumented)
|
| +void WorkerScript::performTask(PassOwnPtr<ExecutionContextTask> task, bool isInstrumented)
|
| {
|
| ASSERT(isCurrentThread());
|
| WorkerGlobalScope* globalScope = workerGlobalScope();
|
| // If the thread is terminated before it had a chance initialize (see
|
| - // WorkerThread::Initialize()), we mustn't run any of the posted tasks.
|
| + // WorkerScript::Initialize()), we mustn't run any of the posted tasks.
|
| if (!globalScope) {
|
| ASSERT(terminated());
|
| return;
|
| @@ -122,7 +122,7 @@ void WorkerThread::performTask(PassOwnPtr<ExecutionContextTask> task, bool isIns
|
| InspectorInstrumentation::didPerformExecutionContextTask(globalScope);
|
| }
|
|
|
| -WebTaskRunner::Task* WorkerThread::createWorkerThreadTask(PassOwnPtr<ExecutionContextTask> task, bool isInstrumented)
|
| +WebTaskRunner::Task* WorkerScript::createWorkerThreadTask(PassOwnPtr<ExecutionContextTask> task, bool isInstrumented)
|
| {
|
| if (isInstrumented)
|
| isInstrumented = !task->taskNameForInstrumentation().isEmpty();
|
| @@ -131,14 +131,14 @@ WebTaskRunner::Task* WorkerThread::createWorkerThreadTask(PassOwnPtr<ExecutionCo
|
| // https://crbug.com/588497
|
| InspectorInstrumentation::didPostExecutionContextTask(workerGlobalScope(), task.get());
|
| }
|
| - return new Task(threadSafeBind(&WorkerThread::performTask, AllowCrossThreadAccess(this), task, isInstrumented));
|
| + return new Task(threadSafeBind(&WorkerScript::performTask, AllowCrossThreadAccess(this), task, isInstrumented));
|
| }
|
|
|
| -class WorkerThread::DebuggerTaskQueue {
|
| +class WorkerScript::DebuggerTaskQueue {
|
| WTF_MAKE_NONCOPYABLE(DebuggerTaskQueue);
|
| public:
|
| using Task = WebTaskRunner::Task;
|
| - using Result = WorkerThread::TaskQueueResult;
|
| + using Result = WorkerScript::TaskQueueResult;
|
|
|
| DebuggerTaskQueue() { }
|
|
|
| @@ -194,7 +194,7 @@ private:
|
| bool m_killed = false;
|
| };
|
|
|
| -WorkerThread::WorkerThread(PassRefPtr<WorkerLoaderProxy> workerLoaderProxy, WorkerReportingProxy& workerReportingProxy)
|
| +WorkerScript::WorkerScript(PassRefPtr<WorkerLoaderProxy> workerLoaderProxy, WorkerReportingProxy& workerReportingProxy)
|
| : m_started(false)
|
| , m_terminated(false)
|
| , m_shutdown(false)
|
| @@ -211,17 +211,17 @@ WorkerThread::WorkerThread(PassRefPtr<WorkerLoaderProxy> workerLoaderProxy, Work
|
| WaitableEvent::InitialState::NonSignaled)))
|
| {
|
| 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(PassOwnPtr<WorkerThreadStartupData> startupData)
|
| +void WorkerScript::start(PassOwnPtr<WorkerScriptStartupData> startupData)
|
| {
|
| ASSERT(isMainThread());
|
|
|
| @@ -229,28 +229,28 @@ void WorkerThread::start(PassOwnPtr<WorkerThreadStartupData> startupData)
|
| return;
|
|
|
| m_started = true;
|
| - backingThread().postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&WorkerThread::initialize, AllowCrossThreadAccess(this), startupData)));
|
| + backingThread().postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&WorkerScript::initialize, AllowCrossThreadAccess(this), startupData)));
|
| }
|
|
|
| -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(PassOwnPtr<WorkerThreadStartupData> startupData)
|
| +void WorkerScript::initialize(PassOwnPtr<WorkerScriptStartupData> startupData)
|
| {
|
| KURL scriptURL = startupData->m_scriptURL;
|
| String sourceCode = startupData->m_sourceCode;
|
| - WorkerThreadStartMode startMode = startupData->m_startMode;
|
| + WorkerScriptStartMode startMode = startupData->m_startMode;
|
| OwnPtr<Vector<char>> cachedMetaData = startupData->m_cachedMetaData.release();
|
| V8CacheOptions v8CacheOptions = startupData->m_v8CacheOptions;
|
| m_webScheduler = backingThread().platformThread().scheduler();
|
| @@ -262,7 +262,7 @@ void WorkerThread::initialize(PassOwnPtr<WorkerThreadStartupData> startupData)
|
| 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();
|
| // Notify the main thread that it is safe to deallocate our resources.
|
| m_terminationEvent->signal();
|
| return;
|
| @@ -278,7 +278,7 @@ void WorkerThread::initialize(PassOwnPtr<WorkerThreadStartupData> startupData)
|
| m_workerGlobalScope = createWorkerGlobalScope(startupData);
|
| m_workerGlobalScope->scriptLoaded(sourceCode.length(), cachedMetaData.get() ? cachedMetaData->size() : 0);
|
|
|
| - didStartWorkerThread();
|
| + didStartWorkerScript();
|
|
|
| // Notify proxy that a new WorkerGlobalScope has been created and started.
|
| m_workerReportingProxy.workerGlobalScopeStarted(m_workerGlobalScope.get());
|
| @@ -301,7 +301,7 @@ void WorkerThread::initialize(PassOwnPtr<WorkerThreadStartupData> startupData)
|
| postInitialize();
|
| }
|
|
|
| -void WorkerThread::shutdown()
|
| +void WorkerScript::shutdown()
|
| {
|
| ASSERT(isCurrentThread());
|
| {
|
| @@ -318,13 +318,13 @@ void WorkerThread::shutdown()
|
|
|
| // This should be called after the WorkerGlobalScope's disposed (which may
|
| // trigger some last-minutes cleanups) and before the thread actually stops.
|
| - willStopWorkerThread();
|
| + willStopWorkerScript();
|
|
|
| backingThread().removeTaskObserver(m_microtaskRunner.get());
|
| - postTask(BLINK_FROM_HERE, createSameThreadTask(&WorkerThread::performShutdownTask, this));
|
| + postTask(BLINK_FROM_HERE, createSameThreadTask(&WorkerScript::performShutdownTask, this));
|
| }
|
|
|
| -void WorkerThread::performShutdownTask()
|
| +void WorkerScript::performShutdownTask()
|
| {
|
| // The below assignment will destroy the context, which will in turn notify messaging proxy.
|
| // We cannot let any objects survive past thread exit, because no other thread will run GC or otherwise destroy them.
|
| @@ -344,37 +344,37 @@ void WorkerThread::performShutdownTask()
|
|
|
| // 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();
|
| }
|
|
|
| -void WorkerThread::terminate()
|
| +void WorkerScript::terminate()
|
| {
|
| // Prevent the deadlock between GC and an attempt to terminate a thread.
|
| SafePointScope safePointScope(BlinkGC::HeapPointersOnStack);
|
| terminateInternal();
|
| }
|
|
|
| -void WorkerThread::terminateAndWait()
|
| +void WorkerScript::terminateAndWait()
|
| {
|
| terminate();
|
| m_terminationEvent->wait();
|
| }
|
|
|
| -WorkerGlobalScope* WorkerThread::workerGlobalScope()
|
| +WorkerGlobalScope* WorkerScript::workerGlobalScope()
|
| {
|
| ASSERT(isCurrentThread());
|
| return m_workerGlobalScope.get();
|
| }
|
|
|
| -bool WorkerThread::terminated()
|
| +bool WorkerScript::terminated()
|
| {
|
| MutexLocker lock(m_threadStateMutex);
|
| return m_terminated;
|
| }
|
|
|
| -void WorkerThread::terminateInternal()
|
| +void WorkerScript::terminateInternal()
|
| {
|
| ASSERT(isMainThread());
|
|
|
| @@ -406,61 +406,61 @@ void WorkerThread::terminateInternal()
|
|
|
| InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScope.get());
|
| m_debuggerTaskQueue->kill();
|
| - backingThread().postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&WorkerThread::shutdown, AllowCrossThreadAccess(this))));
|
| + backingThread().postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&WorkerScript::shutdown, AllowCrossThreadAccess(this))));
|
| }
|
|
|
| -void WorkerThread::didStartWorkerThread()
|
| +void WorkerScript::didStartWorkerScript()
|
| {
|
| ASSERT(isCurrentThread());
|
| Platform::current()->didStartWorkerThread();
|
| }
|
|
|
| -void WorkerThread::willStopWorkerThread()
|
| +void WorkerScript::willStopWorkerScript()
|
| {
|
| ASSERT(isCurrentThread());
|
| Platform::current()->willStopWorkerThread();
|
| }
|
|
|
| -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)
|
| - thread->terminateInternal();
|
| + HashSet<WorkerScript*> scripts = workerScripts();
|
| + for (WorkerScript* workerScript : scripts)
|
| + workerScript->terminateInternal();
|
|
|
| - for (WorkerThread* thread : threads)
|
| - thread->m_terminationEvent->wait();
|
| + for (WorkerScript* workerScript : scripts)
|
| + workerScript->m_terminationEvent->wait();
|
| }
|
|
|
| -bool WorkerThread::isCurrentThread()
|
| +bool WorkerScript::isCurrentThread()
|
| {
|
| return m_started && backingThread().isCurrentThread();
|
| }
|
|
|
| -void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<ExecutionContextTask> task)
|
| +void WorkerScript::postTask(const WebTraceLocation& location, PassOwnPtr<ExecutionContextTask> task)
|
| {
|
| backingThread().postTask(location, createWorkerThreadTask(task, true));
|
| }
|
|
|
| -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, createWorkerThreadTask(task, true), delayMs);
|
| }
|
|
|
| -void WorkerThread::initializeBackingThread()
|
| +void WorkerScript::initializeBackingThread()
|
| {
|
| ASSERT(isCurrentThread());
|
| backingThread().initialize();
|
| }
|
|
|
| -void WorkerThread::shutdownBackingThread()
|
| +void WorkerScript::shutdownBackingThread()
|
| {
|
| ASSERT(isCurrentThread());
|
| backingThread().shutdown();
|
| }
|
|
|
| -v8::Isolate* WorkerThread::initializeIsolate()
|
| +v8::Isolate* WorkerScript::initializeIsolate()
|
| {
|
| ASSERT(isCurrentThread());
|
| ASSERT(!m_isolate);
|
| @@ -475,26 +475,26 @@ v8::Isolate* WorkerThread::initializeIsolate()
|
| return isolate;
|
| }
|
|
|
| -void WorkerThread::willDestroyIsolate()
|
| +void WorkerScript::willDestroyIsolate()
|
| {
|
| ASSERT(isCurrentThread());
|
| ASSERT(m_isolate);
|
| V8PerIsolateData::willBeDestroyed(m_isolate);
|
| }
|
|
|
| -void WorkerThread::destroyIsolate()
|
| +void WorkerScript::destroyIsolate()
|
| {
|
| ASSERT(isCurrentThread());
|
| V8PerIsolateData::destroy(m_isolate);
|
| }
|
|
|
| -void WorkerThread::terminateV8Execution()
|
| +void WorkerScript::terminateV8Execution()
|
| {
|
| ASSERT(isMainThread());
|
| m_isolate->TerminateExecution();
|
| }
|
|
|
| -void WorkerThread::appendDebuggerTask(PassOwnPtr<WebTaskRunner::Task> task)
|
| +void WorkerScript::appendDebuggerTask(PassOwnPtr<WebTaskRunner::Task> task)
|
| {
|
| {
|
| MutexLocker lock(m_threadStateMutex);
|
| @@ -504,7 +504,7 @@ void WorkerThread::appendDebuggerTask(PassOwnPtr<WebTaskRunner::Task> task)
|
| m_debuggerTaskQueue->append(task);
|
| }
|
|
|
| -WorkerThread::TaskQueueResult WorkerThread::runDebuggerTask(WaitMode waitMode)
|
| +WorkerScript::TaskQueueResult WorkerScript::runDebuggerTask(WaitMode waitMode)
|
| {
|
| ASSERT(isCurrentThread());
|
| TaskQueueResult result;
|
| @@ -526,17 +526,17 @@ WorkerThread::TaskQueueResult WorkerThread::runDebuggerTask(WaitMode waitMode)
|
| return result;
|
| }
|
|
|
| -void WorkerThread::willRunDebuggerTasks()
|
| +void WorkerScript::willRunDebuggerTasks()
|
| {
|
| InspectorInstrumentation::willEnterNestedRunLoop(m_workerGlobalScope.get());
|
| }
|
|
|
| -void WorkerThread::didRunDebuggerTasks()
|
| +void WorkerScript::didRunDebuggerTasks()
|
| {
|
| InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get());
|
| }
|
|
|
| -void WorkerThread::setWorkerInspectorController(WorkerInspectorController* workerInspectorController)
|
| +void WorkerScript::setWorkerInspectorController(WorkerInspectorController* workerInspectorController)
|
| {
|
| MutexLocker locker(m_workerInspectorControllerMutex);
|
| m_workerInspectorController = workerInspectorController;
|
|
|