Index: third_party/WebKit/Source/core/workers/WorkerOrWorkletThread.h |
diff --git a/third_party/WebKit/Source/core/workers/WorkerThread.h b/third_party/WebKit/Source/core/workers/WorkerOrWorkletThread.h |
similarity index 84% |
copy from third_party/WebKit/Source/core/workers/WorkerThread.h |
copy to third_party/WebKit/Source/core/workers/WorkerOrWorkletThread.h |
index 92c7dbe30e5e2029efd02695376b526fe3649d85..0ceb5a1c967a352a29a60b9ae68c1621638cd8b5 100644 |
--- a/third_party/WebKit/Source/core/workers/WorkerThread.h |
+++ b/third_party/WebKit/Source/core/workers/WorkerOrWorkletThread.h |
@@ -24,8 +24,8 @@ |
* |
*/ |
-#ifndef WorkerThread_h |
-#define WorkerThread_h |
+#ifndef WorkerOrWorkletThread_h |
+#define WorkerOrWorkletThread_h |
#include "core/CoreExport.h" |
#include "core/dom/ExecutionContextTask.h" |
@@ -53,14 +53,14 @@ enum WorkerThreadStartMode { |
PauseWorkerGlobalScopeOnStart |
}; |
-// WorkerThread is a kind of WorkerBackingThread client. Each worker mechanism |
+// WorkerOrWorkletThread is a kind of WorkerBackingThread client. Each worker mechanism |
// can access the lower thread infrastructure via an implementation of this |
-// abstract class. Multiple WorkerThreads can share one WorkerBackingThread. |
+// abstract class. Multiple WorkerOrWorkletThreads can share one WorkerBackingThread. |
// See WorkerBackingThread.h for more details. |
// |
-// WorkerThread start and termination must be initiated on the main thread and |
+// WorkerOrWorkletThread start and termination must be initiated on the main thread and |
// an actual task is executed on the worker thread. |
-class CORE_EXPORT WorkerThread { |
+class CORE_EXPORT WorkerOrWorkletThread { |
public: |
// Represents how this thread is terminated. |
enum class ExitCode { |
@@ -70,10 +70,15 @@ public: |
AsyncForciblyTerminated, |
}; |
- virtual ~WorkerThread(); |
+ class GlobalScopeFactory { |
+ STACK_ALLOCATED(); |
+ public: |
+ virtual WorkerOrWorkletGlobalScope* create() const = 0; |
+ }; |
+ |
+ virtual ~WorkerOrWorkletThread(); |
// Called on the main thread. |
- void start(PassOwnPtr<WorkerThreadStartupData>); |
void terminate(); |
// Called on the main thread. Internally calls terminateInternal() and wait |
@@ -92,12 +97,6 @@ public: |
bool isCurrentThread(); |
- WorkerLoaderProxy* workerLoaderProxy() const |
- { |
- RELEASE_ASSERT(m_workerLoaderProxy); |
- return m_workerLoaderProxy.get(); |
- } |
- |
WorkerReportingProxy& workerReportingProxy() const { return m_workerReportingProxy; } |
void postTask(const WebTraceLocation&, std::unique_ptr<ExecutionContextTask>); |
@@ -111,7 +110,7 @@ public: |
// Can be called only on the worker thread, WorkerGlobalScope is not thread |
// safe. |
- WorkerGlobalScope* workerGlobalScope(); |
+ WorkerOrWorkletGlobalScope* globalScope(); |
// Returns true once one of the terminate* methods is called. |
bool terminated(); |
@@ -124,15 +123,12 @@ public: |
ExitCode getExitCode(); |
protected: |
- WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&); |
- |
- // Factory method for creating a new worker context for the thread. |
- // Called on the worker thread. |
- virtual WorkerGlobalScope* createWorkerGlobalScope(PassOwnPtr<WorkerThreadStartupData>) = 0; |
+ WorkerOrWorkletThread(WorkerReportingProxy&); |
- // Called on the worker thread. |
- virtual void postInitialize() { } |
+ void initializeGlobalScope(GlobalScopeFactory&); |
+ bool m_started = false; |
+ bool m_terminated = false; |
private: |
friend class WorkerThreadTest; |
@@ -156,7 +152,6 @@ private: |
void terminateInternal(TerminationMode); |
void forciblyTerminateExecution(); |
- void initializeOnWorkerThread(PassOwnPtr<WorkerThreadStartupData>); |
void prepareForShutdownOnWorkerThread(); |
void performShutdownOnWorkerThread(); |
void performTaskOnWorkerThread(std::unique_ptr<ExecutionContextTask>, bool isInstrumented); |
@@ -165,8 +160,6 @@ private: |
void setForceTerminationDelayInMsForTesting(long long forceTerminationDelayInMs) { m_forceTerminationDelayInMs = forceTerminationDelayInMs; } |
- bool m_started = false; |
- bool m_terminated = false; |
bool m_readyToShutdown = false; |
bool m_pausedInDebugger = false; |
bool m_runningDebuggerTask = false; |
@@ -177,7 +170,6 @@ private: |
OwnPtr<InspectorTaskRunner> m_inspectorTaskRunner; |
OwnPtr<WorkerMicrotaskRunner> m_microtaskRunner; |
- RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; |
WorkerReportingProxy& m_workerReportingProxy; |
// This lock protects |m_workerGlobalScope|, |m_terminated|, |
@@ -185,7 +177,7 @@ private: |
// |m_microtaskRunner|. |
Mutex m_threadStateMutex; |
- Persistent<WorkerGlobalScope> m_workerGlobalScope; |
+ Persistent<WorkerOrWorkletGlobalScope> m_globalScope; |
// Signaled when the thread starts termination on the main thread. |
OwnPtr<WaitableEvent> m_terminationEvent; |
@@ -200,4 +192,4 @@ private: |
} // namespace blink |
-#endif // WorkerThread_h |
+#endif // WorkerOrWorkletThread_h |