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

Side by Side Diff: third_party/WebKit/Source/core/inspector/V8AsyncCallTracker.cpp

Issue 1367623006: DevTools: extract V8DebuggerAgent interface, move it under .../inspector/v8 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/inspector/V8AsyncCallTracker.h"
7
8 #include "bindings/core/v8/V8PerContextData.h"
9 #include "core/inspector/AsyncOperationMap.h"
10 #include "platform/heap/Handle.h"
11 #include "wtf/HashMap.h"
12 #include "wtf/text/StringBuilder.h"
13 #include "wtf/text/StringHash.h"
14 #include "wtf/text/WTFString.h"
15
16 namespace blink {
17
18 namespace {
19
20 static const char v8AsyncTaskEventEnqueue[] = "enqueue";
21 static const char v8AsyncTaskEventWillHandle[] = "willHandle";
22 static const char v8AsyncTaskEventDidHandle[] = "didHandle";
23
24 }
25
26 class V8AsyncCallTracker::V8ContextAsyncOperations final : public NoBaseWillBeGa rbageCollectedFinalized<V8AsyncCallTracker::V8ContextAsyncOperations> {
27 WTF_MAKE_NONCOPYABLE(V8ContextAsyncOperations);
28 public:
29 explicit V8ContextAsyncOperations(V8DebuggerAgent* debuggerAgent)
30 : m_v8AsyncOperations(debuggerAgent)
31 {
32 }
33
34 ~V8ContextAsyncOperations()
35 {
36 ASSERT(m_v8AsyncOperations.hasBeenDisposed());
37 }
38
39 void dispose()
40 {
41 // FIXME: get rid of the dispose method and this class altogether once A syncOperationMap is always allocated on C++ heap.
42 m_v8AsyncOperations.dispose();
43 }
44
45 DEFINE_INLINE_TRACE()
46 {
47 #if ENABLE(OILPAN)
48 visitor->trace(m_v8AsyncOperations);
49 #endif
50 }
51
52 AsyncOperationMap<String> m_v8AsyncOperations;
53 };
54
55 static String makeV8AsyncTaskUniqueId(const String& eventName, int id)
56 {
57 StringBuilder builder;
58 builder.append(eventName);
59 builder.append(" -> ");
60 builder.appendNumber(id);
61 return builder.toString();
62 }
63
64 V8AsyncCallTracker::V8AsyncCallTracker(V8DebuggerAgent* debuggerAgent) : m_debug gerAgent(debuggerAgent)
65 {
66 m_debuggerAgent->addAsyncCallTrackingListener(this);
67 }
68
69 V8AsyncCallTracker::~V8AsyncCallTracker()
70 {
71 ASSERT(m_contextAsyncOperationMap.isEmpty());
72 #if !ENABLE(OILPAN)
73 m_debuggerAgent->removeAsyncCallTrackingListener(this);
74 #endif
75 }
76
77 DEFINE_TRACE(V8AsyncCallTracker)
78 {
79 #if ENABLE(OILPAN)
80 visitor->trace(m_contextAsyncOperationMap);
81 visitor->trace(m_debuggerAgent);
82 #endif
83 V8DebuggerAgent::AsyncCallTrackingListener::trace(visitor);
84 }
85
86 void V8AsyncCallTracker::asyncCallTrackingStateChanged(bool)
87 {
88 }
89
90 void V8AsyncCallTracker::resetAsyncOperations()
91 {
92 for (auto& it : m_contextAsyncOperationMap) {
93 it.key->removeObserver(this);
94 it.value->dispose();
95 }
96 m_contextAsyncOperationMap.clear();
97 }
98
99 void V8AsyncCallTracker::willDisposeScriptState(ScriptState* state)
100 {
101 m_contextAsyncOperationMap.remove(state);
102 }
103
104 void V8AsyncCallTracker::didReceiveV8AsyncTaskEvent(ScriptState* state, const St ring& eventType, const String& eventName, int id)
105 {
106 ASSERT(m_debuggerAgent->trackingAsyncCalls());
107 if (eventType == v8AsyncTaskEventEnqueue)
108 didEnqueueV8AsyncTask(state, eventName, id);
109 else if (eventType == v8AsyncTaskEventWillHandle)
110 willHandleV8AsyncTask(state, eventName, id);
111 else if (eventType == v8AsyncTaskEventDidHandle)
112 m_debuggerAgent->traceAsyncCallbackCompleted();
113 else
114 ASSERT_NOT_REACHED();
115 }
116
117 void V8AsyncCallTracker::didEnqueueV8AsyncTask(ScriptState* state, const String& eventName, int id)
118 {
119 ASSERT(state);
120 ASSERT(m_debuggerAgent->trackingAsyncCalls());
121 int operationId = m_debuggerAgent->traceAsyncOperationStarting(eventName);
122 if (!operationId)
123 return;
124 V8ContextAsyncOperations* contextCallChains = m_contextAsyncOperationMap.get (state);
125 if (!contextCallChains)
126 contextCallChains = m_contextAsyncOperationMap.set(state, adoptPtrWillBe Noop(new V8ContextAsyncOperations(m_debuggerAgent))).storedValue->value.get();
127 contextCallChains->m_v8AsyncOperations.set(makeV8AsyncTaskUniqueId(eventName , id), operationId);
128 }
129
130 void V8AsyncCallTracker::willHandleV8AsyncTask(ScriptState* state, const String& eventName, int id)
131 {
132 ASSERT(state);
133 ASSERT(m_debuggerAgent->trackingAsyncCalls());
134 if (V8ContextAsyncOperations* contextCallChains = m_contextAsyncOperationMap .get(state)) {
135 String taskId = makeV8AsyncTaskUniqueId(eventName, id);
136 m_debuggerAgent->traceAsyncCallbackStarting(contextCallChains->m_v8Async Operations.get(taskId));
137 contextCallChains->m_v8AsyncOperations.remove(taskId);
138 } else {
139 m_debuggerAgent->traceAsyncCallbackStarting(V8DebuggerAgent::unknownAsyn cOperationId);
140 }
141 }
142
143 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698