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

Side by Side Diff: Source/core/workers/WorkerScript.h

Issue 1115923002: workers: Rename WorkerThread to WorkerScript. Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 5 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/workers/WorkerReportingProxy.h ('k') | Source/core/workers/WorkerScript.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
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 WorkerScript_h
28 #define WorkerThread_h 28 #define WorkerScript_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 "platform/WebThreadSupportingGC.h" 35 #include "platform/WebThreadSupportingGC.h"
36 #include "platform/weborigin/SecurityOrigin.h" 36 #include "platform/weborigin/SecurityOrigin.h"
37 #include "wtf/Forward.h" 37 #include "wtf/Forward.h"
38 #include "wtf/MessageQueue.h" 38 #include "wtf/MessageQueue.h"
39 #include "wtf/OwnPtr.h" 39 #include "wtf/OwnPtr.h"
40 #include "wtf/PassRefPtr.h" 40 #include "wtf/PassRefPtr.h"
41 #include "wtf/RefCounted.h" 41 #include "wtf/RefCounted.h"
42 #include <v8.h> 42 #include <v8.h>
43 43
44 namespace blink { 44 namespace blink {
45 45
46 class WebWaitableEvent; 46 class WebWaitableEvent;
47 class WorkerGlobalScope; 47 class WorkerGlobalScope;
48 class WorkerInspectorController; 48 class WorkerInspectorController;
49 class WorkerReportingProxy; 49 class WorkerReportingProxy;
50 class WorkerSharedTimer; 50 class WorkerSharedTimer;
51 class WorkerThreadShutdownFinishTask; 51 class WorkerScriptShutdownFinishTask;
52 class WorkerThreadStartupData; 52 class WorkerScriptTask;
53 class WorkerThreadTask; 53 class WorkerScriptStartupData;
54 54
55 enum WorkerThreadStartMode { 55 enum WorkerThreadStartMode {
56 DontPauseWorkerGlobalScopeOnStart, 56 DontPauseWorkerGlobalScopeOnStart,
57 PauseWorkerGlobalScopeOnStart 57 PauseWorkerGlobalScopeOnStart
58 }; 58 };
59 59
60 // TODO(sadrul): Rename to WorkerScript. 60 class CORE_EXPORT WorkerScript : public RefCounted<WorkerScript> {
61 class CORE_EXPORT WorkerThread : public RefCounted<WorkerThread> {
62 public: 61 public:
63 virtual ~WorkerThread(); 62 virtual ~WorkerScript();
64 63
65 virtual void start(); 64 virtual void start();
66 virtual void stop(); 65 virtual void stop();
67 66
68 // Returns the thread this worker runs on. Some implementations can create 67 // Returns the thread this worker runs on. Some implementations can create
69 // a new thread on the first call (e.g. shared, dedicated workers), whereas 68 // a new thread on the first call (e.g. shared, dedicated workers), whereas
70 // some implementations can use an existing thread that is already being 69 // some implementations can use an existing thread that is already being
71 // used by other workers (e.g. compositor workers). 70 // used by other workers (e.g. compositor workers).
72 virtual WebThreadSupportingGC& backingThread() = 0; 71 virtual WebThreadSupportingGC& backingThread() = 0;
73 72
74 virtual void didStartRunLoop(); 73 virtual void didStartRunLoop();
75 virtual void didStopRunLoop(); 74 virtual void didStopRunLoop();
76 75
77 v8::Isolate* isolate() const { return m_isolate; } 76 v8::Isolate* isolate() const { return m_isolate; }
78 77
79 // 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.
yurys 2015/05/12 13:38:57 The comment should be updated as it refers to "thr
80 // (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)
81 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); } 80 WebWaitableEvent* shutdownEvent() { return m_shutdownEvent.get(); }
82 81
83 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); } 82 WebWaitableEvent* terminationEvent() { return m_terminationEvent.get(); }
84 void terminateAndWait(); 83 void terminateAndWait();
85 static void terminateAndWaitForAllWorkers(); 84 static void terminateAndWaitForAllWorkers();
86 85
87 bool isCurrentThread(); 86 bool isCurrentThread();
kinuko 2015/05/08 12:09:52 This method looks a bit strange now. runsOnCurrent
88 WorkerLoaderProxy* workerLoaderProxy() const 87 WorkerLoaderProxy* workerLoaderProxy() const
89 { 88 {
90 RELEASE_ASSERT(m_workerLoaderProxy); 89 RELEASE_ASSERT(m_workerLoaderProxy);
91 return m_workerLoaderProxy.get(); 90 return m_workerLoaderProxy.get();
92 } 91 }
93 92
94 WorkerReportingProxy& workerReportingProxy() const { return m_workerReportin gProxy; } 93 WorkerReportingProxy& workerReportingProxy() const { return m_workerReportin gProxy; }
95 94
96 void postTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTask>); 95 void postTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTask>);
97 void postDebuggerTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTa sk>); 96 void postDebuggerTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTa sk>);
98 97
99 enum WaitMode { WaitForMessage, DontWaitForMessage }; 98 enum WaitMode { WaitForMessage, DontWaitForMessage };
100 MessageQueueWaitResult runDebuggerTask(WaitMode = WaitForMessage); 99 MessageQueueWaitResult runDebuggerTask(WaitMode = WaitForMessage);
101 100
102 // These methods should be called if the holder of the thread is 101 // These methods should be called if the holder of the thread is
103 // going to call runDebuggerTask in a loop. 102 // going to call runDebuggerTask in a loop.
104 void willEnterNestedLoop(); 103 void willEnterNestedLoop();
105 void didLeaveNestedLoop(); 104 void didLeaveNestedLoop();
kinuko 2015/05/08 12:09:52 The comment for these methods needs to be updated.
106 105
107 WorkerGlobalScope* workerGlobalScope() const { return m_workerGlobalScope.ge t(); } 106 WorkerGlobalScope* workerGlobalScope() const { return m_workerGlobalScope.ge t(); }
108 bool terminated(); 107 bool terminated();
109 108
110 // Number of active worker threads. 109 // Number of active worker threads.
kinuko 2015/05/08 12:09:52 Please update this comment.
111 static unsigned workerThreadCount(); 110 static unsigned workerScriptCount();
112 111
113 PlatformThreadId platformThreadId(); 112 PlatformThreadId platformThreadId();
kinuko 2015/05/08 12:09:52 This method looks a bit strange now. getCurrentThr
114 113
115 void interruptAndDispatchInspectorCommands(); 114 void interruptAndDispatchInspectorCommands();
116 void setWorkerInspectorController(WorkerInspectorController*); 115 void setWorkerInspectorController(WorkerInspectorController*);
117 116
118 protected: 117 protected:
119 WorkerThread(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&, PassOwnPt r<WorkerThreadStartupData>); 118 WorkerScript(PassRefPtr<WorkerLoaderProxy>, WorkerReportingProxy&, PassOwnPt r<WorkerScriptStartupData>);
120 119
121 // Factory method for creating a new worker context for the thread. 120 // Factory method for creating a new worker context for the thread.
122 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa ssOwnPtr<WorkerThreadStartupData>) = 0; 121 virtual PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(Pa ssOwnPtr<WorkerScriptStartupData>) = 0;
123 122
124 virtual void postInitialize() { } 123 virtual void postInitialize() { }
125 124
126 virtual v8::Isolate* initializeIsolate(); 125 virtual v8::Isolate* initializeIsolate();
127 virtual void willDestroyIsolate(); 126 virtual void willDestroyIsolate();
128 virtual void destroyIsolate(); 127 virtual void destroyIsolate();
129 virtual void terminateV8Execution(); 128 virtual void terminateV8Execution();
130 129
131 private: 130 private:
132 friend class WorkerSharedTimer; 131 friend class WorkerSharedTimer;
133 friend class WorkerThreadShutdownFinishTask; 132 friend class WorkerScriptShutdownFinishTask;
134 133
135 void stopInShutdownSequence(); 134 void stopInShutdownSequence();
136 void stopInternal(); 135 void stopInternal();
137 136
138 void initialize(); 137 void initialize();
139 void cleanup(); 138 void cleanup();
140 void idleHandler(); 139 void idleHandler();
141 void postDelayedTask(PassOwnPtr<ExecutionContextTask>, long long delayMs); 140 void postDelayedTask(PassOwnPtr<ExecutionContextTask>, long long delayMs);
142 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTas k>, long long delayMs); 141 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<ExecutionContextTas k>, long long delayMs);
143 142
144 bool m_started; 143 bool m_started;
145 bool m_terminated; 144 bool m_terminated;
146 MessageQueue<WorkerThreadTask> m_debuggerMessageQueue; 145 MessageQueue<WorkerScriptTask> m_debuggerMessageQueue;
147 OwnPtr<WebThread::TaskObserver> m_microtaskRunner; 146 OwnPtr<WebThread::TaskObserver> m_microtaskRunner;
148 147
149 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; 148 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy;
150 WorkerReportingProxy& m_workerReportingProxy; 149 WorkerReportingProxy& m_workerReportingProxy;
151 150
152 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle r; 151 RefPtrWillBePersistent<WorkerInspectorController> m_workerInspectorControlle r;
153 Mutex m_workerInspectorControllerMutex; 152 Mutex m_workerInspectorControllerMutex;
154 153
155 Mutex m_threadCreationMutex; 154 Mutex m_threadCreationMutex;
156 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; 155 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope;
157 OwnPtr<WorkerThreadStartupData> m_startupData; 156 OwnPtr<WorkerScriptStartupData> m_startupData;
158 157
159 v8::Isolate* m_isolate; 158 v8::Isolate* m_isolate;
160 OwnPtr<V8IsolateInterruptor> m_interruptor; 159 OwnPtr<V8IsolateInterruptor> m_interruptor;
161 160
162 // Used to signal thread shutdown. 161 // Used to signal thread shutdown.
163 OwnPtr<WebWaitableEvent> m_shutdownEvent; 162 OwnPtr<WebWaitableEvent> m_shutdownEvent;
164 163
165 // Used to signal thread termination. 164 // Used to signal thread termination.
166 OwnPtr<WebWaitableEvent> m_terminationEvent; 165 OwnPtr<WebWaitableEvent> m_terminationEvent;
167 }; 166 };
168 167
169 } // namespace blink 168 } // namespace blink
170 169
171 #endif // WorkerThread_h 170 #endif // WorkerScript_h
OLDNEW
« no previous file with comments | « Source/core/workers/WorkerReportingProxy.h ('k') | Source/core/workers/WorkerScript.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698