OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "core/workers/WorkerInspectorProxy.h" | 7 #include "core/workers/WorkerInspectorProxy.h" |
8 | 8 |
9 #include "core/dom/CrossThreadTask.h" | 9 #include "core/dom/CrossThreadTask.h" |
10 #include "core/inspector/InspectorInstrumentation.h" | 10 #include "core/inspector/InspectorInstrumentation.h" |
11 #include "core/inspector/InspectorTraceEvents.h" | 11 #include "core/inspector/InspectorTraceEvents.h" |
12 #include "core/inspector/WorkerInspectorController.h" | 12 #include "core/inspector/WorkerInspectorController.h" |
13 #include "core/workers/WorkerThread.h" | 13 #include "core/workers/WorkerThread.h" |
14 #include "platform/Task.h" | |
14 #include "platform/TraceEvent.h" | 15 #include "platform/TraceEvent.h" |
15 #include "platform/weborigin/KURL.h" | 16 #include "platform/weborigin/KURL.h" |
17 #include "public/platform/WebTraceLocation.h" | |
16 | 18 |
17 namespace blink { | 19 namespace blink { |
18 | 20 |
19 WorkerInspectorProxy::WorkerInspectorProxy() | 21 WorkerInspectorProxy::WorkerInspectorProxy() |
20 : m_workerThread(nullptr) | 22 : m_workerThread(nullptr) |
21 , m_executionContext(nullptr) | 23 , m_executionContext(nullptr) |
22 , m_pageInspector(nullptr) | 24 , m_pageInspector(nullptr) |
23 , m_workerGlobalScopeProxy(nullptr) | 25 , m_workerGlobalScopeProxy(nullptr) |
24 { | 26 { |
25 } | 27 } |
(...skipping 15 matching lines...) Expand all Loading... | |
41 } | 43 } |
42 | 44 |
43 void WorkerInspectorProxy::workerThreadTerminated() | 45 void WorkerInspectorProxy::workerThreadTerminated() |
44 { | 46 { |
45 if (m_workerThread) | 47 if (m_workerThread) |
46 InspectorInstrumentation::workerTerminated(m_executionContext, this); | 48 InspectorInstrumentation::workerTerminated(m_executionContext, this); |
47 m_workerThread = nullptr; | 49 m_workerThread = nullptr; |
48 m_pageInspector = nullptr; | 50 m_pageInspector = nullptr; |
49 } | 51 } |
50 | 52 |
51 static void connectToWorkerGlobalScopeInspectorTask(ExecutionContext* context) | 53 static void connectToWorkerGlobalScopeInspectorTask(WorkerThread* workerThread) |
52 { | 54 { |
53 toWorkerGlobalScope(context)->workerInspectorController()->connectFrontend() ; | 55 workerThread->workerGlobalScope()->workerInspectorController()->connectFront end(); |
54 } | 56 } |
55 | 57 |
56 void WorkerInspectorProxy::connectToInspector(WorkerInspectorProxy::PageInspecto r* pageInspector) | 58 void WorkerInspectorProxy::connectToInspector(WorkerInspectorProxy::PageInspecto r* pageInspector) |
57 { | 59 { |
58 if (!m_workerThread) | 60 if (!m_workerThread) |
59 return; | 61 return; |
60 ASSERT(!m_pageInspector); | 62 ASSERT(!m_pageInspector); |
61 m_pageInspector = pageInspector; | 63 m_pageInspector = pageInspector; |
62 m_workerThread->postDebuggerTask(FROM_HERE, createCrossThreadTask(connectToW orkerGlobalScopeInspectorTask)); | 64 addDebuggerTaskForWorker(FROM_HERE, adoptPtr(new Task(threadSafeBind(connect ToWorkerGlobalScopeInspectorTask, AllowCrossThreadAccess(m_workerThread))))); |
63 } | 65 } |
64 | 66 |
65 static void disconnectFromWorkerGlobalScopeInspectorTask(ExecutionContext* conte xt) | 67 static void disconnectFromWorkerGlobalScopeInspectorTask(WorkerThread* workerThr ead) |
66 { | 68 { |
67 toWorkerGlobalScope(context)->workerInspectorController()->disconnectFronten d(); | 69 workerThread->workerGlobalScope()->workerInspectorController()->disconnectFr ontend(); |
68 } | 70 } |
69 | 71 |
70 void WorkerInspectorProxy::disconnectFromInspector() | 72 void WorkerInspectorProxy::disconnectFromInspector() |
71 { | 73 { |
72 m_pageInspector = nullptr; | 74 m_pageInspector = nullptr; |
73 if (!m_workerThread) | 75 if (!m_workerThread) |
74 return; | 76 return; |
75 m_workerThread->postDebuggerTask(FROM_HERE, createCrossThreadTask(disconnect FromWorkerGlobalScopeInspectorTask)); | 77 addDebuggerTaskForWorker(FROM_HERE, adoptPtr(new Task(threadSafeBind(disconn ectFromWorkerGlobalScopeInspectorTask, AllowCrossThreadAccess(m_workerThread)))) ); |
76 } | 78 } |
77 | 79 |
78 static void dispatchOnInspectorBackendTask(const String& message, ExecutionConte xt* context) | 80 static void dispatchOnInspectorBackendTask(const String& message, WorkerThread* workerThread) |
79 { | 81 { |
80 toWorkerGlobalScope(context)->workerInspectorController()->dispatchMessageFr omFrontend(message); | 82 workerThread->workerGlobalScope()->workerInspectorController()->dispatchMess ageFromFrontend(message); |
yurys
2015/05/15 23:41:41
Why is it safe to access workerGlobalScope here? I
sadrul
2015/05/16 00:50:53
The WorkerGlobalScope gets destroyed at the same t
| |
81 } | 83 } |
82 | 84 |
83 void WorkerInspectorProxy::sendMessageToInspector(const String& message) | 85 void WorkerInspectorProxy::sendMessageToInspector(const String& message) |
84 { | 86 { |
85 if (!m_workerThread) | 87 if (!m_workerThread) |
86 return; | 88 return; |
87 m_workerThread->postDebuggerTask(FROM_HERE, createCrossThreadTask(dispatchOn InspectorBackendTask, message)); | 89 addDebuggerTaskForWorker(FROM_HERE, adoptPtr(new Task(threadSafeBind(dispatc hOnInspectorBackendTask, message, AllowCrossThreadAccess(m_workerThread))))); |
88 m_workerThread->interruptAndDispatchInspectorCommands(); | 90 m_workerThread->interruptAndDispatchInspectorCommands(); |
89 } | 91 } |
90 | 92 |
91 void WorkerInspectorProxy::writeTimelineStartedEvent(const String& sessionId, co nst String& workerId) | 93 void WorkerInspectorProxy::writeTimelineStartedEvent(const String& sessionId, co nst String& workerId) |
92 { | 94 { |
93 if (!m_workerThread) | 95 if (!m_workerThread) |
94 return; | 96 return; |
95 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Tracin gSessionIdForWorker", TRACE_EVENT_SCOPE_THREAD, "data", InspectorTracingSessionI dForWorkerEvent::data(sessionId, workerId, m_workerThread)); | 97 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Tracin gSessionIdForWorker", TRACE_EVENT_SCOPE_THREAD, "data", InspectorTracingSessionI dForWorkerEvent::data(sessionId, workerId, m_workerThread)); |
96 } | 98 } |
97 | 99 |
100 static void runDebuggerTaskForWorker(WorkerThread* workerThread) | |
101 { | |
102 workerThread->runDebuggerTask(WorkerThread::DontWaitForMessage); | |
103 } | |
104 | |
105 void WorkerInspectorProxy::addDebuggerTaskForWorker(const WebTraceLocation& loca tion, PassOwnPtr<WebThread::Task> task) | |
106 { | |
107 m_workerThread->appendDebuggerTask(task); | |
108 m_workerThread->backingThread().postTask(location, new Task(threadSafeBind(& runDebuggerTaskForWorker, AllowCrossThreadAccess(m_workerThread)))); | |
kinuko
2015/05/18 15:19:49
Could this be just threadSafeBind(&WorkerThread::r
sadrul
2015/05/19 03:50:47
backingThread() returns a WebThreadSupportingGC, w
sadrul
2015/05/19 16:23:06
I have made this change (moved WorkerThread::backi
kinuko
2015/05/20 08:17:46
Sorry, I should have made it clearer. I meant to
| |
109 } | |
110 | |
98 } // namespace blink | 111 } // namespace blink |
OLD | NEW |