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

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/Dispatcher_cpp.template

Issue 1979963002: Remove OwnPtr::release() calls in platform/ (part inspector). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 // This file is generated 1 // This file is generated
2 2
3 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 3 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be 4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file. 5 // found in the LICENSE file.
6 6
7 #include "platform/inspector_protocol/{{class_name}}.h" 7 #include "platform/inspector_protocol/{{class_name}}.h"
8 8
9 #include "platform/inspector_protocol/Collections.h" 9 #include "platform/inspector_protocol/Collections.h"
10 #include "platform/inspector_protocol/FrontendChannel.h" 10 #include "platform/inspector_protocol/FrontendChannel.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 m_frontendChannel = nullptr; 60 m_frontendChannel = nullptr;
61 for (auto& weak : m_weakPtrs) 61 for (auto& weak : m_weakPtrs)
62 weak.first->dispose(); 62 weak.first->dispose();
63 m_weakPtrs.clear(); 63 m_weakPtrs.clear();
64 } 64 }
65 65
66 PassOwnPtr<DispatcherImplWeakPtr> weakPtr() 66 PassOwnPtr<DispatcherImplWeakPtr> weakPtr()
67 { 67 {
68 OwnPtr<DispatcherImplWeakPtr> weak = adoptPtr(new DispatcherImplWeakPtr( this)); 68 OwnPtr<DispatcherImplWeakPtr> weak = adoptPtr(new DispatcherImplWeakPtr( this));
69 m_weakPtrs.add(weak.get()); 69 m_weakPtrs.add(weak.get());
70 return weak.release(); 70 return weak;
71 } 71 }
72 72
73 virtual void dispatch(int sessionId, const String16& message); 73 virtual void dispatch(int sessionId, const String16& message);
74 virtual void reportProtocolError(int sessionId, int callId, CommonErrorCode, const String16& errorMessage, ErrorSupport* errors) const; 74 virtual void reportProtocolError(int sessionId, int callId, CommonErrorCode, const String16& errorMessage, ErrorSupport* errors) const;
75 using Dispatcher::reportProtocolError; 75 using Dispatcher::reportProtocolError;
76 76
77 void sendResponse(int sessionId, int callId, const ErrorString& invocationEr ror, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> result); 77 void sendResponse(int sessionId, int callId, const ErrorString& invocationEr ror, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> result);
78 78
79 {% for domain in api.domains %} 79 {% for domain in api.domains %}
80 virtual void registerAgent(blink::protocol::Backend::{{domain.domain}}* agen t) { ASSERT(!m_{{domain.domain | lower}}Agent); m_{{domain.domain | lower}}Agent = agent; } 80 virtual void registerAgent(blink::protocol::Backend::{{domain.domain}}* agen t) { ASSERT(!m_{{domain.domain | lower}}Agent); m_{{domain.domain | lower}}Agent = agent; }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 { 171 {
172 OwnPtr<protocol::DictionaryValue> resultObject = DictionaryValue::create (); 172 OwnPtr<protocol::DictionaryValue> resultObject = DictionaryValue::create ();
173 {% for parameter in command.returns %} 173 {% for parameter in command.returns %}
174 {% if "optional" in parameter %} 174 {% if "optional" in parameter %}
175 if ({{parameter.name}}.isJust()) 175 if ({{parameter.name}}.isJust())
176 resultObject->setValue("{{parameter.name}}", toValue({{parameter.nam e}}.fromJust())); 176 resultObject->setValue("{{parameter.name}}", toValue({{parameter.nam e}}.fromJust()));
177 {% else %} 177 {% else %}
178 resultObject->setValue("{{parameter.name}}", toValue({{resolve_type(para meter).to_raw_type % parameter.name}})); 178 resultObject->setValue("{{parameter.name}}", toValue({{resolve_type(para meter).to_raw_type % parameter.name}}));
179 {% endif %} 179 {% endif %}
180 {% endfor %} 180 {% endfor %}
181 sendIfActive(resultObject.release(), ErrorString()); 181 sendIfActive(std::move(resultObject), ErrorString());
182 } 182 }
183 183
184 void sendFailure(const ErrorString& error) override 184 void sendFailure(const ErrorString& error) override
185 { 185 {
186 ASSERT(error.length()); 186 ASSERT(error.length());
187 sendIfActive(nullptr, error); 187 sendIfActive(nullptr, error);
188 } 188 }
189 }; 189 };
190 {% endif %} 190 {% endif %}
191 191
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 ErrorString error; 241 ErrorString error;
242 m_{{domain.domain | lower}}Agent->{{command.name}}(&error 242 m_{{domain.domain | lower}}Agent->{{command.name}}(&error
243 {%- for property in command.parameters -%} 243 {%- for property in command.parameters -%}
244 {%- if "optional" in property -%} 244 {%- if "optional" in property -%}
245 , in_{{property.name}} 245 , in_{{property.name}}
246 {%- else -%} 246 {%- else -%}
247 , {{resolve_type(property).to_pass_type % ("in_" + property.name)}} 247 , {{resolve_type(property).to_pass_type % ("in_" + property.name)}}
248 {%- endif -%} 248 {%- endif -%}
249 {%- endfor %} 249 {%- endfor %}
250 {%- if "async" in command -%} 250 {%- if "async" in command -%}
251 , callback.release() 251 , std::move(callback)
252 {%- elif "returns" in command %} 252 {%- elif "returns" in command %}
253 {%- for property in command.returns -%} 253 {%- for property in command.returns -%}
254 , &out_{{property.name}} 254 , &out_{{property.name}}
255 {%- endfor %} 255 {%- endfor %}
256 {% endif %}); 256 {% endif %});
257 {% if "returns" in command and not("async" in command) %} 257 {% if "returns" in command and not("async" in command) %}
258 if (!error.length()) { 258 if (!error.length()) {
259 {% for parameter in command.returns %} 259 {% for parameter in command.returns %}
260 {% if "optional" in parameter %} 260 {% if "optional" in parameter %}
261 if (out_{{parameter.name}}.isJust()) 261 if (out_{{parameter.name}}.isJust())
262 result->setValue("{{parameter.name}}", toValue(out_{{parameter.name} }.fromJust())); 262 result->setValue("{{parameter.name}}", toValue(out_{{parameter.name} }.fromJust()));
263 {% else %} 263 {% else %}
264 result->setValue("{{parameter.name}}", toValue({{resolve_type(parameter) .to_raw_type % ("out_" + parameter.name)}})); 264 result->setValue("{{parameter.name}}", toValue({{resolve_type(parameter) .to_raw_type % ("out_" + parameter.name)}}));
265 {% endif %} 265 {% endif %}
266 {% endfor %} 266 {% endfor %}
267 } 267 }
268 if (weak->get()) 268 if (weak->get())
269 weak->get()->sendResponse(sessionId, callId, error, result.release()); 269 weak->get()->sendResponse(sessionId, callId, error, std::move(result));
270 {% elif not("async" in command) %} 270 {% elif not("async" in command) %}
271 if (weak->get()) 271 if (weak->get())
272 weak->get()->sendResponse(sessionId, callId, error); 272 weak->get()->sendResponse(sessionId, callId, error);
273 {% endif %} 273 {% endif %}
274 } 274 }
275 {% endfor %} 275 {% endfor %}
276 {% endfor %} 276 {% endfor %}
277 277
278 PassOwnPtr<Dispatcher> Dispatcher::create(FrontendChannel* frontendChannel) 278 PassOwnPtr<Dispatcher> Dispatcher::create(FrontendChannel* frontendChannel)
279 { 279 {
280 return adoptPtr(new DispatcherImpl(frontendChannel)); 280 return adoptPtr(new DispatcherImpl(frontendChannel));
281 } 281 }
282 282
283 void DispatcherImpl::dispatch(int sessionId, const String16& message) 283 void DispatcherImpl::dispatch(int sessionId, const String16& message)
284 { 284 {
285 int callId = 0; 285 int callId = 0;
286 OwnPtr<protocol::Value> parsedMessage = parseJSON(message); 286 OwnPtr<protocol::Value> parsedMessage = parseJSON(message);
287 ASSERT(parsedMessage); 287 ASSERT(parsedMessage);
288 OwnPtr<protocol::DictionaryValue> messageObject = DictionaryValue::cast(pars edMessage.release()); 288 OwnPtr<protocol::DictionaryValue> messageObject = DictionaryValue::cast(std: :move(parsedMessage));
289 ASSERT(messageObject); 289 ASSERT(messageObject);
290 290
291 protocol::Value* callIdValue = messageObject->get("id"); 291 protocol::Value* callIdValue = messageObject->get("id");
292 bool success = callIdValue->asNumber(&callId); 292 bool success = callIdValue->asNumber(&callId);
293 ASSERT_UNUSED(success, success); 293 ASSERT_UNUSED(success, success);
294 294
295 protocol::Value* methodValue = messageObject->get("method"); 295 protocol::Value* methodValue = messageObject->get("method");
296 String16 method; 296 String16 method;
297 success = methodValue && methodValue->asString(&method); 297 success = methodValue && methodValue->asString(&method);
298 ASSERT_UNUSED(success, success); 298 ASSERT_UNUSED(success, success);
299 299
300 protocol::HashMap<String16, CallHandler>::iterator it = m_dispatchMap.find(m ethod); 300 protocol::HashMap<String16, CallHandler>::iterator it = m_dispatchMap.find(m ethod);
301 if (it == m_dispatchMap.end()) { 301 if (it == m_dispatchMap.end()) {
302 reportProtocolError(sessionId, callId, MethodNotFound, "'" + method + "' wasn't found"); 302 reportProtocolError(sessionId, callId, MethodNotFound, "'" + method + "' wasn't found");
303 return; 303 return;
304 } 304 }
305 305
306 protocol::ErrorSupport errors; 306 protocol::ErrorSupport errors;
307 ((*this).*(*it->second))(sessionId, callId, messageObject.release(), &errors ); 307 ((*this).*(*it->second))(sessionId, callId, std::move(messageObject), &error s);
308 } 308 }
309 309
310 void DispatcherImpl::sendResponse(int sessionId, int callId, const ErrorString& invocationError, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> res ult) 310 void DispatcherImpl::sendResponse(int sessionId, int callId, const ErrorString& invocationError, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> res ult)
311 { 311 {
312 if (invocationError.length() || (errors && errors->hasErrors())) { 312 if (invocationError.length() || (errors && errors->hasErrors())) {
313 reportProtocolError(sessionId, callId, ServerError, invocationError, err ors); 313 reportProtocolError(sessionId, callId, ServerError, invocationError, err ors);
314 return; 314 return;
315 } 315 }
316 316
317 OwnPtr<protocol::DictionaryValue> responseMessage = DictionaryValue::create( ); 317 OwnPtr<protocol::DictionaryValue> responseMessage = DictionaryValue::create( );
318 responseMessage->setNumber("id", callId); 318 responseMessage->setNumber("id", callId);
319 responseMessage->setObject("result", std::move(result)); 319 responseMessage->setObject("result", std::move(result));
320 if (m_frontendChannel) 320 if (m_frontendChannel)
321 m_frontendChannel->sendProtocolResponse(sessionId, callId, responseMessa ge.release()); 321 m_frontendChannel->sendProtocolResponse(sessionId, callId, std::move(res ponseMessage));
322 } 322 }
323 323
324 void Dispatcher::reportProtocolError(int sessionId, int callId, CommonErrorCode code, const String16& errorMessage) const 324 void Dispatcher::reportProtocolError(int sessionId, int callId, CommonErrorCode code, const String16& errorMessage) const
325 { 325 {
326 ErrorSupport errors; 326 ErrorSupport errors;
327 reportProtocolError(sessionId, callId, code, errorMessage, &errors); 327 reportProtocolError(sessionId, callId, code, errorMessage, &errors);
328 } 328 }
329 329
330 void DispatcherImpl::reportProtocolError(int sessionId, int callId, CommonErrorC ode code, const String16& errorMessage, ErrorSupport* errors) const 330 void DispatcherImpl::reportProtocolError(int sessionId, int callId, CommonErrorC ode code, const String16& errorMessage, ErrorSupport* errors) const
331 { 331 {
332 ASSERT(code >=0); 332 ASSERT(code >=0);
333 ASSERT((unsigned)code < m_commonErrors.size()); 333 ASSERT((unsigned)code < m_commonErrors.size());
334 ASSERT(m_commonErrors[code]); 334 ASSERT(m_commonErrors[code]);
335 OwnPtr<protocol::DictionaryValue> error = DictionaryValue::create(); 335 OwnPtr<protocol::DictionaryValue> error = DictionaryValue::create();
336 error->setNumber("code", m_commonErrors[code]); 336 error->setNumber("code", m_commonErrors[code]);
337 error->setString("message", errorMessage); 337 error->setString("message", errorMessage);
338 ASSERT(error); 338 ASSERT(error);
339 if (errors && errors->hasErrors()) 339 if (errors && errors->hasErrors())
340 error->setString("data", errors->errors()); 340 error->setString("data", errors->errors());
341 OwnPtr<protocol::DictionaryValue> message = DictionaryValue::create(); 341 OwnPtr<protocol::DictionaryValue> message = DictionaryValue::create();
342 message->setObject("error", error.release()); 342 message->setObject("error", std::move(error));
343 message->setNumber("id", callId); 343 message->setNumber("id", callId);
344 if (m_frontendChannel) 344 if (m_frontendChannel)
345 m_frontendChannel->sendProtocolResponse(sessionId, callId, message.relea se()); 345 m_frontendChannel->sendProtocolResponse(sessionId, callId, std::move(mes sage));
346 } 346 }
347 347
348 bool Dispatcher::getCommandName(const String16& message, String16* result) 348 bool Dispatcher::getCommandName(const String16& message, String16* result)
349 { 349 {
350 OwnPtr<protocol::Value> value = parseJSON(message); 350 OwnPtr<protocol::Value> value = parseJSON(message);
351 if (!value) 351 if (!value)
352 return false; 352 return false;
353 353
354 protocol::DictionaryValue* object = DictionaryValue::cast(value.get()); 354 protocol::DictionaryValue* object = DictionaryValue::cast(value.get());
355 if (!object) 355 if (!object)
356 return false; 356 return false;
357 357
358 if (!object->getString("method", result)) 358 if (!object->getString("method", result))
359 return false; 359 return false;
360 360
361 return true; 361 return true;
362 } 362 }
363 363
364 } // namespace protocol 364 } // namespace protocol
365 } // namespace blink 365 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698