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

Side by Side Diff: third_party/inspector_protocol/lib/DispatcherBase_cpp.template

Issue 2548263002: [DevTools] Migrate dom, emulation, inspector, network, page and schema handlers to new generator. (Closed)
Patch Set: works Created 4 years 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 "DispatcherBase.h" 5 //#include "DispatcherBase.h"
6 //#include "Parser.h" 6 //#include "Parser.h"
7 7
8 {% for namespace in config.protocol.namespace %} 8 {% for namespace in config.protocol.namespace %}
9 namespace {{namespace}} { 9 namespace {{namespace}} {
10 {% endfor %} 10 {% endfor %}
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 void UberDispatcher::setFallThroughForNotFound(bool fallThroughForNotFound) 241 void UberDispatcher::setFallThroughForNotFound(bool fallThroughForNotFound)
242 { 242 {
243 m_fallThroughForNotFound = fallThroughForNotFound; 243 m_fallThroughForNotFound = fallThroughForNotFound;
244 } 244 }
245 245
246 void UberDispatcher::registerBackend(const String& name, std::unique_ptr<protoco l::DispatcherBase> dispatcher) 246 void UberDispatcher::registerBackend(const String& name, std::unique_ptr<protoco l::DispatcherBase> dispatcher)
247 { 247 {
248 m_dispatchers[name] = std::move(dispatcher); 248 m_dispatchers[name] = std::move(dispatcher);
249 } 249 }
250 250
251 DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM essage) 251 DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM essage, int* outCallId, String* outMethod)
252 { 252 {
253 if (!parsedMessage) { 253 if (!parsedMessage) {
254 reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kParseError, "Message must be a valid JSON"); 254 reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kParseError, "Message must be a valid JSON");
255 return DispatchResponse::kError; 255 return DispatchResponse::kError;
256 } 256 }
257 std::unique_ptr<protocol::DictionaryValue> messageObject = DictionaryValue:: cast(std::move(parsedMessage)); 257 std::unique_ptr<protocol::DictionaryValue> messageObject = DictionaryValue:: cast(std::move(parsedMessage));
258 if (!messageObject) { 258 if (!messageObject) {
259 reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidReque st, "Message must be an object"); 259 reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidReque st, "Message must be an object");
260 return DispatchResponse::kError; 260 return DispatchResponse::kError;
261 } 261 }
262 262
263 int callId = 0; 263 int callId = 0;
264 protocol::Value* callIdValue = messageObject->get("id"); 264 protocol::Value* callIdValue = messageObject->get("id");
265 bool success = callIdValue && callIdValue->asInteger(&callId); 265 bool success = callIdValue && callIdValue->asInteger(&callId);
266 if (outCallId)
267 *outCallId = callId;
266 if (!success) { 268 if (!success) {
267 reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidReque st, "Message must have integer 'id' porperty"); 269 reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidReque st, "Message must have integer 'id' porperty");
268 return DispatchResponse::kError; 270 return DispatchResponse::kError;
269 } 271 }
270 272
271 protocol::Value* methodValue = messageObject->get("method"); 273 protocol::Value* methodValue = messageObject->get("method");
272 String method; 274 String method;
273 success = methodValue && methodValue->asString(&method); 275 success = methodValue && methodValue->asString(&method);
276 if (outMethod)
277 *outMethod = method;
274 if (!success) { 278 if (!success) {
275 reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kInva lidRequest, "Message must have string 'method' porperty", nullptr); 279 reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kInva lidRequest, "Message must have string 'method' porperty", nullptr);
276 return DispatchResponse::kError; 280 return DispatchResponse::kError;
277 } 281 }
278 282
279 size_t dotIndex = method.find("."); 283 size_t dotIndex = method.find(".");
280 if (dotIndex == StringUtil::kNotFound) { 284 if (dotIndex == StringUtil::kNotFound) {
281 if (m_fallThroughForNotFound) 285 if (m_fallThroughForNotFound)
282 return DispatchResponse::kFallThrough; 286 return DispatchResponse::kFallThrough;
283 reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kMeth odNotFound, "'" + method + "' wasn't found", nullptr); 287 reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kMeth odNotFound, "'" + method + "' wasn't found", nullptr);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 InternalResponse::InternalResponse(int callId, const String& notification, std:: unique_ptr<Serializable> params) 329 InternalResponse::InternalResponse(int callId, const String& notification, std:: unique_ptr<Serializable> params)
326 : m_callId(callId) 330 : m_callId(callId)
327 , m_notification(notification) 331 , m_notification(notification)
328 , m_params(params ? std::move(params) : nullptr) 332 , m_params(params ? std::move(params) : nullptr)
329 { 333 {
330 } 334 }
331 335
332 {% for namespace in config.protocol.namespace %} 336 {% for namespace in config.protocol.namespace %}
333 } // namespace {{namespace}} 337 } // namespace {{namespace}}
334 {% endfor %} 338 {% endfor %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698