| 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 "platform/v8_inspector/V8AsyncCallTracker.h" | 5 #include "platform/v8_inspector/V8AsyncCallTracker.h" |
| 6 | 6 |
| 7 #include "wtf/HashMap.h" | 7 #include "platform/inspector_protocol/Collections.h" |
| 8 #include "wtf/text/StringBuilder.h" | 8 #include "wtf/text/StringBuilder.h" |
| 9 #include "wtf/text/StringHash.h" | 9 #include "wtf/text/StringHash.h" |
| 10 #include "wtf/text/WTFString.h" | 10 #include "wtf/text/WTFString.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 static const char v8AsyncTaskEventEnqueue[] = "enqueue"; | 16 static const char v8AsyncTaskEventEnqueue[] = "enqueue"; |
| 17 static const char v8AsyncTaskEventWillHandle[] = "willHandle"; | 17 static const char v8AsyncTaskEventWillHandle[] = "willHandle"; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 38 ASSERT(m_idToOperations.isEmpty()); | 38 ASSERT(m_idToOperations.isEmpty()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void V8AsyncCallTracker::asyncCallTrackingStateChanged(bool) | 41 void V8AsyncCallTracker::asyncCallTrackingStateChanged(bool) |
| 42 { | 42 { |
| 43 } | 43 } |
| 44 | 44 |
| 45 void V8AsyncCallTracker::resetAsyncOperations() | 45 void V8AsyncCallTracker::resetAsyncOperations() |
| 46 { | 46 { |
| 47 for (auto& it : m_idToOperations) | 47 for (auto& it : m_idToOperations) |
| 48 completeOperations(it.value->map); | 48 completeOperations(it.second->map); |
| 49 m_idToOperations.clear(); | 49 m_idToOperations.clear(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void V8AsyncCallTracker::contextDisposed(int contextId) | 52 void V8AsyncCallTracker::contextDisposed(int contextId) |
| 53 { | 53 { |
| 54 completeOperations(m_idToOperations.get(contextId)->map); | 54 completeOperations(m_idToOperations.get(contextId)->map); |
| 55 m_idToOperations.remove(contextId); | 55 m_idToOperations.remove(contextId); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void V8AsyncCallTracker::didReceiveV8AsyncTaskEvent(v8::Local<v8::Context> conte
xt, const String& eventType, const String& eventName, int id) | 58 void V8AsyncCallTracker::didReceiveV8AsyncTaskEvent(v8::Local<v8::Context> conte
xt, const String& eventType, const String& eventName, int id) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 80 int operationId = m_debuggerAgent->traceAsyncOperationStarting(eventName); | 80 int operationId = m_debuggerAgent->traceAsyncOperationStarting(eventName); |
| 81 if (!operationId) | 81 if (!operationId) |
| 82 return; | 82 return; |
| 83 int contextId = V8Debugger::contextId(context); | 83 int contextId = V8Debugger::contextId(context); |
| 84 Operations* operations = m_idToOperations.get(contextId); | 84 Operations* operations = m_idToOperations.get(contextId); |
| 85 if (!operations) { | 85 if (!operations) { |
| 86 OwnPtr<Operations> newOperations = adoptPtr(new Operations()); | 86 OwnPtr<Operations> newOperations = adoptPtr(new Operations()); |
| 87 newOperations->contextId = contextId; | 87 newOperations->contextId = contextId; |
| 88 newOperations->target = this; | 88 newOperations->target = this; |
| 89 newOperations->context.Reset(context->GetIsolate(), context); | 89 newOperations->context.Reset(context->GetIsolate(), context); |
| 90 operations = m_idToOperations.set(contextId, newOperations.release()).st
oredValue->value.get(); | 90 operations = newOperations.get(); |
| 91 m_idToOperations.set(contextId, newOperations.release()); |
| 91 operations->context.SetWeak(operations, V8AsyncCallTracker::weakCallback
, v8::WeakCallbackType::kParameter); | 92 operations->context.SetWeak(operations, V8AsyncCallTracker::weakCallback
, v8::WeakCallbackType::kParameter); |
| 92 } | 93 } |
| 93 operations->map.set(makeV8AsyncTaskUniqueId(eventName, id), operationId); | 94 operations->map.set(makeV8AsyncTaskUniqueId(eventName, id), operationId); |
| 94 } | 95 } |
| 95 | 96 |
| 96 void V8AsyncCallTracker::willHandleV8AsyncTask(v8::Local<v8::Context> context, c
onst String& eventName, int id) | 97 void V8AsyncCallTracker::willHandleV8AsyncTask(v8::Local<v8::Context> context, c
onst String& eventName, int id) |
| 97 { | 98 { |
| 98 ASSERT(!context.IsEmpty()); | 99 ASSERT(!context.IsEmpty()); |
| 99 ASSERT(m_debuggerAgent->trackingAsyncCalls()); | 100 ASSERT(m_debuggerAgent->trackingAsyncCalls()); |
| 100 int contextId = V8Debugger::contextId(context); | 101 int contextId = V8Debugger::contextId(context); |
| 101 if (Operations* operations = m_idToOperations.get(contextId)) { | 102 if (Operations* operations = m_idToOperations.get(contextId)) { |
| 102 String taskId = makeV8AsyncTaskUniqueId(eventName, id); | 103 String taskId = makeV8AsyncTaskUniqueId(eventName, id); |
| 103 int operationId = operations->map.get(taskId); | 104 int operationId = operations->map.get(taskId); |
| 104 m_debuggerAgent->traceAsyncCallbackStarting(operationId); | 105 m_debuggerAgent->traceAsyncCallbackStarting(operationId); |
| 105 m_debuggerAgent->traceAsyncOperationCompleted(operationId); | 106 m_debuggerAgent->traceAsyncOperationCompleted(operationId); |
| 106 operations->map.remove(taskId); | 107 operations->map.remove(taskId); |
| 107 } else { | 108 } else { |
| 108 m_debuggerAgent->traceAsyncCallbackStarting(V8DebuggerAgentImpl::unknown
AsyncOperationId); | 109 m_debuggerAgent->traceAsyncCallbackStarting(V8DebuggerAgentImpl::unknown
AsyncOperationId); |
| 109 } | 110 } |
| 110 } | 111 } |
| 111 | 112 |
| 112 void V8AsyncCallTracker::completeOperations(const HashMap<String, int>& contextC
allChains) | 113 void V8AsyncCallTracker::completeOperations(const protocol::HashMap<String, int>
& contextCallChains) |
| 113 { | 114 { |
| 114 for (auto& it : contextCallChains) | 115 for (const auto& it : contextCallChains) |
| 115 m_debuggerAgent->traceAsyncOperationCompleted(it.value); | 116 m_debuggerAgent->traceAsyncOperationCompleted(*it.second); |
| 116 } | 117 } |
| 117 | 118 |
| 118 } // namespace blink | 119 } // namespace blink |
| OLD | NEW |