Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 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/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/WorkerIsolateWrapper.h" | |
| 34 #include "core/workers/WorkerLoaderProxy.h" | 35 #include "core/workers/WorkerLoaderProxy.h" |
| 35 #include "platform/WebThreadSupportingGC.h" | 36 #include "platform/WebThreadSupportingGC.h" |
| 36 #include "platform/weborigin/SecurityOrigin.h" | 37 #include "platform/weborigin/SecurityOrigin.h" |
| 37 #include "wtf/Forward.h" | 38 #include "wtf/Forward.h" |
| 38 #include "wtf/MessageQueue.h" | 39 #include "wtf/MessageQueue.h" |
| 39 #include "wtf/OwnPtr.h" | 40 #include "wtf/OwnPtr.h" |
| 40 #include "wtf/PassRefPtr.h" | 41 #include "wtf/PassRefPtr.h" |
| 41 #include "wtf/RefCounted.h" | 42 #include "wtf/RefCounted.h" |
| 42 #include <v8.h> | 43 #include <v8.h> |
| 43 | 44 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 62 virtual ~WorkerThread(); | 63 virtual ~WorkerThread(); |
| 63 | 64 |
| 64 virtual void start(PassOwnPtr<WorkerThreadStartupData>); | 65 virtual void start(PassOwnPtr<WorkerThreadStartupData>); |
| 65 virtual void stop(); | 66 virtual void stop(); |
| 66 | 67 |
| 67 // Returns the thread this worker runs on. Some implementations can create | 68 // Returns the thread this worker runs on. Some implementations can create |
| 68 // a new thread on the first call (e.g. shared, dedicated workers), whereas | 69 // a new thread on the first call (e.g. shared, dedicated workers), whereas |
| 69 // some implementations can use an existing thread that is already being | 70 // some implementations can use an existing thread that is already being |
| 70 // used by other workers (e.g. compositor workers). | 71 // used by other workers (e.g. compositor workers). |
| 71 virtual WebThreadSupportingGC& backingThread() = 0; | 72 virtual WebThreadSupportingGC& backingThread() = 0; |
| 72 | |
| 73 virtual void didStartRunLoop(); | 73 virtual void didStartRunLoop(); |
| 74 virtual void didStopRunLoop(); | 74 virtual void didStopRunLoop(); |
| 75 | 75 |
| 76 v8::Isolate* isolate() const { return m_isolate; } | 76 v8::Isolate* isolate(); |
| 77 | 77 |
| 78 // Can be used to wait for this worker thread to shut down. | 78 // Can be used to wait for this worker thread to shut down. |
| 79 // (This is signalled on the main thread, so it's assumed to be waited on th e worker context thread) | 79 // (This is signalled on the main thread, so it's assumed to be waited on th e worker context thread) |
| 80 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } | 80 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } |
| 81 | 81 |
| 82 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); } | 82 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); } |
| 83 void terminateAndWait(); | 83 void terminateAndWait(); |
| 84 static void terminateAndWaitForAllWorkers(); | 84 static void terminateAndWaitForAllWorkers(); |
| 85 | 85 |
| 86 bool isCurrentThread(); | 86 bool isCurrentThread(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 115 void setWorkerInspectorController(WorkerInspectorController*); | 115 void setWorkerInspectorController(WorkerInspectorController*); |
| 116 | 116 |
| 117 protected: | 117 protected: |
| 118 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&); | 118 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&); |
| 119 | 119 |
| 120 // Factory method for creating a new worker context for the thread. | 120 // Factory method for creating a new worker context for the thread. |
| 121 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa ssOwnPtr<WorkerThreadStartupData>) = 0; | 121 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa ssOwnPtr<WorkerThreadStartupData>) = 0; |
| 122 | 122 |
| 123 virtual void postInitialize() { } | 123 virtual void postInitialize() { } |
| 124 | 124 |
| 125 virtual v8::Isolate* initializeIsolate(); | 125 virtual PassOwnPtr<WorkerIsolateWrapper> createIsolateWrapper() = 0; |
|
kinuko
2015/06/01 13:15:41
Please comment that this needs to be called on the
sadrul
2015/06/01 14:21:16
Done.
| |
| 126 virtual void willDestroyIsolate(); | |
| 127 virtual void destroyIsolate(); | |
| 128 virtual void terminateV8Execution(); | 126 virtual void terminateV8Execution(); |
| 129 | 127 |
| 128 virtual void initializeBackingThread(); | |
| 129 virtual void shutdownBackingThread(); | |
|
kinuko
2015/06/01 13:15:41
Please comment that these need to be called on the
sadrul
2015/06/01 14:21:16
Done.
| |
| 130 | |
| 130 // This is protected virtual for testing. | 131 // This is protected virtual for testing. |
| 131 virtual bool doIdleGc(double deadlineSeconds); | 132 virtual bool doIdleGc(double deadlineSeconds); |
| 132 | 133 |
| 133 private: | 134 private: |
| 134 friend class WorkerSharedTimer; | 135 friend class WorkerSharedTimer; |
| 135 friend class WorkerMicrotaskRunner; | 136 friend class WorkerMicrotaskRunner; |
| 136 | 137 |
| 137 void stopInShutdownSequence(); | 138 void stopInShutdownSequence(); |
| 138 void stopInternal(); | 139 void stopInternal(); |
| 139 | 140 |
| 140 void initialize(PassOwnPtr<WorkerThreadStartupData>); | 141 void initialize(PassOwnPtr<WorkerThreadStartupData>); |
| 141 void shutdown(); | 142 void shutdown(); |
| 142 void performIdleWork(double deadlineSeconds); | 143 void performIdleWork(double deadlineSeconds); |
| 143 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTas k>, long long delayMs); | 144 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTas k>, long long delayMs); |
| 144 | 145 |
| 145 bool m_started; | 146 bool m_started; |
| 146 bool m_terminated; | 147 bool m_terminated; |
| 147 bool m_shutdown; | 148 bool m_shutdown; |
| 148 MessageQueue<WebThread::Task> m_debuggerMessageQueue; | 149 MessageQueue<WebThread::Task> m_debuggerMessageQueue; |
| 149 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; | 150 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; |
| 150 | 151 |
| 151 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; | 152 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; |
| 152 WorkerReportingProxy& m_workerReportingProxy; | 153 WorkerReportingProxy& m_workerReportingProxy; |
| 153 RawPtr<WebScheduler> m_webScheduler; // Not owned. | 154 RawPtr<WebScheduler> m_webScheduler; // Not owned. |
| 154 | 155 |
| 155 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle r; | 156 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle r; |
| 156 Mutex m_workerInspectorControllerMutex; | 157 Mutex m_workerInspectorControllerMutex; |
| 157 | 158 |
| 158 // This lock protects |m_workerGlobalScope|, |m_terminated|, |m_isolate| and |m_microtaskRunner|. | 159 // This lock protects |m_workerGlobalScope|, |m_terminated|, and |m_isolateW rapper|. |
| 159 Mutex m_threadStateMutex; | 160 Mutex m_threadStateMutex; |
| 160 | 161 |
| 161 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; | 162 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
| 162 | 163 OwnPtr<WorkerIsolateWrapper> m_isolateWrapper; |
| 163 v8::Isolate* m_isolate; | |
| 164 OwnPtr<V8IsolateInterruptor> m_interruptor; | |
| 165 | 164 |
| 166 // Used to signal thread shutdown. | 165 // Used to signal thread shutdown. |
| 167 OwnPtr<WebWaitableEvent> m_shutdownEvent; | 166 OwnPtr<WebWaitableEvent> m_shutdownEvent; |
| 168 | 167 |
| 169 // Used to signal thread termination. | 168 // Used to signal thread termination. |
| 170 OwnPtr<WebWaitableEvent> m_terminationEvent; | 169 OwnPtr<WebWaitableEvent> m_terminationEvent; |
| 171 }; | 170 }; |
| 172 | 171 |
| 173 } // namespace blink | 172 } // namespace blink |
| 174 | 173 |
| 175 #endif // WorkerThread_h | 174 #endif // WorkerThread_h |
| OLD | NEW |