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

Unified Diff: headless/lib/browser/domain_cc.template

Issue 2278123002: headless: Ensure all commands have parameters and return types (Closed)
Patch Set: Created 4 years, 4 months 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
« no previous file with comments | « headless/lib/browser/client_api_generator_unittest.py ('k') | headless/lib/browser/domain_h.template » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: headless/lib/browser/domain_cc.template
diff --git a/headless/lib/browser/domain_cc.template b/headless/lib/browser/domain_cc.template
index adff89be95edb62c81a93304d93a2e6c9b83a0bf..643afe749a8a0879d190698589e3a28db4852593 100644
--- a/headless/lib/browser/domain_cc.template
+++ b/headless/lib/browser/domain_cc.template
@@ -32,19 +32,8 @@ void Domain::RemoveObserver(Observer* observer) {
{% set class_name = 'ExperimentalDomain' if command.experimental else 'Domain' %}
{% set method_name = command.name | to_title_case %}
- {% if "parameters" in command and "returns" in command %}
void {{class_name}}::{{method_name}}(std::unique_ptr<{{method_name}}Params> params, base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback) {
dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Serialize(), base::Bind(&Domain::Handle{{method_name}}Response, callback));
- {% elif "parameters" in command %}
-void {{class_name}}::{{method_name}}(std::unique_ptr<{{method_name}}Params> params, base::Callback<void()> callback) {
- dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Serialize(), std::move(callback));
- {% elif "returns" in command %}
-void {{class_name}}::{{method_name}}(base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback) {
- dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", base::Bind(&Domain::Handle{{method_name}}Response, std::move(callback)));
- {% else %}
-void {{class_name}}::{{method_name}}(base::Callback<void()> callback) {
- dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", std::move(callback));
- {% endif %}
}
{# Generate convenience methods that take the required parameters directly. #}
{% if not "parameters" in command %}{% continue %}{% endif %}
@@ -59,8 +48,8 @@ void {{class_name}}::{{method_name}}({##}
{% if not loop.first %}, {% endif %}
{{resolve_type(parameter).pass_type}} {{parameter.name | camelcase_to_hacker_style -}}
{% endfor %}
- {% if "parameters" in command and not command.parameters[0].get("optional", False) %}, {% endif %}{# -#}
- {% if "returns" in command -%}
+ {% if command.get("parameters", []) and not command.parameters[0].get("optional", False) %}, {% endif %}{# -#}
+ {% if command.get("returns", []) -%}
base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback{##}
{% else -%}
base::Callback<void()> callback{##}
@@ -75,8 +64,19 @@ void {{class_name}}::{{method_name}}({##}
{% endfor %}
.Build();
{# Send the message. #}
- {{method_name}}(std::move(params), std::move(callback));
+ {% if command.get("returns", []) -%}
+ dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Serialize(), base::Bind(&Domain::Handle{{method_name}}Response, callback));
+ {% else %}
+ dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Serialize(), std::move(callback));
+ {% endif %}
+}
+ {# If the command has no return value, generate a convenience method that #}
+ {# accepts a base::Callback<void()> together with the parameters object. #}
+ {% if not command.get("returns", []) %}
+void {{class_name}}::{{method_name}}(std::unique_ptr<{{method_name}}Params> params, base::Callback<void()> callback) {
+ dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Serialize(), std::move(callback));
}
+ {% endif %}
{% endfor %}
{# Generate response handlers for commands that need them. #}
« no previous file with comments | « headless/lib/browser/client_api_generator_unittest.py ('k') | headless/lib/browser/domain_h.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698