| OLD | NEW |
| 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 12 matching lines...) Expand all Loading... |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 * | 24 * |
| 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/dom/ExecutionContextTask.h" | 30 #include "core/dom/ExecutionContextTask.h" |
| 31 #include "core/frame/csp/ContentSecurityPolicy.h" | 31 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 32 #include "core/workers/WorkerGlobalScope.h" | 32 #include "core/workers/WorkerGlobalScope.h" |
| 33 #include "core/workers/WorkerLoaderProxy.h" |
| 33 #include "platform/SharedTimer.h" | 34 #include "platform/SharedTimer.h" |
| 34 #include "platform/WebThreadSupportingGC.h" | 35 #include "platform/WebThreadSupportingGC.h" |
| 35 #include "platform/weborigin/SecurityOrigin.h" | 36 #include "platform/weborigin/SecurityOrigin.h" |
| 36 #include "wtf/Forward.h" | 37 #include "wtf/Forward.h" |
| 37 #include "wtf/MessageQueue.h" | 38 #include "wtf/MessageQueue.h" |
| 38 #include "wtf/OwnPtr.h" | 39 #include "wtf/OwnPtr.h" |
| 39 #include "wtf/PassRefPtr.h" | 40 #include "wtf/PassRefPtr.h" |
| 40 #include "wtf/RefCounted.h" | 41 #include "wtf/RefCounted.h" |
| 41 | 42 |
| 42 namespace blink { | 43 namespace blink { |
| 43 | 44 |
| 44 class WebWaitableEvent; | 45 class WebWaitableEvent; |
| 45 class WorkerGlobalScope; | 46 class WorkerGlobalScope; |
| 46 class WorkerInspectorController; | 47 class WorkerInspectorController; |
| 47 class WorkerLoaderProxy; | |
| 48 class WorkerReportingProxy; | 48 class WorkerReportingProxy; |
| 49 class WorkerSharedTimer; | 49 class WorkerSharedTimer; |
| 50 class WorkerThreadShutdownFinishTask; | 50 class WorkerThreadShutdownFinishTask; |
| 51 class WorkerThreadStartupData; | 51 class WorkerThreadStartupData; |
| 52 class WorkerThreadTask; | 52 class WorkerThreadTask; |
| 53 | 53 |
| 54 enum WorkerThreadStartMode { | 54 enum WorkerThreadStartMode { |
| 55 DontPauseWorkerGlobalScopeOnStart, | 55 DontPauseWorkerGlobalScopeOnStart, |
| 56 PauseWorkerGlobalScopeOnStart | 56 PauseWorkerGlobalScopeOnStart |
| 57 }; | 57 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 68 | 68 |
| 69 // Can be used to wait for this worker thread to shut down. | 69 // Can be used to wait for this worker thread to shut down. |
| 70 // (This is signalled on the main thread, so it's assumed to be waited on th
e worker context thread) | 70 // (This is signalled on the main thread, so it's assumed to be waited on th
e worker context thread) |
| 71 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } | 71 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } |
| 72 | 72 |
| 73 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); } | 73 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); } |
| 74 void terminateAndWait(); | 74 void terminateAndWait(); |
| 75 static void terminateAndWaitForAllWorkers(); | 75 static void terminateAndWaitForAllWorkers(); |
| 76 | 76 |
| 77 bool isCurrentThread() const; | 77 bool isCurrentThread() const; |
| 78 WorkerLoaderProxy& workerLoaderProxy() const { return m_workerLoaderProxy; } | 78 WorkerLoaderProxy* workerLoaderProxy() const |
| 79 { |
| 80 RELEASE_ASSERT(m_workerLoaderProxy); |
| 81 return m_workerLoaderProxy.get(); |
| 82 } |
| 83 |
| 79 WorkerReportingProxy& workerReportingProxy() const { return m_workerReportin
gProxy; } | 84 WorkerReportingProxy& workerReportingProxy() const { return m_workerReportin
gProxy; } |
| 80 | 85 |
| 81 void postTask(PassOwnPtr<ExecutionContextTask>); | 86 void postTask(PassOwnPtr<ExecutionContextTask>); |
| 82 void postDebuggerTask(PassOwnPtr<ExecutionContextTask>); | 87 void postDebuggerTask(PassOwnPtr<ExecutionContextTask>); |
| 83 | 88 |
| 84 enum WaitMode { WaitForMessage, DontWaitForMessage }; | 89 enum WaitMode { WaitForMessage, DontWaitForMessage }; |
| 85 MessageQueueWaitResult runDebuggerTask(WaitMode = WaitForMessage); | 90 MessageQueueWaitResult runDebuggerTask(WaitMode = WaitForMessage); |
| 86 | 91 |
| 87 // These methods should be called if the holder of the thread is | 92 // These methods should be called if the holder of the thread is |
| 88 // going to call runDebuggerTask in a loop. | 93 // going to call runDebuggerTask in a loop. |
| 89 void willEnterNestedLoop(); | 94 void willEnterNestedLoop(); |
| 90 void didLeaveNestedLoop(); | 95 void didLeaveNestedLoop(); |
| 91 | 96 |
| 92 WorkerGlobalScope* workerGlobalScope() const { return m_workerGlobalScope.ge
t(); } | 97 WorkerGlobalScope* workerGlobalScope() const { return m_workerGlobalScope.ge
t(); } |
| 93 bool terminated(); | 98 bool terminated(); |
| 94 | 99 |
| 95 // Number of active worker threads. | 100 // Number of active worker threads. |
| 96 static unsigned workerThreadCount(); | 101 static unsigned workerThreadCount(); |
| 97 | 102 |
| 98 PlatformThreadId platformThreadId() const; | 103 PlatformThreadId platformThreadId() const; |
| 99 | 104 |
| 100 void interruptAndDispatchInspectorCommands(); | 105 void interruptAndDispatchInspectorCommands(); |
| 101 void setWorkerInspectorController(WorkerInspectorController*); | 106 void setWorkerInspectorController(WorkerInspectorController*); |
| 102 | 107 |
| 103 protected: | 108 protected: |
| 104 WorkerThread(WorkerLoaderProxy&, WorkerReportingProxy&, PassOwnPtrWillBeRawP
tr<WorkerThreadStartupData>); | 109 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&, PassOwnPt
rWillBeRawPtr<WorkerThreadStartupData>); |
| 105 | 110 |
| 106 // Factory method for creating a new worker context for the thread. | 111 // Factory method for creating a new worker context for the thread. |
| 107 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa
ssOwnPtrWillBeRawPtr<WorkerThreadStartupData>) = 0; | 112 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa
ssOwnPtrWillBeRawPtr<WorkerThreadStartupData>) = 0; |
| 108 | 113 |
| 109 virtual void postInitialize() { } | 114 virtual void postInitialize() { } |
| 110 | 115 |
| 111 private: | 116 private: |
| 112 friend class WorkerSharedTimer; | 117 friend class WorkerSharedTimer; |
| 113 friend class WorkerThreadShutdownFinishTask; | 118 friend class WorkerThreadShutdownFinishTask; |
| 114 | 119 |
| 115 void stopInShutdownSequence(); | 120 void stopInShutdownSequence(); |
| 116 void stopInternal(); | 121 void stopInternal(); |
| 117 | 122 |
| 118 void initialize(); | 123 void initialize(); |
| 119 void cleanup(); | 124 void cleanup(); |
| 120 void idleHandler(); | 125 void idleHandler(); |
| 121 void postDelayedTask(PassOwnPtr<ExecutionContextTask>, long long delayMs); | 126 void postDelayedTask(PassOwnPtr<ExecutionContextTask>, long long delayMs); |
| 122 | 127 |
| 123 bool m_terminated; | 128 bool m_terminated; |
| 124 OwnPtr<WorkerSharedTimer> m_sharedTimer; | 129 OwnPtr<WorkerSharedTimer> m_sharedTimer; |
| 125 MessageQueue<WorkerThreadTask> m_debuggerMessageQueue; | 130 MessageQueue<WorkerThreadTask> m_debuggerMessageQueue; |
| 126 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; | 131 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; |
| 127 | 132 |
| 128 WorkerLoaderProxy& m_workerLoaderProxy; | 133 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; |
| 129 WorkerReportingProxy& m_workerReportingProxy; | 134 WorkerReportingProxy& m_workerReportingProxy; |
| 130 | 135 |
| 131 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle
r; | 136 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle
r; |
| 132 Mutex m_workerInspectorControllerMutex; | 137 Mutex m_workerInspectorControllerMutex; |
| 133 | 138 |
| 134 Mutex m_threadCreationMutex; | 139 Mutex m_threadCreationMutex; |
| 135 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; | 140 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
| 136 OwnPtrWillBePersistent<WorkerThreadStartupData> m_startupData; | 141 OwnPtrWillBePersistent<WorkerThreadStartupData> m_startupData; |
| 137 | 142 |
| 138 // Used to signal thread shutdown. | 143 // Used to signal thread shutdown. |
| 139 OwnPtr<WebWaitableEvent> m_shutdownEvent; | 144 OwnPtr<WebWaitableEvent> m_shutdownEvent; |
| 140 | 145 |
| 141 // Used to signal thread termination. | 146 // Used to signal thread termination. |
| 142 OwnPtr<WebWaitableEvent> m_terminationEvent; | 147 OwnPtr<WebWaitableEvent> m_terminationEvent; |
| 143 | 148 |
| 144 // FIXME: This has to be last because of crbug.com/401397 - the | 149 // FIXME: This has to be last because of crbug.com/401397 - the |
| 145 // WorkerThread might get deleted before it had a chance to properly | 150 // WorkerThread might get deleted before it had a chance to properly |
| 146 // shut down. By deleting the WebThread first, we can guarantee that | 151 // shut down. By deleting the WebThread first, we can guarantee that |
| 147 // no pending tasks on the thread might want to access any of the other | 152 // no pending tasks on the thread might want to access any of the other |
| 148 // members during the WorkerThread's destruction. | 153 // members during the WorkerThread's destruction. |
| 149 OwnPtr<WebThreadSupportingGC> m_thread; | 154 OwnPtr<WebThreadSupportingGC> m_thread; |
| 150 }; | 155 }; |
| 151 | 156 |
| 152 } // namespace blink | 157 } // namespace blink |
| 153 | 158 |
| 154 #endif // WorkerThread_h | 159 #endif // WorkerThread_h |
| OLD | NEW |