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

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: rebase, test fix 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 void UberDispatcher::setupRedirects(const HashMap<String, String>& redirects)
252 {
253 for (const auto& pair : redirects)
caseq 2016/12/09 01:57:49 nit: do we really need to clone it?
dgozman 2016/12/12 23:01:25 Yes, this accumulates them in UberDispatcher.
254 m_redirects[pair.first] = pair.second;
255 }
256
257 DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM essage, int* outCallId, String* outMethod)
252 { 258 {
253 if (!parsedMessage) { 259 if (!parsedMessage) {
254 reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kParseError, "Message must be a valid JSON"); 260 reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kParseError, "Message must be a valid JSON");
255 return DispatchResponse::kError; 261 return DispatchResponse::kError;
256 } 262 }
257 std::unique_ptr<protocol::DictionaryValue> messageObject = DictionaryValue:: cast(std::move(parsedMessage)); 263 std::unique_ptr<protocol::DictionaryValue> messageObject = DictionaryValue:: cast(std::move(parsedMessage));
258 if (!messageObject) { 264 if (!messageObject) {
259 reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidReque st, "Message must be an object"); 265 reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidReque st, "Message must be an object");
260 return DispatchResponse::kError; 266 return DispatchResponse::kError;
261 } 267 }
262 268
263 int callId = 0; 269 int callId = 0;
264 protocol::Value* callIdValue = messageObject->get("id"); 270 protocol::Value* callIdValue = messageObject->get("id");
265 bool success = callIdValue && callIdValue->asInteger(&callId); 271 bool success = callIdValue && callIdValue->asInteger(&callId);
272 if (outCallId)
273 *outCallId = callId;
266 if (!success) { 274 if (!success) {
267 reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidReque st, "Message must have integer 'id' porperty"); 275 reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidReque st, "Message must have integer 'id' porperty");
268 return DispatchResponse::kError; 276 return DispatchResponse::kError;
269 } 277 }
270 278
271 protocol::Value* methodValue = messageObject->get("method"); 279 protocol::Value* methodValue = messageObject->get("method");
272 String method; 280 String method;
273 success = methodValue && methodValue->asString(&method); 281 success = methodValue && methodValue->asString(&method);
282 if (outMethod)
283 *outMethod = method;
274 if (!success) { 284 if (!success) {
275 reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kInva lidRequest, "Message must have string 'method' porperty", nullptr); 285 reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kInva lidRequest, "Message must have string 'method' porperty", nullptr);
276 return DispatchResponse::kError; 286 return DispatchResponse::kError;
277 } 287 }
278 288
289 if (m_redirects.find(method) != m_redirects.end())
caseq 2016/12/09 01:57:49 nit: keep the iterator returned from find to avoid
dgozman 2016/12/12 23:01:25 Done.
290 method = m_redirects[method];
291
279 size_t dotIndex = method.find("."); 292 size_t dotIndex = method.find(".");
280 if (dotIndex == StringUtil::kNotFound) { 293 if (dotIndex == StringUtil::kNotFound) {
281 if (m_fallThroughForNotFound) 294 if (m_fallThroughForNotFound)
282 return DispatchResponse::kFallThrough; 295 return DispatchResponse::kFallThrough;
283 reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kMeth odNotFound, "'" + method + "' wasn't found", nullptr); 296 reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kMeth odNotFound, "'" + method + "' wasn't found", nullptr);
284 return DispatchResponse::kError; 297 return DispatchResponse::kError;
285 } 298 }
286 String domain = StringUtil::substring(method, 0, dotIndex); 299 String domain = StringUtil::substring(method, 0, dotIndex);
287 auto it = m_dispatchers.find(domain); 300 auto it = m_dispatchers.find(domain);
288 if (it == m_dispatchers.end()) { 301 if (it == m_dispatchers.end()) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 InternalResponse::InternalResponse(int callId, const String& notification, std:: unique_ptr<Serializable> params) 338 InternalResponse::InternalResponse(int callId, const String& notification, std:: unique_ptr<Serializable> params)
326 : m_callId(callId) 339 : m_callId(callId)
327 , m_notification(notification) 340 , m_notification(notification)
328 , m_params(params ? std::move(params) : nullptr) 341 , m_params(params ? std::move(params) : nullptr)
329 { 342 {
330 } 343 }
331 344
332 {% for namespace in config.protocol.namespace %} 345 {% for namespace in config.protocol.namespace %}
333 } // namespace {{namespace}} 346 } // namespace {{namespace}}
334 {% endfor %} 347 {% endfor %}
OLDNEW
« no previous file with comments | « third_party/inspector_protocol/CodeGenerator.py ('k') | third_party/inspector_protocol/lib/DispatcherBase_h.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698