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

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: Stop tracing CrossThread(Weak)Persistents 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> {
kinuko 2016/06/10 02:05:28 nit: This very generic, yet another -context class
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 // 81 //
64 // When termination starts, (debugger) tasks on WorkerThread are handled as 82 // When termination starts, (debugger) tasks on WorkerThread are handled as
65 // follows: 83 // follows:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 void appendDebuggerTask(std::unique_ptr<CrossThreadClosure>); 131 void appendDebuggerTask(std::unique_ptr<CrossThreadClosure>);
114 132
115 // Runs only debugger tasks while paused in debugger. 133 // Runs only debugger tasks while paused in debugger.
116 void startRunningDebuggerTasksOnPauseOnWorkerThread(); 134 void startRunningDebuggerTasksOnPauseOnWorkerThread();
117 void stopRunningDebuggerTasksOnPauseOnWorkerThread(); 135 void stopRunningDebuggerTasksOnPauseOnWorkerThread();
118 136
119 // Can be called only on the worker thread, WorkerGlobalScope is not thread 137 // Can be called only on the worker thread, WorkerGlobalScope is not thread
120 // safe. 138 // safe.
121 WorkerGlobalScope* workerGlobalScope(); 139 WorkerGlobalScope* workerGlobalScope();
122 140
141 // Called for creating WorkerThreadLifecycleObserver on both the main thread
142 // and the worker thread.
143 WorkerThreadContext* workerThreadContext() const { return m_workerThreadCont ext; }
kinuko 2016/06/10 02:05:28 nit: I know this file is consistently in the old s
144
123 // Returns true once one of the terminate* methods is called. 145 // Returns true once one of the terminate* methods is called.
124 bool terminated(); 146 bool terminated();
125 147
126 // Number of active worker threads. 148 // Number of active worker threads.
127 static unsigned workerThreadCount(); 149 static unsigned workerThreadCount();
128 150
129 PlatformThreadId platformThreadId(); 151 PlatformThreadId platformThreadId();
130 152
131 ExitCode getExitCode(); 153 ExitCode getExitCode();
132 154
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 218
197 // Signaled when the thread starts termination on the main thread. 219 // Signaled when the thread starts termination on the main thread.
198 OwnPtr<WaitableEvent> m_terminationEvent; 220 OwnPtr<WaitableEvent> m_terminationEvent;
199 221
200 // Signaled when the thread completes termination on the worker thread. 222 // Signaled when the thread completes termination on the worker thread.
201 OwnPtr<WaitableEvent> m_shutdownEvent; 223 OwnPtr<WaitableEvent> m_shutdownEvent;
202 224
203 // Scheduled when termination starts with TerminationMode::Force, and 225 // Scheduled when termination starts with TerminationMode::Force, and
204 // cancelled when the worker thread is gracefully shut down. 226 // cancelled when the worker thread is gracefully shut down.
205 OwnPtr<ForceTerminationTask> m_scheduledForceTerminationTask; 227 OwnPtr<ForceTerminationTask> m_scheduledForceTerminationTask;
228
229 Persistent<WorkerThreadContext> m_workerThreadContext;
206 }; 230 };
207 231
208 } // namespace blink 232 } // namespace blink
209 233
210 #endif // WorkerThread_h 234 #endif // WorkerThread_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698