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 14 matching lines...) Expand all Loading... |
25 observers_.RemoveObserver(observer); | 25 observers_.RemoveObserver(observer); |
26 } | 26 } |
27 {% endif %} | 27 {% endif %} |
28 | 28 |
29 {% for command in domain.commands %} | 29 {% for command in domain.commands %} |
30 {# Skip redirected commands. #} | 30 {# Skip redirected commands. #} |
31 {% if "redirect" in command %}{% continue %}{% endif %} | 31 {% if "redirect" in command %}{% continue %}{% endif %} |
32 | 32 |
33 {% set class_name = 'ExperimentalDomain' if command.experimental else 'Domai
n' %} | 33 {% set class_name = 'ExperimentalDomain' if command.experimental else 'Domai
n' %} |
34 {% set method_name = command.name | to_title_case %} | 34 {% set method_name = command.name | to_title_case %} |
35 {% if "parameters" in command and "returns" in command %} | |
36 void {{class_name}}::{{method_name}}(std::unique_ptr<{{method_name}}Params> para
ms, base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback) { | 35 void {{class_name}}::{{method_name}}(std::unique_ptr<{{method_name}}Params> para
ms, base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback) { |
37 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali
ze(), base::Bind(&Domain::Handle{{method_name}}Response, callback)); | 36 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali
ze(), base::Bind(&Domain::Handle{{method_name}}Response, callback)); |
38 {% elif "parameters" in command %} | |
39 void {{class_name}}::{{method_name}}(std::unique_ptr<{{method_name}}Params> para
ms, base::Callback<void()> callback) { | |
40 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali
ze(), std::move(callback)); | |
41 {% elif "returns" in command %} | |
42 void {{class_name}}::{{method_name}}(base::Callback<void(std::unique_ptr<{{metho
d_name}}Result>)> callback) { | |
43 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", base::Bind(&Dom
ain::Handle{{method_name}}Response, std::move(callback))); | |
44 {% else %} | |
45 void {{class_name}}::{{method_name}}(base::Callback<void()> callback) { | |
46 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", std::move(callb
ack)); | |
47 {% endif %} | |
48 } | 37 } |
49 {# Generate convenience methods that take the required parameters directly.
#} | 38 {# Generate convenience methods that take the required parameters directly.
#} |
50 {% if not "parameters" in command %}{% continue %}{% endif %} | 39 {% if not "parameters" in command %}{% continue %}{% endif %} |
51 {# Don't generate these for experimental commands. #} | 40 {# Don't generate these for experimental commands. #} |
52 {% if command.experimental %}{% continue %}{% endif %} | 41 {% if command.experimental %}{% continue %}{% endif %} |
53 | 42 |
54 void {{class_name}}::{{method_name}}({##} | 43 void {{class_name}}::{{method_name}}({##} |
55 {% for parameter in command.parameters -%} | 44 {% for parameter in command.parameters -%} |
56 {% if parameter.get("optional", False) -%} | 45 {% if parameter.get("optional", False) -%} |
57 {% break %} | 46 {% break %} |
58 {% endif %} | 47 {% endif %} |
59 {% if not loop.first %}, {% endif %} | 48 {% if not loop.first %}, {% endif %} |
60 {{resolve_type(parameter).pass_type}} {{parameter.name | camelcase_to_hacker_sty
le -}} | 49 {{resolve_type(parameter).pass_type}} {{parameter.name | camelcase_to_hacker_sty
le -}} |
61 {% endfor %} | 50 {% endfor %} |
62 {% if "parameters" in command and not command.parameters[0].get("optional",
False) %}, {% endif %}{# -#} | 51 {% if command.get("parameters", []) and not command.parameters[0].get("optio
nal", False) %}, {% endif %}{# -#} |
63 {% if "returns" in command -%} | 52 {% if command.get("returns", []) -%} |
64 base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback{##} | 53 base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback{##} |
65 {% else -%} | 54 {% else -%} |
66 base::Callback<void()> callback{##} | 55 base::Callback<void()> callback{##} |
67 {% endif %}) { | 56 {% endif %}) { |
68 {# Build the parameters object. #} | 57 {# Build the parameters object. #} |
69 std::unique_ptr<{{method_name}}Params> params = {{method_name}}Params::Builder
() | 58 std::unique_ptr<{{method_name}}Params> params = {{method_name}}Params::Builder
() |
70 {% for parameter in command.parameters -%} | 59 {% for parameter in command.parameters -%} |
71 {% if parameter.get("optional", False) -%} | 60 {% if parameter.get("optional", False) -%} |
72 {% break %} | 61 {% break %} |
73 {% endif %} | 62 {% endif %} |
74 .Set{{parameter.name | to_title_case}}(std::move({{parameter.name | camelc
ase_to_hacker_style}})) | 63 .Set{{parameter.name | to_title_case}}(std::move({{parameter.name | camelc
ase_to_hacker_style}})) |
75 {% endfor %} | 64 {% endfor %} |
76 .Build(); | 65 .Build(); |
77 {# Send the message. #} | 66 {# Send the message. #} |
78 {{method_name}}(std::move(params), std::move(callback)); | 67 {% if command.get("returns", []) -%} |
| 68 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali
ze(), base::Bind(&Domain::Handle{{method_name}}Response, callback)); |
| 69 {% else %} |
| 70 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali
ze(), std::move(callback)); |
| 71 {% endif %} |
79 } | 72 } |
| 73 {# If the command has no return value, generate a convenience method that #} |
| 74 {# accepts a base::Callback<void()> together with the parameters object. #} |
| 75 {% if not command.get("returns", []) %} |
| 76 void {{class_name}}::{{method_name}}(std::unique_ptr<{{method_name}}Params> para
ms, base::Callback<void()> callback) { |
| 77 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali
ze(), std::move(callback)); |
| 78 } |
| 79 {% endif %} |
80 {% endfor %} | 80 {% endfor %} |
81 | 81 |
82 {# Generate response handlers for commands that need them. #} | 82 {# Generate response handlers for commands that need them. #} |
83 {% for command in domain.commands %} | 83 {% for command in domain.commands %} |
84 {% if not "returns" in command %}{% continue %}{% endif %} | 84 {% if not "returns" in command %}{% continue %}{% endif %} |
85 {% set method_name = command.name | to_title_case %} | 85 {% set method_name = command.name | to_title_case %} |
86 | 86 |
87 // static | 87 // static |
88 void Domain::Handle{{method_name}}Response(base::Callback<void(std::unique_ptr<{
{method_name}}Result>)> callback, const base::Value& response) { | 88 void Domain::Handle{{method_name}}Response(base::Callback<void(std::unique_ptr<{
{method_name}}Result>)> callback, const base::Value& response) { |
89 if (callback.is_null()) | 89 if (callback.is_null()) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 133 } |
134 | 134 |
135 void ExperimentalDomain::RemoveObserver(ExperimentalObserver* observer) { | 135 void ExperimentalDomain::RemoveObserver(ExperimentalObserver* observer) { |
136 observers_.RemoveObserver(observer); | 136 observers_.RemoveObserver(observer); |
137 } | 137 } |
138 {% endif %} | 138 {% endif %} |
139 | 139 |
140 } // namespace {{domain.domain | camelcase_to_hacker_style}} | 140 } // namespace {{domain.domain | camelcase_to_hacker_style}} |
141 | 141 |
142 } // namespace headless | 142 } // namespace headless |
OLD | NEW |