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

Side by Side Diff: third_party/WebKit/Source/core/workers/WorkerThread.h

Issue 2025783002: Worker: Introduce an observation mechanism for WorkerThread termination (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@delayed_task
Patch Set: remake and add tests Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 14 matching lines...) Expand all
25 */ 25 */
26 26
27 #ifndef WorkerThread_h 27 #ifndef WorkerThread_h
28 #define WorkerThread_h 28 #define WorkerThread_h
29 29
30 #include "core/CoreExport.h" 30 #include "core/CoreExport.h"
31 #include "core/dom/ExecutionContextTask.h" 31 #include "core/dom/ExecutionContextTask.h"
32 #include "core/frame/csp/ContentSecurityPolicy.h" 32 #include "core/frame/csp/ContentSecurityPolicy.h"
33 #include "core/workers/WorkerGlobalScope.h" 33 #include "core/workers/WorkerGlobalScope.h"
34 #include "core/workers/WorkerLoaderProxy.h" 34 #include "core/workers/WorkerLoaderProxy.h"
35 #include "core/workers/WorkerThreadLifecycleObserver.h"
36 #include "platform/LifecycleNotifier.h"
35 #include "wtf/Forward.h" 37 #include "wtf/Forward.h"
36 #include "wtf/Functional.h" 38 #include "wtf/Functional.h"
37 #include "wtf/OwnPtr.h" 39 #include "wtf/OwnPtr.h"
38 #include "wtf/PassRefPtr.h" 40 #include "wtf/PassRefPtr.h"
39 #include <v8.h> 41 #include <v8.h>
40 42
41 namespace blink { 43 namespace blink {
42 44
43 class InspectorTaskRunner; 45 class InspectorTaskRunner;
44 class WaitableEvent; 46 class WaitableEvent;
45 class WorkerBackingThread; 47 class WorkerBackingThread;
46 class WorkerGlobalScope; 48 class WorkerGlobalScope;
47 class WorkerInspectorController; 49 class WorkerInspectorController;
48 class WorkerReportingProxy; 50 class WorkerReportingProxy;
49 class WorkerThreadStartupData; 51 class WorkerThreadStartupData;
50 52
51 enum WorkerThreadStartMode { 53 enum WorkerThreadStartMode {
52 DontPauseWorkerGlobalScopeOnStart, 54 DontPauseWorkerGlobalScopeOnStart,
53 PauseWorkerGlobalScopeOnStart 55 PauseWorkerGlobalScopeOnStart
54 }; 56 };
55 57
58 // Used for notifying observers on the main thread of worker thread termination.
59 // The lifetime of this class is equal to that of WorkerThread. Created and
60 // destructed on the main thread.
61 class CORE_EXPORT WorkerThreadContext final : public GarbageCollectedFinalized<W orkerThreadContext>, public LifecycleNotifier<WorkerThreadContext, WorkerThreadL ifecycleObserver> {
62 USING_GARBAGE_COLLECTED_MIXIN(WorkerThreadContext);
63 WTF_MAKE_NONCOPYABLE(WorkerThreadContext);
64 public:
65 WorkerThreadContext();
66 ~WorkerThreadContext() override;
67 void notifyContextDestroyed() override;
68
69 private:
70 friend class WorkerThreadLifecycleObserver;
71 bool m_wasContextDestroyed = false;
72 };
73
56 // WorkerThread is a kind of WorkerBackingThread client. Each worker mechanism 74 // WorkerThread is a kind of WorkerBackingThread client. Each worker mechanism
57 // can access the lower thread infrastructure via an implementation of this 75 // can access the lower thread infrastructure via an implementation of this
58 // abstract class. Multiple WorkerThreads can share one WorkerBackingThread. 76 // abstract class. Multiple WorkerThreads can share one WorkerBackingThread.
59 // See WorkerBackingThread.h for more details. 77 // See WorkerBackingThread.h for more details.
60 // 78 //
61 // WorkerThread start and termination must be initiated on the main thread and 79 // WorkerThread start and termination must be initiated on the main thread and
62 // an actual task is executed on the worker thread. 80 // an actual task is executed on the worker thread.
63 class CORE_EXPORT WorkerThread { 81 class CORE_EXPORT WorkerThread {
64 public: 82 public:
65 // Represents how this thread is terminated. 83 // Represents how this thread is terminated.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // Runs only debugger tasks while paused in debugger, called on the worker 124 // Runs only debugger tasks while paused in debugger, called on the worker
107 // thread. 125 // thread.
108 void startRunningDebuggerTasksOnPause(); 126 void startRunningDebuggerTasksOnPause();
109 void stopRunningDebuggerTasksOnPause(); 127 void stopRunningDebuggerTasksOnPause();
110 bool isRunningDebuggerTasksOnPause() const { return m_pausedInDebugger; } 128 bool isRunningDebuggerTasksOnPause() const { return m_pausedInDebugger; }
111 129
112 // Can be called only on the worker thread, WorkerGlobalScope is not thread 130 // Can be called only on the worker thread, WorkerGlobalScope is not thread
113 // safe. 131 // safe.
114 WorkerGlobalScope* workerGlobalScope(); 132 WorkerGlobalScope* workerGlobalScope();
115 133
134 // Called for creating WorkerThreadLifecycleObserver on both the main thread
135 // and the worker thread.
136 WorkerThreadContext* workerThreadContext() const { return m_workerThreadCont ext; }
137
116 // Returns true once one of the terminate* methods is called. 138 // Returns true once one of the terminate* methods is called.
117 bool terminated(); 139 bool terminated();
118 140
119 // Number of active worker threads. 141 // Number of active worker threads.
120 static unsigned workerThreadCount(); 142 static unsigned workerThreadCount();
121 143
122 PlatformThreadId platformThreadId(); 144 PlatformThreadId platformThreadId();
123 145
124 ExitCode getExitCode(); 146 ExitCode getExitCode();
125 147
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 211
190 // Signaled when the thread starts termination on the main thread. 212 // Signaled when the thread starts termination on the main thread.
191 OwnPtr<WaitableEvent> m_terminationEvent; 213 OwnPtr<WaitableEvent> m_terminationEvent;
192 214
193 // Signaled when the thread completes termination on the worker thread. 215 // Signaled when the thread completes termination on the worker thread.
194 OwnPtr<WaitableEvent> m_shutdownEvent; 216 OwnPtr<WaitableEvent> m_shutdownEvent;
195 217
196 // Scheduled when termination starts with TerminationMode::Force, and 218 // Scheduled when termination starts with TerminationMode::Force, and
197 // cancelled when the worker thread is gracefully shut down. 219 // cancelled when the worker thread is gracefully shut down.
198 OwnPtr<ForceTerminationTask> m_scheduledForceTerminationTask; 220 OwnPtr<ForceTerminationTask> m_scheduledForceTerminationTask;
221
222 Persistent<WorkerThreadContext> m_workerThreadContext;
199 }; 223 };
200 224
201 } // namespace blink 225 } // namespace blink
202 226
203 #endif // WorkerThread_h 227 #endif // WorkerThread_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698