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

Unified Diff: third_party/WebKit/Source/core/workers/WorkerThread.cpp

Issue 2118243002: [proof-of-concept] SW thread independent of the main thread Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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: 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);
}
« no previous file with comments | « third_party/WebKit/Source/core/workers/WorkerThread.h ('k') | third_party/WebKit/Source/modules/modules.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698