| Index: third_party/WebKit/Source/core/workers/WorkerThread.cpp
|
| diff --git a/third_party/WebKit/Source/core/workers/WorkerThread.cpp b/third_party/WebKit/Source/core/workers/WorkerThread.cpp
|
| index 55ad091a54ccf1baa29fcba78dbd20b35ff2b287..ad825e712448374d94451b2be05f6459888893bf 100644
|
| --- a/third_party/WebKit/Source/core/workers/WorkerThread.cpp
|
| +++ b/third_party/WebKit/Source/core/workers/WorkerThread.cpp
|
| @@ -47,6 +47,7 @@
|
| #include "platform/heap/SafePoint.h"
|
| #include "platform/heap/ThreadState.h"
|
| #include "platform/scheduler/CancellableTaskFactory.h"
|
| +#include "platform/TraceEvent.h"
|
| #include "platform/weborigin/KURL.h"
|
| #include "public/platform/WebThread.h"
|
| #include "wtf/Functional.h"
|
| @@ -190,7 +191,9 @@ WorkerThread::~WorkerThread()
|
|
|
| void WorkerThread::start(std::unique_ptr<WorkerThreadStartupData> startupData)
|
| {
|
| - DCHECK(isMainThread());
|
| +
|
| + if (m_launchedFromMainThread)
|
| + DCHECK(isMainThread());
|
|
|
| if (m_requestedToStart)
|
| return;
|
| @@ -349,16 +352,19 @@ bool WorkerThread::isForciblyTerminated()
|
| return false;
|
| }
|
|
|
| -WorkerThread::WorkerThread(PassRefPtr<WorkerLoaderProxy> workerLoaderProxy, WorkerReportingProxy& workerReportingProxy)
|
| +WorkerThread::WorkerThread(PassRefPtr<WorkerLoaderProxy> workerLoaderProxy, WorkerReportingProxy& workerReportingProxy, bool launchedFromMainThread)
|
| : m_forceTerminationDelayInMs(kForceTerminationDelayInMs)
|
| , m_inspectorTaskRunner(wrapUnique(new InspectorTaskRunner()))
|
| , m_workerLoaderProxy(workerLoaderProxy)
|
| , m_workerReportingProxy(workerReportingProxy)
|
| , m_shutdownEvent(wrapUnique(new WaitableEvent(
|
| - WaitableEvent::ResetPolicy::Manual,
|
| - WaitableEvent::InitialState::NonSignaled)))
|
| - , m_workerThreadLifecycleContext(new WorkerThreadLifecycleContext)
|
| + WaitableEvent::ResetPolicy::Manual,
|
| + WaitableEvent::InitialState::NonSignaled)))
|
| + , m_workerThreadLifecycleContext(launchedFromMainThread ? new WorkerThreadLifecycleContext : nullptr)
|
| + , m_launchedFromMainThread(launchedFromMainThread)
|
| {
|
| + if (!m_launchedFromMainThread)
|
| + return;
|
| DCHECK(isMainThread());
|
| MutexLocker lock(threadSetMutex());
|
| workerThreads().add(this);
|
| @@ -476,6 +482,10 @@ bool WorkerThread::isInShutdown()
|
| void WorkerThread::initializeOnWorkerThread(std::unique_ptr<WorkerThreadStartupData> startupData)
|
| {
|
| DCHECK(isCurrentThread());
|
| +
|
| + TRACE_EVENT0("ServiceWorker", "WorkerThread::initializeOnWorkerThread");
|
| + m_workerReportingProxy.initializeOnWorkerThread();
|
| +
|
| KURL scriptURL = startupData->m_scriptURL;
|
| String sourceCode = startupData->m_sourceCode;
|
| WorkerThreadStartMode startMode = startupData->m_startMode;
|
| @@ -500,11 +510,13 @@ void WorkerThread::initializeOnWorkerThread(std::unique_ptr<WorkerThreadStartupD
|
| return;
|
| }
|
|
|
| - if (isOwningBackingThread())
|
| + if (isOwningBackingThread()) {
|
| workerBackingThread().initialize();
|
| + }
|
|
|
| - if (shouldAttachThreadDebugger())
|
| + if (shouldAttachThreadDebugger()) {
|
| V8PerIsolateData::from(isolate())->setThreadDebugger(wrapUnique(new WorkerThreadDebugger(this, isolate())));
|
| + }
|
| m_microtaskRunner = wrapUnique(new WorkerMicrotaskRunner(this));
|
| workerBackingThread().backingThread().addTaskObserver(m_microtaskRunner.get());
|
|
|
| @@ -552,8 +564,22 @@ void WorkerThread::initializeOnWorkerThread(std::unique_ptr<WorkerThreadStartupD
|
|
|
| if (globalScope()->isWorkerGlobalScope()) {
|
| WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(globalScope());
|
| - CachedMetadataHandler* handler = workerGlobalScope->createWorkerScriptCachedMetadataHandler(scriptURL, cachedMetaData.get());
|
| - bool success = workerGlobalScope->scriptController()->evaluate(ScriptSourceCode(sourceCode, scriptURL), nullptr, handler, v8CacheOptions);
|
| + std::unique_ptr<String> alternativeCode(m_workerReportingProxy.takeAlternativeCode(scriptURL));
|
| + bool success = false;
|
| +
|
| + if (alternativeCode) {
|
| + CachedMetadataHandler* handler = workerGlobalScope->createWorkerScriptCachedMetadataHandler(scriptURL, cachedMetaData.get());
|
| + {
|
| + TRACE_EVENT0("ServiceWorker", "WorkerThread::initializeOnWorkerThread::evaluate");
|
| + success = workerGlobalScope->scriptController()->evaluate(ScriptSourceCode(*alternativeCode, scriptURL), nullptr, handler, v8CacheOptions);
|
| + }
|
| + } else {
|
| + CachedMetadataHandler* handler = workerGlobalScope->createWorkerScriptCachedMetadataHandler(scriptURL, cachedMetaData.get());
|
| + {
|
| + TRACE_EVENT0("ServiceWorker", "WorkerThread::initializeOnWorkerThread::evaluate");
|
| + success = workerGlobalScope->scriptController()->evaluate(ScriptSourceCode(sourceCode, scriptURL), nullptr, handler, v8CacheOptions);
|
| + }
|
| + }
|
| workerGlobalScope->didEvaluateWorkerScript();
|
| m_workerReportingProxy.didEvaluateWorkerScript(success);
|
| }
|
|
|