| 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/TraceEvent.h" | 14 #include "platform/TraceEvent.h" |
| 15 #include "platform/weborigin/KURL.h" | 15 #include "platform/weborigin/KURL.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 WorkerInspectorProxy::WorkerInspectorProxy() | 19 WorkerInspectorProxy::WorkerInspectorProxy() |
| 20 : m_workerThread(0) | 20 : m_workerThread(nullptr) |
| 21 , m_executionContext(0) | 21 , m_executionContext(nullptr) |
| 22 , m_pageInspector(0) | 22 , m_pageInspector(nullptr) |
| 23 { | 23 { |
| 24 } | 24 } |
| 25 | 25 |
| 26 PassOwnPtr<WorkerInspectorProxy> WorkerInspectorProxy::create() | 26 PassOwnPtr<WorkerInspectorProxy> WorkerInspectorProxy::create() |
| 27 { | 27 { |
| 28 return adoptPtr(new WorkerInspectorProxy()); | 28 return adoptPtr(new WorkerInspectorProxy()); |
| 29 } | 29 } |
| 30 | 30 |
| 31 WorkerInspectorProxy::~WorkerInspectorProxy() | 31 WorkerInspectorProxy::~WorkerInspectorProxy() |
| 32 { | 32 { |
| 33 } | 33 } |
| 34 | 34 |
| 35 void WorkerInspectorProxy::workerThreadCreated(ExecutionContext* context, Worker
Thread* workerThread, const KURL& url) | 35 void WorkerInspectorProxy::workerThreadCreated(ExecutionContext* context, Worker
Thread* workerThread, const KURL& url) |
| 36 { | 36 { |
| 37 m_workerThread = workerThread; | 37 m_workerThread = workerThread; |
| 38 m_executionContext = context; | 38 m_executionContext = context; |
| 39 InspectorInstrumentation::didStartWorker(context, this, url); | 39 InspectorInstrumentation::didStartWorker(context, this, url); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void WorkerInspectorProxy::workerThreadTerminated() | 42 void WorkerInspectorProxy::workerThreadTerminated() |
| 43 { | 43 { |
| 44 if (m_workerThread) | 44 if (m_workerThread) |
| 45 InspectorInstrumentation::workerTerminated(m_executionContext, this); | 45 InspectorInstrumentation::workerTerminated(m_executionContext, this); |
| 46 m_workerThread = 0; | 46 m_workerThread = nullptr; |
| 47 m_pageInspector = 0; | 47 m_pageInspector = nullptr; |
| 48 } | 48 } |
| 49 | 49 |
| 50 static void connectToWorkerGlobalScopeInspectorTask(ExecutionContext* context, b
ool) | 50 static void connectToWorkerGlobalScopeInspectorTask(ExecutionContext* context, b
ool) |
| 51 { | 51 { |
| 52 toWorkerGlobalScope(context)->workerInspectorController()->connectFrontend()
; | 52 toWorkerGlobalScope(context)->workerInspectorController()->connectFrontend()
; |
| 53 } | 53 } |
| 54 | 54 |
| 55 void WorkerInspectorProxy::connectToInspector(WorkerInspectorProxy::PageInspecto
r* pageInspector) | 55 void WorkerInspectorProxy::connectToInspector(WorkerInspectorProxy::PageInspecto
r* pageInspector) |
| 56 { | 56 { |
| 57 if (!m_workerThread) | 57 if (!m_workerThread) |
| 58 return; | 58 return; |
| 59 ASSERT(!m_pageInspector); | 59 ASSERT(!m_pageInspector); |
| 60 m_pageInspector = pageInspector; | 60 m_pageInspector = pageInspector; |
| 61 m_workerThread->postDebuggerTask(createCrossThreadTask(connectToWorkerGlobal
ScopeInspectorTask, true)); | 61 m_workerThread->postDebuggerTask(createCrossThreadTask(connectToWorkerGlobal
ScopeInspectorTask, true)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 static void disconnectFromWorkerGlobalScopeInspectorTask(ExecutionContext* conte
xt, bool) | 64 static void disconnectFromWorkerGlobalScopeInspectorTask(ExecutionContext* conte
xt, bool) |
| 65 { | 65 { |
| 66 toWorkerGlobalScope(context)->workerInspectorController()->disconnectFronten
d(); | 66 toWorkerGlobalScope(context)->workerInspectorController()->disconnectFronten
d(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void WorkerInspectorProxy::disconnectFromInspector() | 69 void WorkerInspectorProxy::disconnectFromInspector() |
| 70 { | 70 { |
| 71 m_pageInspector = 0; | 71 m_pageInspector = nullptr; |
| 72 if (!m_workerThread) | 72 if (!m_workerThread) |
| 73 return; | 73 return; |
| 74 m_workerThread->postDebuggerTask(createCrossThreadTask(disconnectFromWorkerG
lobalScopeInspectorTask, true)); | 74 m_workerThread->postDebuggerTask(createCrossThreadTask(disconnectFromWorkerG
lobalScopeInspectorTask, true)); |
| 75 } | 75 } |
| 76 | 76 |
| 77 static void dispatchOnInspectorBackendTask(ExecutionContext* context, const Stri
ng& message) | 77 static void dispatchOnInspectorBackendTask(ExecutionContext* context, const Stri
ng& message) |
| 78 { | 78 { |
| 79 toWorkerGlobalScope(context)->workerInspectorController()->dispatchMessageFr
omFrontend(message); | 79 toWorkerGlobalScope(context)->workerInspectorController()->dispatchMessageFr
omFrontend(message); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void WorkerInspectorProxy::sendMessageToInspector(const String& message) | 82 void WorkerInspectorProxy::sendMessageToInspector(const String& message) |
| 83 { | 83 { |
| 84 if (!m_workerThread) | 84 if (!m_workerThread) |
| 85 return; | 85 return; |
| 86 m_workerThread->postDebuggerTask(createCrossThreadTask(dispatchOnInspectorBa
ckendTask, String(message))); | 86 m_workerThread->postDebuggerTask(createCrossThreadTask(dispatchOnInspectorBa
ckendTask, String(message))); |
| 87 m_workerThread->interruptAndDispatchInspectorCommands(); | 87 m_workerThread->interruptAndDispatchInspectorCommands(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void WorkerInspectorProxy::writeTimelineStartedEvent(const String& sessionId) | 90 void WorkerInspectorProxy::writeTimelineStartedEvent(const String& sessionId) |
| 91 { | 91 { |
| 92 if (!m_workerThread) | 92 if (!m_workerThread) |
| 93 return; | 93 return; |
| 94 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Tracin
gSessionIdForWorker", "data", InspectorTracingSessionIdForWorkerEvent::data(sess
ionId, m_workerThread)); | 94 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Tracin
gSessionIdForWorker", "data", InspectorTracingSessionIdForWorkerEvent::data(sess
ionId, m_workerThread)); |
| 95 } | 95 } |
| 96 | 96 |
| 97 } // namespace blink | 97 } // namespace blink |
| OLD | NEW |