| OLD | NEW |
| 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 namespace blink { | 5 namespace blink { |
| 6 namespace protocol { | 6 namespace protocol { |
| 7 | 7 |
| 8 // static | 8 // static |
| 9 const char DispatcherBase::kInvalidRequest[] = "Invalid request"; | 9 const char DispatcherBase::kInvalidRequest[] = "Invalid request"; |
| 10 | 10 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 120 } |
| 121 | 121 |
| 122 UberDispatcher::UberDispatcher(FrontendChannel* frontendChannel) | 122 UberDispatcher::UberDispatcher(FrontendChannel* frontendChannel) |
| 123 : m_frontendChannel(frontendChannel) { } | 123 : m_frontendChannel(frontendChannel) { } |
| 124 | 124 |
| 125 void UberDispatcher::registerBackend(const String16& name, std::unique_ptr<proto
col::DispatcherBase> dispatcher) | 125 void UberDispatcher::registerBackend(const String16& name, std::unique_ptr<proto
col::DispatcherBase> dispatcher) |
| 126 { | 126 { |
| 127 m_dispatchers[name] = std::move(dispatcher); | 127 m_dispatchers[name] = std::move(dispatcher); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void UberDispatcher::dispatch(const String16& message) | 130 void UberDispatcher::dispatch(std::unique_ptr<Value> parsedMessage) |
| 131 { | 131 { |
| 132 std::unique_ptr<protocol::Value> parsedMessage = parseJSON(message); | |
| 133 if (!parsedMessage) | 132 if (!parsedMessage) |
| 134 return; | 133 return; |
| 135 std::unique_ptr<protocol::DictionaryValue> messageObject = DictionaryValue::
cast(std::move(parsedMessage)); | 134 std::unique_ptr<protocol::DictionaryValue> messageObject = DictionaryValue::
cast(std::move(parsedMessage)); |
| 136 if (!messageObject) | 135 if (!messageObject) |
| 137 return; | 136 return; |
| 138 | 137 |
| 139 int callId = 0; | 138 int callId = 0; |
| 140 protocol::Value* callIdValue = messageObject->get("id"); | 139 protocol::Value* callIdValue = messageObject->get("id"); |
| 141 bool success = callIdValue->asInteger(&callId); | 140 bool success = callIdValue->asInteger(&callId); |
| 142 if (!success) | 141 if (!success) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 159 reportProtocolError(m_frontendChannel, callId, DispatcherBase::MethodNot
Found, "'" + method + "' wasn't found", nullptr); | 158 reportProtocolError(m_frontendChannel, callId, DispatcherBase::MethodNot
Found, "'" + method + "' wasn't found", nullptr); |
| 160 return; | 159 return; |
| 161 } | 160 } |
| 162 it->second->dispatch(callId, method, std::move(messageObject)); | 161 it->second->dispatch(callId, method, std::move(messageObject)); |
| 163 } | 162 } |
| 164 | 163 |
| 165 UberDispatcher::~UberDispatcher() = default; | 164 UberDispatcher::~UberDispatcher() = default; |
| 166 | 165 |
| 167 } // namespace protocol | 166 } // namespace protocol |
| 168 } // namespace blink | 167 } // namespace blink |
| OLD | NEW |