[DevTools] Dispatch messages to V8InspectorSession directly.
This patch adds dispatcher, backend and frontend channel to V8InspectorSessionImpl
and removes agent public interfaces and their blink wrappers.
Drive-by: removed sessionId from inspector_protocol since InspectorSession now
handles it.
Next step would be to separate v8 instrumentation from InspectorSession,
remove latter from worker (depends on console efforts) and merge session
into WebDevToolsAgentImpl.
BUG=580337
Review-Url: https://codereview.chromium.org/1967933002
Cr-Original-Commit-Position: refs/heads/master@{#395269}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 4698dd61590b2cba8346c5efd83428b9a3c3e970
diff --git a/Dispatcher_cpp.template b/Dispatcher_cpp.template
index 44e1ea4..5241f60 100644
--- a/Dispatcher_cpp.template
+++ b/Dispatcher_cpp.template
@@ -70,11 +70,11 @@
return weak;
}
- virtual void dispatch(int sessionId, const String16& message);
- virtual void reportProtocolError(int sessionId, int callId, CommonErrorCode, const String16& errorMessage, ErrorSupport* errors) const;
+ virtual void dispatch(const String16& message);
+ virtual void reportProtocolError(int callId, CommonErrorCode, const String16& errorMessage, ErrorSupport* errors) const;
using Dispatcher::reportProtocolError;
- void sendResponse(int sessionId, int callId, const ErrorString& invocationError, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> result);
+ void sendResponse(int callId, const ErrorString& invocationError, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> result);
{% for domain in api.domains %}
virtual void registerAgent(blink::protocol::Backend::{{domain.domain}}* agent) { DCHECK(!m_{{domain.domain | lower}}Agent); m_{{domain.domain | lower}}Agent = agent; }
@@ -83,14 +83,14 @@
private:
friend class DispatcherCallbackBase;
friend class DispatcherImplWeakPtr;
- using CallHandler = void (DispatcherImpl::*)(int sessionId, int callId, PassOwnPtr<DictionaryValue> messageObject, ErrorSupport* errors);
+ using CallHandler = void (DispatcherImpl::*)(int callId, PassOwnPtr<DictionaryValue> messageObject, ErrorSupport* errors);
using DispatchMap = protocol::HashMap<String16, CallHandler>;
{% for domain in api.domains %}
{% for command in domain.commands %}
{% if "redirect" in command %}{% continue %}{% endif %}
{% if "handlers" in command and not ("renderer" in command["handlers"]) %}{% continue %}{% endif %}
- void {{domain.domain}}_{{command.name}}(int sessionId, int callId, PassOwnPtr<DictionaryValue> requestMessageObject, ErrorSupport*);
+ void {{domain.domain}}_{{command.name}}(int callId, PassOwnPtr<DictionaryValue> requestMessageObject, ErrorSupport*);
{% endfor %}
{% endfor %}
@@ -100,14 +100,14 @@
Backend::{{domain.domain}}* m_{{domain.domain | lower}}Agent;
{% endfor %}
- void sendResponse(int sessionId, int callId, ErrorString invocationError, PassOwnPtr<protocol::DictionaryValue> result)
+ void sendResponse(int callId, ErrorString invocationError, PassOwnPtr<protocol::DictionaryValue> result)
{
- sendResponse(sessionId, callId, invocationError, nullptr, std::move(result));
+ sendResponse(callId, invocationError, nullptr, std::move(result));
}
- void sendResponse(int sessionId, int callId, ErrorString invocationError)
+ void sendResponse(int callId, ErrorString invocationError)
{
- sendResponse(sessionId, callId, invocationError, nullptr, DictionaryValue::create());
+ sendResponse(callId, invocationError, nullptr, DictionaryValue::create());
}
static const char kInvalidRequest[];
@@ -119,8 +119,8 @@
class PLATFORM_EXPORT DispatcherCallbackBase : public protocol::Backend::CallbackBase {
public:
- DispatcherCallbackBase(PassOwnPtr<DispatcherImplWeakPtr> backendImpl, int sessionId, int id)
- : m_backendImpl(std::move(backendImpl)), m_sessionId(sessionId), m_id(id) { }
+ DispatcherCallbackBase(PassOwnPtr<DispatcherImplWeakPtr> backendImpl, int callId)
+ : m_backendImpl(std::move(backendImpl)), m_callId(callId) { }
virtual ~DispatcherCallbackBase() { }
void dispose() { m_backendImpl = nullptr; }
@@ -129,14 +129,13 @@
{
if (!m_backendImpl->get())
return;
- m_backendImpl->get()->sendResponse(m_sessionId, m_id, invocationError, nullptr, std::move(partialMessage));
+ m_backendImpl->get()->sendResponse(m_callId, invocationError, nullptr, std::move(partialMessage));
m_backendImpl = nullptr;
}
private:
OwnPtr<DispatcherImplWeakPtr> m_backendImpl;
- int m_sessionId;
- int m_id;
+ int m_callId;
};
DispatcherImplWeakPtr::~DispatcherImplWeakPtr()
@@ -156,8 +155,8 @@
class PLATFORM_EXPORT {{domain.domain}}{{command.name | to_title_case}}Callback : public Backend::{{domain.domain}}::{{command.name | to_title_case}}Callback, public DispatcherCallbackBase {
public:
- {{domain.domain}}{{command.name | to_title_case}}Callback(PassOwnPtr<DispatcherImplWeakPtr> backendImpl, int sessionId, int id)
- : DispatcherCallbackBase(std::move(backendImpl), sessionId, id) { }
+ {{domain.domain}}{{command.name | to_title_case}}Callback(PassOwnPtr<DispatcherImplWeakPtr> backendImpl, int callId)
+ : DispatcherCallbackBase(std::move(backendImpl), callId) { }
void sendSuccess(
{%- for parameter in command.returns -%}
@@ -189,13 +188,13 @@
};
{% endif %}
-void DispatcherImpl::{{domain.domain}}_{{command.name}}(int sessionId, int callId, PassOwnPtr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
+void DispatcherImpl::{{domain.domain}}_{{command.name}}(int callId, PassOwnPtr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
{
if (!m_{{domain.domain | lower}}Agent)
errors->addError("{{domain.domain}} handler is not available.");
if (errors->hasErrors()) {
- reportProtocolError(sessionId, callId, InvalidParams, kInvalidRequest, errors);
+ reportProtocolError(callId, InvalidParams, kInvalidRequest, errors);
return;
}
{% if "parameters" in command %}
@@ -218,13 +217,13 @@
{% endfor %}
errors->pop();
if (errors->hasErrors()) {
- reportProtocolError(sessionId, callId, InvalidParams, kInvalidRequest, errors);
+ reportProtocolError(callId, InvalidParams, kInvalidRequest, errors);
return;
}
{% endif %}
{% if "async" in command %}
- OwnPtr<{{domain.domain}}{{command.name | to_title_case}}Callback> callback = adoptPtr(new {{domain.domain}}{{command.name | to_title_case}}Callback(weakPtr(), sessionId, callId));
+ OwnPtr<{{domain.domain}}{{command.name | to_title_case}}Callback> callback = adoptPtr(new {{domain.domain}}{{command.name | to_title_case}}Callback(weakPtr(), callId));
{% elif "returns" in command %}
// Declare output parameters.
OwnPtr<protocol::DictionaryValue> result = DictionaryValue::create();
@@ -266,10 +265,10 @@
{% endfor %}
}
if (weak->get())
- weak->get()->sendResponse(sessionId, callId, error, std::move(result));
+ weak->get()->sendResponse(callId, error, std::move(result));
{% elif not("async" in command) %}
if (weak->get())
- weak->get()->sendResponse(sessionId, callId, error);
+ weak->get()->sendResponse(callId, error);
{% endif %}
}
{% endfor %}
@@ -280,7 +279,7 @@
return adoptPtr(new DispatcherImpl(frontendChannel));
}
-void DispatcherImpl::dispatch(int sessionId, const String16& message)
+void DispatcherImpl::dispatch(const String16& message)
{
int callId = 0;
OwnPtr<protocol::Value> parsedMessage = parseJSON(message);
@@ -299,18 +298,18 @@
protocol::HashMap<String16, CallHandler>::iterator it = m_dispatchMap.find(method);
if (it == m_dispatchMap.end()) {
- reportProtocolError(sessionId, callId, MethodNotFound, "'" + method + "' wasn't found");
+ reportProtocolError(callId, MethodNotFound, "'" + method + "' wasn't found");
return;
}
protocol::ErrorSupport errors;
- ((*this).*(*it->second))(sessionId, callId, std::move(messageObject), &errors);
+ ((*this).*(*it->second))(callId, std::move(messageObject), &errors);
}
-void DispatcherImpl::sendResponse(int sessionId, int callId, const ErrorString& invocationError, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> result)
+void DispatcherImpl::sendResponse(int callId, const ErrorString& invocationError, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> result)
{
if (invocationError.length() || (errors && errors->hasErrors())) {
- reportProtocolError(sessionId, callId, ServerError, invocationError, errors);
+ reportProtocolError(callId, ServerError, invocationError, errors);
return;
}
@@ -318,16 +317,16 @@
responseMessage->setNumber("id", callId);
responseMessage->setObject("result", std::move(result));
if (m_frontendChannel)
- m_frontendChannel->sendProtocolResponse(sessionId, callId, std::move(responseMessage));
+ m_frontendChannel->sendProtocolResponse(callId, responseMessage->toJSONString());
}
-void Dispatcher::reportProtocolError(int sessionId, int callId, CommonErrorCode code, const String16& errorMessage) const
+void Dispatcher::reportProtocolError(int callId, CommonErrorCode code, const String16& errorMessage) const
{
ErrorSupport errors;
- reportProtocolError(sessionId, callId, code, errorMessage, &errors);
+ reportProtocolError(callId, code, errorMessage, &errors);
}
-void DispatcherImpl::reportProtocolError(int sessionId, int callId, CommonErrorCode code, const String16& errorMessage, ErrorSupport* errors) const
+void DispatcherImpl::reportProtocolError(int callId, CommonErrorCode code, const String16& errorMessage, ErrorSupport* errors) const
{
DCHECK(code >=0);
DCHECK((unsigned)code < m_commonErrors.size());
@@ -342,7 +341,7 @@
message->setObject("error", std::move(error));
message->setNumber("id", callId);
if (m_frontendChannel)
- m_frontendChannel->sendProtocolResponse(sessionId, callId, std::move(message));
+ m_frontendChannel->sendProtocolResponse(callId, message->toJSONString());
}
bool Dispatcher::getCommandName(const String16& message, String16* result)
diff --git a/Dispatcher_h.template b/Dispatcher_h.template
index d0c7797..cda88f7 100644
--- a/Dispatcher_h.template
+++ b/Dispatcher_h.template
@@ -23,7 +23,7 @@
class PLATFORM_EXPORT CallbackBase {
public:
- CallbackBase(PassOwnPtr<DispatcherImplWeakPtr> backendImpl, int sessionId, int id);
+ CallbackBase(PassOwnPtr<DispatcherImplWeakPtr> backendImpl, int callId);
virtual ~CallbackBase();
void sendFailure(const ErrorString&);
void dispose();
@@ -33,8 +33,7 @@
private:
OwnPtr<DispatcherImplWeakPtr> m_backendImpl;
- int m_sessionId;
- int m_id;
+ int m_callId;
};
{% for domain in api.domains %}
@@ -53,9 +52,9 @@
LastEntry,
};
- void reportProtocolError(int sessionId, int callId, CommonErrorCode, const String16& errorMessage) const;
- virtual void reportProtocolError(int sessionId, int callId, CommonErrorCode, const String16& errorMessage, ErrorSupport*) const = 0;
- virtual void dispatch(int sessionId, const String16& message) = 0;
+ void reportProtocolError(int callId, CommonErrorCode, const String16& errorMessage) const;
+ virtual void reportProtocolError(int callId, CommonErrorCode, const String16& errorMessage, ErrorSupport*) const = 0;
+ virtual void dispatch(const String16& message) = 0;
static bool getCommandName(const String16& message, String16* result);
};
diff --git a/FrontendChannel.h b/FrontendChannel.h
index e2b769b..533c4c5 100644
--- a/FrontendChannel.h
+++ b/FrontendChannel.h
@@ -34,9 +34,9 @@
class FrontendChannel {
public:
virtual ~FrontendChannel() { }
- virtual void sendProtocolResponse(int sessionId, int callId, PassOwnPtr<protocol::DictionaryValue> message) = 0;
- virtual void sendProtocolNotification(PassOwnPtr<protocol::DictionaryValue> message) = 0;
- virtual void flush() = 0;
+ virtual void sendProtocolResponse(int callId, const String16& message) = 0;
+ virtual void sendProtocolNotification(const String16& message) = 0;
+ virtual void flushProtocolNotifications() = 0;
};
} // namespace protocol
diff --git a/Frontend_cpp.template b/Frontend_cpp.template
index 58c7691..d65e35c 100644
--- a/Frontend_cpp.template
+++ b/Frontend_cpp.template
@@ -44,7 +44,7 @@
{% endfor %}
jsonMessage->setObject("params", std::move(paramsObject));
if (m_frontendChannel)
- m_frontendChannel->sendProtocolNotification(std::move(jsonMessage));
+ m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString());
}
{% endfor %}
{% endfor %}
diff --git a/Frontend_h.template b/Frontend_h.template
index 79cc64b..b116ed5 100644
--- a/Frontend_h.template
+++ b/Frontend_h.template
@@ -38,7 +38,7 @@
);
{% endfor %}
- void flush() { m_frontendChannel->flush(); }
+ void flush() { m_frontendChannel->flushProtocolNotifications(); }
private:
FrontendChannel* m_frontendChannel;
};