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

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

Issue 2004313003: DevTools: migrate from OwnPtr to std::unique_ptr for inspector protocol classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined Created 4 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/V8InspectorSessionImpl.h" 5 #include "platform/v8_inspector/V8InspectorSessionImpl.h"
6 6
7 #include "platform/inspector_protocol/Parser.h" 7 #include "platform/inspector_protocol/Parser.h"
8 #include "platform/v8_inspector/InjectedScript.h" 8 #include "platform/v8_inspector/InjectedScript.h"
9 #include "platform/v8_inspector/InspectedContext.h" 9 #include "platform/v8_inspector/InspectedContext.h"
10 #include "platform/v8_inspector/RemoteObjectId.h" 10 #include "platform/v8_inspector/RemoteObjectId.h"
11 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" 11 #include "platform/v8_inspector/V8DebuggerAgentImpl.h"
12 #include "platform/v8_inspector/V8DebuggerImpl.h" 12 #include "platform/v8_inspector/V8DebuggerImpl.h"
13 #include "platform/v8_inspector/V8HeapProfilerAgentImpl.h" 13 #include "platform/v8_inspector/V8HeapProfilerAgentImpl.h"
14 #include "platform/v8_inspector/V8ProfilerAgentImpl.h" 14 #include "platform/v8_inspector/V8ProfilerAgentImpl.h"
15 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" 15 #include "platform/v8_inspector/V8RuntimeAgentImpl.h"
16 #include "platform/v8_inspector/public/V8ContextInfo.h" 16 #include "platform/v8_inspector/public/V8ContextInfo.h"
17 #include "platform/v8_inspector/public/V8DebuggerClient.h" 17 #include "platform/v8_inspector/public/V8DebuggerClient.h"
18 18
19 namespace blink { 19 namespace blink {
20 20
21 const char V8InspectorSession::backtraceObjectGroup[] = "backtrace"; 21 const char V8InspectorSession::backtraceObjectGroup[] = "backtrace";
22 22
23 // static 23 // static
24 bool V8InspectorSession::isV8ProtocolMethod(const String16& method) 24 bool V8InspectorSession::isV8ProtocolMethod(const String16& method)
25 { 25 {
26 return method.startWith("Debugger.") || method.startWith("HeapProfiler.") || method.startWith("Profiler.") || method.startWith("Runtime."); 26 return method.startWith("Debugger.") || method.startWith("HeapProfiler.") || method.startWith("Profiler.") || method.startWith("Runtime.");
27 } 27 }
28 28
29 PassOwnPtr<V8InspectorSessionImpl> V8InspectorSessionImpl::create(V8DebuggerImpl * debugger, int contextGroupId, V8InspectorSessionClient* client, const String16 * state) 29 std::unique_ptr<V8InspectorSessionImpl> V8InspectorSessionImpl::create(V8Debugge rImpl* debugger, int contextGroupId, V8InspectorSessionClient* client, const Str ing16* state)
30 { 30 {
31 return adoptPtr(new V8InspectorSessionImpl(debugger, contextGroupId, client, state)); 31 return wrapUnique(new V8InspectorSessionImpl(debugger, contextGroupId, clien t, state));
32 } 32 }
33 33
34 V8InspectorSessionImpl::V8InspectorSessionImpl(V8DebuggerImpl* debugger, int con textGroupId, V8InspectorSessionClient* client, const String16* savedState) 34 V8InspectorSessionImpl::V8InspectorSessionImpl(V8DebuggerImpl* debugger, int con textGroupId, V8InspectorSessionClient* client, const String16* savedState)
35 : m_contextGroupId(contextGroupId) 35 : m_contextGroupId(contextGroupId)
36 , m_debugger(debugger) 36 , m_debugger(debugger)
37 , m_client(client) 37 , m_client(client)
38 , m_customObjectFormatterEnabled(false) 38 , m_customObjectFormatterEnabled(false)
39 , m_instrumentationCounter(0) 39 , m_instrumentationCounter(0)
40 , m_frontend(adoptPtr(new protocol::Frontend(client))) 40 , m_frontend(new protocol::Frontend(client))
41 , m_dispatcher(protocol::Dispatcher::create(client)) 41 , m_dispatcher(protocol::Dispatcher::create(client))
42 , m_state(nullptr) 42 , m_state(nullptr)
43 , m_runtimeAgent(nullptr) 43 , m_runtimeAgent(nullptr)
44 , m_debuggerAgent(nullptr) 44 , m_debuggerAgent(nullptr)
45 , m_heapProfilerAgent(nullptr) 45 , m_heapProfilerAgent(nullptr)
46 , m_profilerAgent(nullptr) 46 , m_profilerAgent(nullptr)
47 { 47 {
48 if (savedState) { 48 if (savedState) {
49 OwnPtr<protocol::Value> state = protocol::parseJSON(*savedState); 49 std::unique_ptr<protocol::Value> state = protocol::parseJSON(*savedState );
50 if (state) 50 if (state)
51 m_state = protocol::DictionaryValue::cast(std::move(state)); 51 m_state = protocol::DictionaryValue::cast(std::move(state));
52 if (!m_state) 52 if (!m_state)
53 m_state = protocol::DictionaryValue::create(); 53 m_state = protocol::DictionaryValue::create();
54 } else { 54 } else {
55 m_state = protocol::DictionaryValue::create(); 55 m_state = protocol::DictionaryValue::create();
56 } 56 }
57 57
58 m_runtimeAgent = adoptPtr(new V8RuntimeAgentImpl(this, protocol::Frontend::R untime::from(m_frontend.get()), agentState("Runtime"))); 58 m_runtimeAgent = wrapUnique(new V8RuntimeAgentImpl(this, protocol::Frontend: :Runtime::from(m_frontend.get()), agentState("Runtime")));
59 m_dispatcher->registerAgent(static_cast<protocol::Backend::Runtime*>(m_runti meAgent.get())); 59 m_dispatcher->registerAgent(static_cast<protocol::Backend::Runtime*>(m_runti meAgent.get()));
60 60
61 m_debuggerAgent = adoptPtr(new V8DebuggerAgentImpl(this, protocol::Frontend: :Debugger::from(m_frontend.get()), agentState("Debugger"))); 61 m_debuggerAgent = wrapUnique(new V8DebuggerAgentImpl(this, protocol::Fronten d::Debugger::from(m_frontend.get()), agentState("Debugger")));
62 m_dispatcher->registerAgent(static_cast<protocol::Backend::Debugger*>(m_debu ggerAgent.get())); 62 m_dispatcher->registerAgent(static_cast<protocol::Backend::Debugger*>(m_debu ggerAgent.get()));
63 63
64 m_heapProfilerAgent = adoptPtr(new V8HeapProfilerAgentImpl(this, protocol::F rontend::HeapProfiler::from(m_frontend.get()), agentState("HeapProfiler"))); 64 m_heapProfilerAgent = wrapUnique(new V8HeapProfilerAgentImpl(this, protocol: :Frontend::HeapProfiler::from(m_frontend.get()), agentState("HeapProfiler")));
65 m_dispatcher->registerAgent(static_cast<protocol::Backend::HeapProfiler*>(m_ heapProfilerAgent.get())); 65 m_dispatcher->registerAgent(static_cast<protocol::Backend::HeapProfiler*>(m_ heapProfilerAgent.get()));
66 66
67 m_profilerAgent = adoptPtr(new V8ProfilerAgentImpl(this, protocol::Frontend: :Profiler::from(m_frontend.get()), agentState("Profiler"))); 67 m_profilerAgent = wrapUnique(new V8ProfilerAgentImpl(this, protocol::Fronten d::Profiler::from(m_frontend.get()), agentState("Profiler")));
68 m_dispatcher->registerAgent(static_cast<protocol::Backend::Profiler*>(m_prof ilerAgent.get())); 68 m_dispatcher->registerAgent(static_cast<protocol::Backend::Profiler*>(m_prof ilerAgent.get()));
69 69
70 if (savedState) { 70 if (savedState) {
71 m_runtimeAgent->restore(); 71 m_runtimeAgent->restore();
72 m_debuggerAgent->restore(); 72 m_debuggerAgent->restore();
73 m_heapProfilerAgent->restore(); 73 m_heapProfilerAgent->restore();
74 m_profilerAgent->restore(); 74 m_profilerAgent->restore();
75 } 75 }
76 } 76 }
77 77
78 V8InspectorSessionImpl::~V8InspectorSessionImpl() 78 V8InspectorSessionImpl::~V8InspectorSessionImpl()
79 { 79 {
80 m_dispatcher->clearFrontend(); 80 m_dispatcher->clearFrontend();
81 m_dispatcher.clear(); 81 m_dispatcher.reset();
82 82
83 ErrorString errorString; 83 ErrorString errorString;
84 m_profilerAgent->disable(&errorString); 84 m_profilerAgent->disable(&errorString);
85 m_heapProfilerAgent->disable(&errorString); 85 m_heapProfilerAgent->disable(&errorString);
86 m_debuggerAgent->disable(&errorString); 86 m_debuggerAgent->disable(&errorString);
87 m_runtimeAgent->disable(&errorString); 87 m_runtimeAgent->disable(&errorString);
88 88
89 m_frontend.clear(); 89 m_frontend.reset();
90 discardInjectedScripts(); 90 discardInjectedScripts();
91 m_debugger->disconnect(this); 91 m_debugger->disconnect(this);
92 } 92 }
93 93
94 protocol::DictionaryValue* V8InspectorSessionImpl::agentState(const String16& na me) 94 protocol::DictionaryValue* V8InspectorSessionImpl::agentState(const String16& na me)
95 { 95 {
96 protocol::DictionaryValue* state = m_state->getObject(name); 96 protocol::DictionaryValue* state = m_state->getObject(name);
97 if (!state) { 97 if (!state) {
98 OwnPtr<protocol::DictionaryValue> newState = protocol::DictionaryValue:: create(); 98 std::unique_ptr<protocol::DictionaryValue> newState = protocol::Dictiona ryValue::create();
99 state = newState.get(); 99 state = newState.get();
100 m_state->setObject(name, std::move(newState)); 100 m_state->setObject(name, std::move(newState));
101 } 101 }
102 return state; 102 return state;
103 } 103 }
104 104
105 void V8InspectorSessionImpl::reset() 105 void V8InspectorSessionImpl::reset()
106 { 106 {
107 m_debuggerAgent->reset(); 107 m_debuggerAgent->reset();
108 m_runtimeAgent->reset(); 108 m_runtimeAgent->reset();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 if (contexts && contexts->contains(key)) { 171 if (contexts && contexts->contains(key)) {
172 InjectedScript* injectedScript = contexts->get(key)->getInjectedScri pt(); 172 InjectedScript* injectedScript = contexts->get(key)->getInjectedScri pt();
173 if (injectedScript) 173 if (injectedScript)
174 injectedScript->releaseObjectGroup(objectGroup); // This may des troy some contexts. 174 injectedScript->releaseObjectGroup(objectGroup); // This may des troy some contexts.
175 } 175 }
176 } 176 }
177 } 177 }
178 178
179 v8::Local<v8::Value> V8InspectorSessionImpl::findObject(ErrorString* errorString , const String16& objectId, v8::Local<v8::Context>* context, String16* groupName ) 179 v8::Local<v8::Value> V8InspectorSessionImpl::findObject(ErrorString* errorString , const String16& objectId, v8::Local<v8::Context>* context, String16* groupName )
180 { 180 {
181 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString, objectI d); 181 std::unique_ptr<RemoteObjectId> remoteId = RemoteObjectId::parse(errorString , objectId);
182 if (!remoteId) 182 if (!remoteId)
183 return v8::Local<v8::Value>(); 183 return v8::Local<v8::Value>();
184 InjectedScript* injectedScript = findInjectedScript(errorString, remoteId.ge t()); 184 InjectedScript* injectedScript = findInjectedScript(errorString, remoteId.ge t());
185 if (!injectedScript) 185 if (!injectedScript)
186 return v8::Local<v8::Value>(); 186 return v8::Local<v8::Value>();
187 v8::Local<v8::Value> objectValue; 187 v8::Local<v8::Value> objectValue;
188 injectedScript->findObject(errorString, *remoteId, &objectValue); 188 injectedScript->findObject(errorString, *remoteId, &objectValue);
189 if (objectValue.IsEmpty()) 189 if (objectValue.IsEmpty())
190 return v8::Local<v8::Value>(); 190 return v8::Local<v8::Value>();
191 if (context) 191 if (context)
192 *context = injectedScript->context()->context(); 192 *context = injectedScript->context()->context();
193 if (groupName) 193 if (groupName)
194 *groupName = injectedScript->objectGroupName(*remoteId); 194 *groupName = injectedScript->objectGroupName(*remoteId);
195 return objectValue; 195 return objectValue;
196 } 196 }
197 197
198 PassOwnPtr<protocol::Runtime::RemoteObject> V8InspectorSessionImpl::wrapObject(v 8::Local<v8::Context> context, v8::Local<v8::Value> value, const String16& group Name, bool generatePreview) 198 std::unique_ptr<protocol::Runtime::RemoteObject> V8InspectorSessionImpl::wrapObj ect(v8::Local<v8::Context> context, v8::Local<v8::Value> value, const String16& groupName, bool generatePreview)
199 { 199 {
200 ErrorString errorString; 200 ErrorString errorString;
201 InjectedScript* injectedScript = findInjectedScript(&errorString, V8Debugger ::contextId(context)); 201 InjectedScript* injectedScript = findInjectedScript(&errorString, V8Debugger ::contextId(context));
202 if (!injectedScript) 202 if (!injectedScript)
203 return nullptr; 203 return nullptr;
204 return injectedScript->wrapObject(&errorString, value, groupName, false, gen eratePreview); 204 return injectedScript->wrapObject(&errorString, value, groupName, false, gen eratePreview);
205 } 205 }
206 206
207 PassOwnPtr<protocol::Runtime::RemoteObject> V8InspectorSessionImpl::wrapTable(v8 ::Local<v8::Context> context, v8::Local<v8::Value> table, v8::Local<v8::Value> c olumns) 207 std::unique_ptr<protocol::Runtime::RemoteObject> V8InspectorSessionImpl::wrapTab le(v8::Local<v8::Context> context, v8::Local<v8::Value> table, v8::Local<v8::Val ue> columns)
208 { 208 {
209 ErrorString errorString; 209 ErrorString errorString;
210 InjectedScript* injectedScript = findInjectedScript(&errorString, V8Debugger ::contextId(context)); 210 InjectedScript* injectedScript = findInjectedScript(&errorString, V8Debugger ::contextId(context));
211 if (!injectedScript) 211 if (!injectedScript)
212 return nullptr; 212 return nullptr;
213 return injectedScript->wrapTable(table, columns); 213 return injectedScript->wrapTable(table, columns);
214 } 214 }
215 215
216 void V8InspectorSessionImpl::setCustomObjectFormatterEnabled(bool enabled) 216 void V8InspectorSessionImpl::setCustomObjectFormatterEnabled(bool enabled)
217 { 217 {
(...skipping 30 matching lines...) Expand all
248 void V8InspectorSessionImpl::dispatchProtocolMessage(const String16& message) 248 void V8InspectorSessionImpl::dispatchProtocolMessage(const String16& message)
249 { 249 {
250 m_dispatcher->dispatch(message); 250 m_dispatcher->dispatch(message);
251 } 251 }
252 252
253 String16 V8InspectorSessionImpl::stateJSON() 253 String16 V8InspectorSessionImpl::stateJSON()
254 { 254 {
255 return m_state->toJSONString(); 255 return m_state->toJSONString();
256 } 256 }
257 257
258 void V8InspectorSessionImpl::addInspectedObject(PassOwnPtr<V8InspectorSession::I nspectable> inspectable) 258 void V8InspectorSessionImpl::addInspectedObject(std::unique_ptr<V8InspectorSessi on::Inspectable> inspectable)
259 { 259 {
260 m_inspectedObjects.prepend(std::move(inspectable)); 260 m_inspectedObjects.prepend(std::move(inspectable));
261 while (m_inspectedObjects.size() > kInspectedObjectBufferSize) 261 while (m_inspectedObjects.size() > kInspectedObjectBufferSize)
262 m_inspectedObjects.removeLast(); 262 m_inspectedObjects.removeLast();
263 } 263 }
264 264
265 V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject(unsigne d num) 265 V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject(unsigne d num)
266 { 266 {
267 if (num >= m_inspectedObjects.size()) 267 if (num >= m_inspectedObjects.size())
268 return nullptr; 268 return nullptr;
269 return m_inspectedObjects[num]; 269 return m_inspectedObjects[num];
270 } 270 }
271 271
272 void V8InspectorSessionImpl::schedulePauseOnNextStatement(const String16& breakR eason, PassOwnPtr<protocol::DictionaryValue> data) 272 void V8InspectorSessionImpl::schedulePauseOnNextStatement(const String16& breakR eason, std::unique_ptr<protocol::DictionaryValue> data)
273 { 273 {
274 m_debuggerAgent->schedulePauseOnNextStatement(breakReason, std::move(data)); 274 m_debuggerAgent->schedulePauseOnNextStatement(breakReason, std::move(data));
275 } 275 }
276 276
277 void V8InspectorSessionImpl::cancelPauseOnNextStatement() 277 void V8InspectorSessionImpl::cancelPauseOnNextStatement()
278 { 278 {
279 m_debuggerAgent->cancelPauseOnNextStatement(); 279 m_debuggerAgent->cancelPauseOnNextStatement();
280 } 280 }
281 281
282 void V8InspectorSessionImpl::breakProgram(const String16& breakReason, PassOwnPt r<protocol::DictionaryValue> data) 282 void V8InspectorSessionImpl::breakProgram(const String16& breakReason, std::uniq ue_ptr<protocol::DictionaryValue> data)
283 { 283 {
284 m_debuggerAgent->breakProgram(breakReason, std::move(data)); 284 m_debuggerAgent->breakProgram(breakReason, std::move(data));
285 } 285 }
286 286
287 void V8InspectorSessionImpl::breakProgramOnException(const String16& breakReason , PassOwnPtr<protocol::DictionaryValue> data) 287 void V8InspectorSessionImpl::breakProgramOnException(const String16& breakReason , std::unique_ptr<protocol::DictionaryValue> data)
288 { 288 {
289 m_debuggerAgent->breakProgramOnException(breakReason, std::move(data)); 289 m_debuggerAgent->breakProgramOnException(breakReason, std::move(data));
290 } 290 }
291 291
292 void V8InspectorSessionImpl::setSkipAllPauses(bool skip) 292 void V8InspectorSessionImpl::setSkipAllPauses(bool skip)
293 { 293 {
294 ErrorString errorString; 294 ErrorString errorString;
295 m_debuggerAgent->setSkipAllPauses(&errorString, skip); 295 m_debuggerAgent->setSkipAllPauses(&errorString, skip);
296 } 296 }
297 297
(...skipping 28 matching lines...) Expand all
326 { 326 {
327 m_debuggerAgent->asyncTaskFinished(task); 327 m_debuggerAgent->asyncTaskFinished(task);
328 } 328 }
329 329
330 void V8InspectorSessionImpl::allAsyncTasksCanceled() 330 void V8InspectorSessionImpl::allAsyncTasksCanceled()
331 { 331 {
332 m_debuggerAgent->allAsyncTasksCanceled(); 332 m_debuggerAgent->allAsyncTasksCanceled();
333 } 333 }
334 334
335 } // namespace blink 335 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698