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

Unified Diff: third_party/inspector_protocol/lib/DispatcherBase_cpp.template

Issue 2500093002: [DevTools] Move IO and Tracing to new generator. (Closed)
Patch Set: roll Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: third_party/inspector_protocol/lib/DispatcherBase_cpp.template
diff --git a/third_party/inspector_protocol/lib/DispatcherBase_cpp.template b/third_party/inspector_protocol/lib/DispatcherBase_cpp.template
index 9095cbc961c7761406eb58c76264cf13e9b1f128..b08947aba43f32c1da32a290560dcbd32471e306 100644
--- a/third_party/inspector_protocol/lib/DispatcherBase_cpp.template
+++ b/third_party/inspector_protocol/lib/DispatcherBase_cpp.template
@@ -39,6 +39,16 @@ DispatchResponse DispatchResponse::InternalError()
}
// static
+DispatchResponse DispatchResponse::InvalidParams(const String& error)
+{
+ DispatchResponse result;
+ result.m_status = kError;
+ result.m_errorCode = kInvalidParams;
+ result.m_errorMessage = error;
+ return result;
+}
+
+// static
DispatchResponse DispatchResponse::FallThrough()
{
DispatchResponse result;
@@ -58,9 +68,10 @@ DispatcherBase::WeakPtr::~WeakPtr()
m_dispatcher->m_weakPtrs.erase(this);
}
-DispatcherBase::Callback::Callback(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId)
+DispatcherBase::Callback::Callback(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId, int callbackId)
: m_backendImpl(std::move(backendImpl))
- , m_callId(callId) { }
+ , m_callId(callId)
+ , m_callbackId(callbackId) { }
DispatcherBase::Callback::~Callback() = default;
@@ -77,14 +88,36 @@ void DispatcherBase::Callback::sendIfActive(std::unique_ptr<protocol::Dictionary
m_backendImpl = nullptr;
}
+void DispatcherBase::Callback::fallThroughIfActive()
+{
+ if (!m_backendImpl || !m_backendImpl->get())
+ return;
+ m_backendImpl->get()->markFallThrough(m_callbackId);
+ m_backendImpl = nullptr;
+}
+
DispatcherBase::DispatcherBase(FrontendChannel* frontendChannel)
- : m_frontendChannel(frontendChannel) { }
+ : m_frontendChannel(frontendChannel)
+ , m_lastCallbackId(0)
+ , m_lastCallbackFallThrough(false) { }
DispatcherBase::~DispatcherBase()
{
clearFrontend();
}
+int DispatcherBase::nextCallbackId()
+{
+ m_lastCallbackFallThrough = false;
+ return ++m_lastCallbackId;
+}
+
+void DispatcherBase::markFallThrough(int callbackId)
+{
+ DCHECK(callbackId == m_lastCallbackId);
+ m_lastCallbackFallThrough = true;
+}
+
// static
bool DispatcherBase::getCommandName(const String& message, String* result)
{
@@ -169,7 +202,13 @@ std::unique_ptr<DispatcherBase::WeakPtr> DispatcherBase::weakPtr()
}
UberDispatcher::UberDispatcher(FrontendChannel* frontendChannel)
- : m_frontendChannel(frontendChannel) { }
+ : m_frontendChannel(frontendChannel)
+ , m_fallThroughForNotFound(false) { }
+
+void UberDispatcher::setFallThroughForNotFound(bool fallThroughForNotFound)
+{
+ m_fallThroughForNotFound = fallThroughForNotFound;
+}
void UberDispatcher::registerBackend(const String& name, std::unique_ptr<protocol::DispatcherBase> dispatcher)
{
@@ -206,12 +245,16 @@ DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM
size_t dotIndex = method.find(".");
if (dotIndex == StringUtil::kNotFound) {
+ if (m_fallThroughForNotFound)
+ return DispatchResponse::kFallThrough;
reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
return DispatchResponse::kError;
}
String domain = StringUtil::substring(method, 0, dotIndex);
auto it = m_dispatchers.find(domain);
if (it == m_dispatchers.end()) {
+ if (m_fallThroughForNotFound)
+ return DispatchResponse::kFallThrough;
reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
return DispatchResponse::kError;
}
« no previous file with comments | « third_party/inspector_protocol/README.chromium ('k') | third_party/inspector_protocol/lib/DispatcherBase_h.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698