OLD | NEW |
(Empty) | |
| 1 // This file is generated |
| 2 |
| 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 |
| 5 // found in the LICENSE file. |
| 6 |
| 7 #include "headless/public/domains/{{domain.domain | camelcase_to_hacker_style}}.
h" |
| 8 |
| 9 #include "base/bind.h" |
| 10 |
| 11 namespace headless { |
| 12 |
| 13 namespace {{domain.domain | camelcase_to_hacker_style}} { |
| 14 |
| 15 Domain::Domain(internal::MessageDispatcher* dispatcher) : dispatcher_(dispatcher
) {} |
| 16 |
| 17 Domain::~Domain() {} |
| 18 {% for command in domain.commands %} |
| 19 {# Skip redirected commands. #} |
| 20 {% if "redirect" in command %}{% continue %}{% endif %} |
| 21 |
| 22 {% set method_name = command.name | to_title_case %} |
| 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) { |
| 25 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali
ze(), base::Bind(&Domain::Handle{{method_name}}Response, callback)); |
| 26 {% elif "parameters" in command %} |
| 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)); |
| 29 {% elif "returns" in command %} |
| 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)); |
| 32 {% else %} |
| 33 void Domain::{{method_name}}(base::Callback<void()> callback) { |
| 34 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", std::move(callb
ack)); |
| 35 {% endif %} |
| 36 } |
| 37 {% endfor %} |
| 38 |
| 39 {# Generate response handlers for commands that need them. #} |
| 40 {% for command in domain.commands %} |
| 41 {% if not "returns" in command %}{% continue %}{% endif %} |
| 42 {% set method_name = command.name | to_title_case %} |
| 43 |
| 44 // static |
| 45 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()) |
| 47 return; |
| 48 ErrorReporter errors; |
| 49 std::unique_ptr<{{method_name}}Result> result = {{method_name}}Result::Parse(r
esponse, &errors); |
| 50 DCHECK(!errors.HasErrors()); |
| 51 callback.Run(std::move(result)); |
| 52 } |
| 53 {% endfor %} |
| 54 |
| 55 } // namespace {{domain.domain | camelcase_to_hacker_style}} |
| 56 |
| 57 } // namespace headless |
OLD | NEW |