Chromium Code Reviews| Index: lib/DispatcherBase_cpp.template |
| diff --git a/lib/DispatcherBase_cpp.template b/lib/DispatcherBase_cpp.template |
| index 0d4a305abe89872af970ba20b9dc8cc1da563a20..e9730eb7b59b3030e536920c1d1a37706f3fe3cc 100644 |
| --- a/lib/DispatcherBase_cpp.template |
| +++ b/lib/DispatcherBase_cpp.template |
| @@ -248,7 +248,13 @@ void UberDispatcher::registerBackend(const String& name, std::unique_ptr<protoco |
| m_dispatchers[name] = std::move(dispatcher); |
| } |
| -DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedMessage) |
| +void UberDispatcher::setupRedirects(const HashMap<String, String>& redirects) |
| +{ |
| + for (const auto& pair : redirects) |
|
kozy
2016/12/12 23:10:29
Do we need to cleanup redirects before setup new o
dgozman
2016/12/12 23:27:12
No, this method accumulates redirects from differe
|
| + m_redirects[pair.first] = pair.second; |
| +} |
| + |
| +DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedMessage, int* outCallId, String* outMethod) |
| { |
| if (!parsedMessage) { |
| reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kParseError, "Message must be a valid JSON"); |
| @@ -263,6 +269,8 @@ DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM |
| int callId = 0; |
| protocol::Value* callIdValue = messageObject->get("id"); |
| bool success = callIdValue && callIdValue->asInteger(&callId); |
| + if (outCallId) |
| + *outCallId = callId; |
| if (!success) { |
| reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidRequest, "Message must have integer 'id' porperty"); |
| return DispatchResponse::kError; |
| @@ -271,11 +279,17 @@ DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM |
| protocol::Value* methodValue = messageObject->get("method"); |
| String method; |
| success = methodValue && methodValue->asString(&method); |
| + if (outMethod) |
| + *outMethod = method; |
| if (!success) { |
| reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kInvalidRequest, "Message must have string 'method' porperty", nullptr); |
| return DispatchResponse::kError; |
| } |
| + HashMap<String, String>::iterator redirectIt = m_redirects.find(method); |
| + if (redirectIt != m_redirects.end()) |
| + method = redirectIt->second; |
| + |
| size_t dotIndex = method.find("."); |
| if (dotIndex == StringUtil::kNotFound) { |
| if (m_fallThroughForNotFound) |