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

Unified Diff: third_party/inspector_protocol/templates/TypeBuilder_cpp.template

Issue 2522583002: Roll third_party/inspector_protocol to 4ad35c45aca9834b67ec2cb152c816ea1b7ceb48 (Closed)
Patch Set: removed redundant new line 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/templates/TypeBuilder_cpp.template
diff --git a/third_party/inspector_protocol/templates/TypeBuilder_cpp.template b/third_party/inspector_protocol/templates/TypeBuilder_cpp.template
index b63a0e880ddc502d68ca0be325907cf8d33750f2..63dded9c0b061b05616b9d6175240c76464677f5 100644
--- a/third_party/inspector_protocol/templates/TypeBuilder_cpp.template
+++ b/third_party/inspector_protocol/templates/TypeBuilder_cpp.template
@@ -144,6 +144,43 @@ const char* {{ literal | to_title_case}} = "{{literal}}";
{% endfor %}
// ------------- Frontend notifications.
+
+namespace {
+
+class Notification : public Serializable {
dgozman 2016/11/21 22:29:16 This should not be in template - it will be genera
kozy 2016/11/22 01:25:38 Done.
+public:
+ static std::unique_ptr<Notification> create(const String& method, std::unique_ptr<Serializable> params = nullptr)
+ {
+ return std::unique_ptr<Notification>(new Notification(method, std::move(params)));
+ }
+
+ std::unique_ptr<protocol::Value> serializeValue() const override
+ {
+ std::unique_ptr<DictionaryValue> result = DictionaryValue::create();
+ result->setString("method", m_method);
+ std::unique_ptr<DictionaryValue> params;
+ if (!m_params)
+ params = DictionaryValue::create();
dgozman 2016/11/21 22:29:16 4 spaces
kozy 2016/11/22 01:25:38 Done.
+ else
+ params = std::unique_ptr<DictionaryValue>(static_cast<DictionaryValue*>(m_params->serializeValue().release()));
+ result->setObject("params", std::move(params));
+ return result;
+ }
+
+protected:
+ Notification(const String& method, std::unique_ptr<Serializable> params)
+ : m_method(method)
+ , m_params(std::move(params))
+ {
+ }
+
+private:
+ String m_method;
+ std::unique_ptr<Serializable> m_params;
+};
+
+} // namespace
+
{% for event in domain.events %}
{% if not generate_event(domain.domain, event.name) %}{% continue %}{% endif %}
@@ -156,20 +193,26 @@ void Frontend::{{event.name | to_method_case}}(
{%- endif %} {{parameter.name}}{%- if not loop.last -%}, {% endif -%}
{% endfor -%})
{
- std::unique_ptr<protocol::DictionaryValue> jsonMessage = DictionaryValue::create();
- jsonMessage->setString("method", "{{domain.domain}}.{{event.name}}");
- std::unique_ptr<protocol::DictionaryValue> paramsObject = DictionaryValue::create();
- {% for parameter in event.parameters %}
- {% if "optional" in parameter %}
+ if (!m_frontendChannel)
+ return;
+ {% if event.parameters %}
+ std::unique_ptr<{{event.name | to_title_case}}Notification> messageData = {{event.name | to_title_case}}Notification::{{"create" | to_method_case}}()
+ {% for parameter in event.parameters %}
+ {% if not "optional" in parameter %}
+ .{{"set" | to_method_case}}{{parameter.name | to_title_case}}({{resolve_type(parameter).to_pass_type % parameter.name}})
+ {% endif %}
+ {% endfor %}
+ .{{ "build" | to_method_case }}();
+ {% for parameter in event.parameters %}
+ {% if "optional" in parameter %}
if ({{parameter.name}}.isJust())
- paramsObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(parameter).raw_type}}>::serialize({{parameter.name}}.fromJust()));
+ messageData->{{"set" | to_method_case}}{{parameter.name | to_title_case}}(std::move({{parameter.name}}).takeJust());
+ {% endif %}
+ {% endfor %}
+ m_frontendChannel->sendProtocolNotification(Notification::create("{{domain.domain}}.{{event.name}}", std::move(messageData)));
{% else %}
- paramsObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(parameter).raw_type}}>::serialize({{resolve_type(parameter).to_raw_type % parameter.name}}));
+ m_frontendChannel->sendProtocolNotification(Notification::create("{{domain.domain}}.{{event.name}}"));
{% endif %}
- {% endfor %}
- jsonMessage->setObject("params", std::move(paramsObject));
- if (m_frontendChannel)
- m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString());
}
{% endfor %}
@@ -178,9 +221,28 @@ void Frontend::flush()
m_frontendChannel->flushProtocolNotifications();
}
+namespace {
+
+class RawNotification : public Serializable {
+public:
+ explicit RawNotification(const String& notification)
+ : m_notification(notification)
+ {
+ }
+
+ std::unique_ptr<protocol::Value> serializeValue() const override {
+ return SerializedValue::create(m_notification);
+ }
+
+private:
+ String m_notification;
+};
+
+} // namespace
+
void Frontend::sendRawNotification(const String& notification)
{
- m_frontendChannel->sendProtocolNotification(notification);
+ m_frontendChannel->sendProtocolNotification(std::unique_ptr<Serializable>(new RawNotification(notification)));
}
// --------------------- Dispatcher.

Powered by Google App Engine
This is Rietveld 408576698