| OLD | NEW |
| 1 // This file is generated | 1 // This file is generated |
| 2 | 2 |
| 3 // Copyright 2016 The Chromium Authors. All rights reserved. | 3 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 4 // Use of this source code is governed by a BSD-style license that can be | 4 // Use of this source code is governed by a BSD-style license that can be |
| 5 // found in the LICENSE file. | 5 // found in the LICENSE file. |
| 6 | 6 |
| 7 #include "headless/public/domains/{{domain.domain | camelcase_to_hacker_style}}.
h" | 7 #include "headless/public/domains/{{domain.domain | camelcase_to_hacker_style}}.
h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 {% set method_name = command.name | to_title_case %} | 22 {% set method_name = command.name | to_title_case %} |
| 23 {% if "parameters" in command and "returns" in command %} | 23 {% if "parameters" in command and "returns" in command %} |
| 24 void Domain::{{method_name}}(std::unique_ptr<{{method_name}}Params> params, base
::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback) { | 24 void Domain::{{method_name}}(std::unique_ptr<{{method_name}}Params> params, base
::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback) { |
| 25 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali
ze(), base::Bind(&Domain::Handle{{method_name}}Response, callback)); | 25 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali
ze(), base::Bind(&Domain::Handle{{method_name}}Response, callback)); |
| 26 {% elif "parameters" in command %} | 26 {% elif "parameters" in command %} |
| 27 void Domain::{{method_name}}(std::unique_ptr<{{method_name}}Params> params, base
::Callback<void()> callback) { | 27 void Domain::{{method_name}}(std::unique_ptr<{{method_name}}Params> params, base
::Callback<void()> callback) { |
| 28 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali
ze(), std::move(callback)); | 28 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali
ze(), std::move(callback)); |
| 29 {% elif "returns" in command %} | 29 {% elif "returns" in command %} |
| 30 void Domain::{{method_name}}(base::Callback<void(std::unique_ptr<{{method_name}}
Result>)> callback) { | 30 void Domain::{{method_name}}(base::Callback<void(std::unique_ptr<{{method_name}}
Result>)> callback) { |
| 31 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", base::Bind(&Dom
ain::Handle{{method_name}}Response, callback)); | 31 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", base::Bind(&Dom
ain::Handle{{method_name}}Response, std::move(callback))); |
| 32 {% else %} | 32 {% else %} |
| 33 void Domain::{{method_name}}(base::Callback<void()> callback) { | 33 void Domain::{{method_name}}(base::Callback<void()> callback) { |
| 34 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", std::move(callb
ack)); | 34 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", std::move(callb
ack)); |
| 35 {% endif %} | 35 {% endif %} |
| 36 } | 36 } |
| 37 {# Generate convenience methods that take the required parameters directly.
#} |
| 38 {% if not "parameters" in command %}{% continue %}{% endif %} |
| 39 |
| 40 void Domain::{{method_name}}({##} |
| 41 {% for parameter in command.parameters -%} |
| 42 {% if parameter.get("optional", False) -%} |
| 43 {% break %} |
| 44 {% endif %} |
| 45 {% if not loop.first %}, {% endif %} |
| 46 {{resolve_type(parameter).pass_type}} {{parameter.name | camelcase_to_hacker_sty
le -}} |
| 47 {% endfor %} |
| 48 {% if "parameters" in command and not command.parameters[0].get("optional",
False) %}, {% endif %}{# -#} |
| 49 {% if "returns" in command -%} |
| 50 base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback{##} |
| 51 {% else -%} |
| 52 base::Callback<void()> callback{##} |
| 53 {% endif %}) { |
| 54 {# Build the parameters object. #} |
| 55 std::unique_ptr<{{method_name}}Params> params = {{method_name}}Params::Builder
() |
| 56 {% for parameter in command.parameters -%} |
| 57 {% if parameter.get("optional", False) -%} |
| 58 {% break %} |
| 59 {% endif %} |
| 60 .Set{{parameter.name | to_title_case}}(std::move({{parameter.name | camelc
ase_to_hacker_style}})) |
| 61 {% endfor %} |
| 62 .Build(); |
| 63 {# Send the message. #} |
| 64 {{method_name}}(std::move(params), std::move(callback)); |
| 65 } |
| 37 {% endfor %} | 66 {% endfor %} |
| 38 | 67 |
| 39 {# Generate response handlers for commands that need them. #} | 68 {# Generate response handlers for commands that need them. #} |
| 40 {% for command in domain.commands %} | 69 {% for command in domain.commands %} |
| 41 {% if not "returns" in command %}{% continue %}{% endif %} | 70 {% if not "returns" in command %}{% continue %}{% endif %} |
| 42 {% set method_name = command.name | to_title_case %} | 71 {% set method_name = command.name | to_title_case %} |
| 43 | 72 |
| 44 // static | 73 // static |
| 45 void Domain::Handle{{method_name}}Response(base::Callback<void(std::unique_ptr<{
{method_name}}Result>)> callback, const base::Value& response) { | 74 void Domain::Handle{{method_name}}Response(base::Callback<void(std::unique_ptr<{
{method_name}}Result>)> callback, const base::Value& response) { |
| 46 if (callback.is_null()) | 75 if (callback.is_null()) |
| 47 return; | 76 return; |
| 48 ErrorReporter errors; | 77 ErrorReporter errors; |
| 49 std::unique_ptr<{{method_name}}Result> result = {{method_name}}Result::Parse(r
esponse, &errors); | 78 std::unique_ptr<{{method_name}}Result> result = {{method_name}}Result::Parse(r
esponse, &errors); |
| 50 DCHECK(!errors.HasErrors()); | 79 DCHECK(!errors.HasErrors()); |
| 51 callback.Run(std::move(result)); | 80 callback.Run(std::move(result)); |
| 52 } | 81 } |
| 53 {% endfor %} | 82 {% endfor %} |
| 54 | 83 |
| 55 } // namespace {{domain.domain | camelcase_to_hacker_style}} | 84 } // namespace {{domain.domain | camelcase_to_hacker_style}} |
| 56 | 85 |
| 57 } // namespace headless | 86 } // namespace headless |
| OLD | NEW |