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

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

Issue 2473073003: [headless] Refactor headless devtools client API. (Closed)
Patch Set: Address nits 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
« no previous file with comments | « headless/lib/browser/devtools_api/domain_types_h.template ('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
deleted file mode 100644
index a59ea16c62a4a80cc3a082ced64a02557f44a805..0000000000000000000000000000000000000000
--- a/headless/lib/browser/domain_cc.template
+++ /dev/null
@@ -1,150 +0,0 @@
-// This file is generated
-
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "headless/public/domains/{{domain.domain | camelcase_to_hacker_style}}.h"
-
-#include "base/bind.h"
-
-namespace headless {
-
-namespace {{domain.domain | camelcase_to_hacker_style}} {
-
-ExperimentalDomain* Domain::GetExperimental() {
- return static_cast<ExperimentalDomain*>(this);
-}
-
- {% if "events" in domain %}
-void Domain::AddObserver(Observer* observer) {
- RegisterEventHandlersIfNeeded();
- observers_.AddObserver(observer);
-}
-
-void Domain::RemoveObserver(Observer* observer) {
- observers_.RemoveObserver(observer);
-}
-
-void Domain::RegisterEventHandlersIfNeeded() {
- if (event_handlers_registered_)
- return;
- event_handlers_registered_ = true;
- {# Register all events in this domain. #}
- {% for event in domain.events %}
- dispatcher_->RegisterEventHandler(
- "{{domain.domain}}.{{event.name}}",
- base::Bind(&Domain::Dispatch{{event.name | to_title_case}}Event,
- base::Unretained(this)));
- {% endfor %}
-}
- {% endif %}
-
- {% for command in domain.commands %}
- {# Skip redirected commands. #}
- {% if "redirect" in command %}{% continue %}{% endif %}
-
- {% set class_name = 'ExperimentalDomain' if command.experimental else 'Domain' %}
- {% set method_name = command.name | to_title_case %}
-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));
-}
- {# Generate convenience methods that take the required parameters directly. #}
- {% if not "parameters" in command %}{% continue %}{% endif %}
- {# Don't generate these for experimental commands. #}
- {% if command.experimental %}{% continue %}{% endif %}
-
-void {{class_name}}::{{method_name}}({##}
- {% for parameter in command.parameters -%}
- {% if parameter.get("optional", False) -%}
- {% break %}
- {% endif %}
- {% if not loop.first %}, {% endif %}
-{{resolve_type(parameter).pass_type}} {{parameter.name | camelcase_to_hacker_style -}}
- {% endfor %}
- {% 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{##}
- {% endif %}) {
- {# Build the parameters object. #}
- std::unique_ptr<{{method_name}}Params> params = {{method_name}}Params::Builder()
- {% for parameter in command.parameters -%}
- {% if parameter.get("optional", False) -%}
- {% break %}
- {% endif %}
- .Set{{parameter.name | to_title_case}}(std::move({{parameter.name | camelcase_to_hacker_style}}))
- {% endfor %}
- .Build();
- {# Send the message. #}
- {% 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. #}
-{% for command in domain.commands %}
- {% if not "returns" in command %}{% continue %}{% endif %}
- {% set method_name = command.name | to_title_case %}
-
-// static
-void Domain::Handle{{method_name}}Response(base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback, const base::Value& response) {
- if (callback.is_null())
- return;
- ErrorReporter errors;
- std::unique_ptr<{{method_name}}Result> result = {{method_name}}Result::Parse(response, &errors);
- DCHECK(!errors.HasErrors());
- callback.Run(std::move(result));
-}
-{% endfor %}
-{% if "events" in domain %}
- {% for event in domain.events %}
-
-{# Generate dispatchers which call registered observers for an event. #}
-void Domain::Dispatch{{event.name | to_title_case}}Event(const base::Value& params) {
- ErrorReporter errors;
- std::unique_ptr<{{event.name | to_title_case}}Params> parsed_params({{event.name | to_title_case}}Params::Parse(params, &errors));
- DCHECK(!errors.HasErrors());
- for (ExperimentalObserver& observer : observers_) {
- observer.On{{event.name | to_title_case}}(*parsed_params);
- }
-}
- {% endfor %}
-{% endif %}
-
-Domain::Domain(internal::MessageDispatcher* dispatcher)
- : dispatcher_(dispatcher) {
-}
-
-Domain::~Domain() {}
-
-ExperimentalDomain::ExperimentalDomain(internal::MessageDispatcher* dispatcher)
- : Domain(dispatcher) {}
-
-ExperimentalDomain::~ExperimentalDomain() {}
-
- {% if "events" in domain %}
-void ExperimentalDomain::AddObserver(ExperimentalObserver* observer) {
- RegisterEventHandlersIfNeeded();
- observers_.AddObserver(observer);
-}
-
-void ExperimentalDomain::RemoveObserver(ExperimentalObserver* observer) {
- observers_.RemoveObserver(observer);
-}
- {% endif %}
-
-} // namespace {{domain.domain | camelcase_to_hacker_style}}
-
-} // namespace headless
« no previous file with comments | « headless/lib/browser/devtools_api/domain_types_h.template ('k') | headless/lib/browser/domain_h.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698