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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8AsyncCallTracker.cpp

Issue 1767883002: DevTools: generate string16-based handlers for v8_inspector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for landing 2 Created 4 years, 9 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
OLDNEW
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 "platform/inspector_protocol/Collections.h" 7 #include "platform/inspector_protocol/Collections.h"
8 #include "wtf/text/StringBuilder.h" 8 #include "platform/inspector_protocol/String16.h"
9 #include "wtf/text/StringHash.h"
10 #include "wtf/text/WTFString.h"
11 9
12 namespace blink { 10 namespace blink {
13 11
14 namespace { 12 namespace {
15 13
16 static const char v8AsyncTaskEventEnqueue[] = "enqueue"; 14 static const char v8AsyncTaskEventEnqueue[] = "enqueue";
17 static const char v8AsyncTaskEventWillHandle[] = "willHandle"; 15 static const char v8AsyncTaskEventWillHandle[] = "willHandle";
18 static const char v8AsyncTaskEventDidHandle[] = "didHandle"; 16 static const char v8AsyncTaskEventDidHandle[] = "didHandle";
19 17
20 } 18 }
21 19
22 static String makeV8AsyncTaskUniqueId(const String& eventName, int id) 20 static String16 makeV8AsyncTaskUniqueId(const String16& eventName, int id)
23 { 21 {
24 StringBuilder builder; 22 String16Builder builder;
25 builder.append(eventName); 23 builder.append(eventName);
26 builder.append(" -> "); 24 builder.append(" -> ");
27 builder.appendNumber(id); 25 builder.appendNumber(id);
28 return builder.toString(); 26 return builder.toString();
29 } 27 }
30 28
31 V8AsyncCallTracker::V8AsyncCallTracker(V8DebuggerAgentImpl* debuggerAgent) 29 V8AsyncCallTracker::V8AsyncCallTracker(V8DebuggerAgentImpl* debuggerAgent)
32 : m_debuggerAgent(debuggerAgent) 30 : m_debuggerAgent(debuggerAgent)
33 { 31 {
34 } 32 }
(...skipping 13 matching lines...) Expand all
48 completeOperations(it.second->map); 46 completeOperations(it.second->map);
49 m_idToOperations.clear(); 47 m_idToOperations.clear();
50 } 48 }
51 49
52 void V8AsyncCallTracker::contextDisposed(int contextId) 50 void V8AsyncCallTracker::contextDisposed(int contextId)
53 { 51 {
54 completeOperations(m_idToOperations.get(contextId)->map); 52 completeOperations(m_idToOperations.get(contextId)->map);
55 m_idToOperations.remove(contextId); 53 m_idToOperations.remove(contextId);
56 } 54 }
57 55
58 void V8AsyncCallTracker::didReceiveV8AsyncTaskEvent(v8::Local<v8::Context> conte xt, const String& eventType, const String& eventName, int id) 56 void V8AsyncCallTracker::didReceiveV8AsyncTaskEvent(v8::Local<v8::Context> conte xt, const String16& eventType, const String16& eventName, int id)
59 { 57 {
60 ASSERT(m_debuggerAgent->trackingAsyncCalls()); 58 ASSERT(m_debuggerAgent->trackingAsyncCalls());
61 if (eventType == v8AsyncTaskEventEnqueue) 59 if (eventType == v8AsyncTaskEventEnqueue)
62 didEnqueueV8AsyncTask(context, eventName, id); 60 didEnqueueV8AsyncTask(context, eventName, id);
63 else if (eventType == v8AsyncTaskEventWillHandle) 61 else if (eventType == v8AsyncTaskEventWillHandle)
64 willHandleV8AsyncTask(context, eventName, id); 62 willHandleV8AsyncTask(context, eventName, id);
65 else if (eventType == v8AsyncTaskEventDidHandle) 63 else if (eventType == v8AsyncTaskEventDidHandle)
66 m_debuggerAgent->traceAsyncCallbackCompleted(); 64 m_debuggerAgent->traceAsyncCallbackCompleted();
67 else 65 else
68 ASSERT_NOT_REACHED(); 66 ASSERT_NOT_REACHED();
69 } 67 }
70 68
71 void V8AsyncCallTracker::weakCallback(const v8::WeakCallbackInfo<Operations>& da ta) 69 void V8AsyncCallTracker::weakCallback(const v8::WeakCallbackInfo<Operations>& da ta)
72 { 70 {
73 data.GetParameter()->target->contextDisposed(data.GetParameter()->contextId) ; 71 data.GetParameter()->target->contextDisposed(data.GetParameter()->contextId) ;
74 } 72 }
75 73
76 void V8AsyncCallTracker::didEnqueueV8AsyncTask(v8::Local<v8::Context> context, c onst String& eventName, int id) 74 void V8AsyncCallTracker::didEnqueueV8AsyncTask(v8::Local<v8::Context> context, c onst String16& eventName, int id)
77 { 75 {
78 ASSERT(!context.IsEmpty()); 76 ASSERT(!context.IsEmpty());
79 ASSERT(m_debuggerAgent->trackingAsyncCalls()); 77 ASSERT(m_debuggerAgent->trackingAsyncCalls());
80 int operationId = m_debuggerAgent->traceAsyncOperationStarting(eventName); 78 int operationId = m_debuggerAgent->traceAsyncOperationStarting(eventName);
81 if (!operationId) 79 if (!operationId)
82 return; 80 return;
83 int contextId = V8Debugger::contextId(context); 81 int contextId = V8Debugger::contextId(context);
84 Operations* operations = m_idToOperations.get(contextId); 82 Operations* operations = m_idToOperations.get(contextId);
85 if (!operations) { 83 if (!operations) {
86 OwnPtr<Operations> newOperations = adoptPtr(new Operations()); 84 OwnPtr<Operations> newOperations = adoptPtr(new Operations());
87 newOperations->contextId = contextId; 85 newOperations->contextId = contextId;
88 newOperations->target = this; 86 newOperations->target = this;
89 newOperations->context.Reset(context->GetIsolate(), context); 87 newOperations->context.Reset(context->GetIsolate(), context);
90 operations = newOperations.get(); 88 operations = newOperations.get();
91 m_idToOperations.set(contextId, newOperations.release()); 89 m_idToOperations.set(contextId, newOperations.release());
92 operations->context.SetWeak(operations, V8AsyncCallTracker::weakCallback , v8::WeakCallbackType::kParameter); 90 operations->context.SetWeak(operations, V8AsyncCallTracker::weakCallback , v8::WeakCallbackType::kParameter);
93 } 91 }
94 operations->map.set(makeV8AsyncTaskUniqueId(eventName, id), operationId); 92 operations->map.set(makeV8AsyncTaskUniqueId(eventName, id), operationId);
95 } 93 }
96 94
97 void V8AsyncCallTracker::willHandleV8AsyncTask(v8::Local<v8::Context> context, c onst String& eventName, int id) 95 void V8AsyncCallTracker::willHandleV8AsyncTask(v8::Local<v8::Context> context, c onst String16& eventName, int id)
98 { 96 {
99 ASSERT(!context.IsEmpty()); 97 ASSERT(!context.IsEmpty());
100 ASSERT(m_debuggerAgent->trackingAsyncCalls()); 98 ASSERT(m_debuggerAgent->trackingAsyncCalls());
101 int contextId = V8Debugger::contextId(context); 99 int contextId = V8Debugger::contextId(context);
102 if (Operations* operations = m_idToOperations.get(contextId)) { 100 if (Operations* operations = m_idToOperations.get(contextId)) {
103 String taskId = makeV8AsyncTaskUniqueId(eventName, id); 101 String16 taskId = makeV8AsyncTaskUniqueId(eventName, id);
104 int operationId = operations->map.get(taskId); 102 int operationId = operations->map.get(taskId);
105 m_debuggerAgent->traceAsyncCallbackStarting(operationId); 103 m_debuggerAgent->traceAsyncCallbackStarting(operationId);
106 m_debuggerAgent->traceAsyncOperationCompleted(operationId); 104 m_debuggerAgent->traceAsyncOperationCompleted(operationId);
107 operations->map.remove(taskId); 105 operations->map.remove(taskId);
108 } else { 106 } else {
109 m_debuggerAgent->traceAsyncCallbackStarting(V8DebuggerAgentImpl::unknown AsyncOperationId); 107 m_debuggerAgent->traceAsyncCallbackStarting(V8DebuggerAgentImpl::unknown AsyncOperationId);
110 } 108 }
111 } 109 }
112 110
113 void V8AsyncCallTracker::completeOperations(const protocol::HashMap<String, int> & contextCallChains) 111 void V8AsyncCallTracker::completeOperations(const protocol::HashMap<String16, in t>& contextCallChains)
114 { 112 {
115 for (const auto& it : contextCallChains) 113 for (const auto& it : contextCallChains)
116 m_debuggerAgent->traceAsyncOperationCompleted(*it.second); 114 m_debuggerAgent->traceAsyncOperationCompleted(*it.second);
117 } 115 }
118 116
119 } // namespace blink 117 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698