| Index: headless/lib/browser/domain_cc.template
|
| diff --git a/headless/lib/browser/domain_cc.template b/headless/lib/browser/domain_cc.template
|
| index 9ce250ab9a7ba8a07409c4f944c788d3b68ccb8f..118d996627e6de2aaf9ea37f416e14db7de2bcc1 100644
|
| --- a/headless/lib/browser/domain_cc.template
|
| +++ b/headless/lib/browser/domain_cc.template
|
| @@ -12,17 +12,8 @@ namespace headless {
|
|
|
| namespace {{domain.domain | camelcase_to_hacker_style}} {
|
|
|
| -Domain::Domain(internal::MessageDispatcher* dispatcher)
|
| - : dispatcher_(dispatcher) {
|
| - {% if "events" in domain %}
|
| - {# 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 %}
|
| +ExperimentalDomain* Domain::GetExperimental() {
|
| + return static_cast<ExperimentalDomain*>(this);
|
| }
|
|
|
| {% if "events" in domain %}
|
| @@ -35,30 +26,32 @@ void Domain::RemoveObserver(Observer* observer) {
|
| }
|
| {% endif %}
|
|
|
| -Domain::~Domain() {}
|
| {% for command in domain.commands %}
|
| {# Skip redirected commands. #}
|
| {% if "redirect" in command %}{% continue %}{% endif %}
|
|
|
| + {% set class_name = 'ExperimentalDomain' if command.hidden else 'Domain' %}
|
| {% set method_name = command.name | to_title_case %}
|
| {% if "parameters" in command and "returns" in command %}
|
| -void Domain::{{method_name}}(std::unique_ptr<{{method_name}}Params> params, base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback) {
|
| +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 Domain::{{method_name}}(std::unique_ptr<{{method_name}}Params> params, base::Callback<void()> callback) {
|
| +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 Domain::{{method_name}}(base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback) {
|
| +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 Domain::{{method_name}}(base::Callback<void()> callback) {
|
| +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 %}
|
| + {# Don't generate these for hidden commands. #}
|
| + {% if command.hidden %}{% continue %}{% endif %}
|
|
|
| -void Domain::{{method_name}}({##}
|
| +void {{class_name}}::{{method_name}}({##}
|
| {% for parameter in command.parameters -%}
|
| {% if parameter.get("optional", False) -%}
|
| {% break %}
|
| @@ -109,11 +102,41 @@ void Domain::Dispatch{{event.name | to_title_case}}Event(const base::Value& para
|
| 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_EACH_OBSERVER(Observer, observers_, On{{event.name | to_title_case}}(*parsed_params));
|
| + FOR_EACH_OBSERVER(ExperimentalObserver, observers_, On{{event.name | to_title_case}}(*parsed_params));
|
| }
|
| {% endfor %}
|
| {% endif %}
|
|
|
| +Domain::Domain(internal::MessageDispatcher* dispatcher)
|
| + : dispatcher_(dispatcher) {
|
| + {% if "events" in domain %}
|
| + {# 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 %}
|
| +}
|
| +
|
| +Domain::~Domain() {}
|
| +
|
| +ExperimentalDomain::ExperimentalDomain(internal::MessageDispatcher* dispatcher)
|
| + : Domain(dispatcher) {}
|
| +
|
| +ExperimentalDomain::~ExperimentalDomain() {}
|
| +
|
| + {% if "events" in domain %}
|
| +void ExperimentalDomain::AddObserver(ExperimentalObserver* observer) {
|
| + observers_.AddObserver(observer);
|
| +}
|
| +
|
| +void ExperimentalDomain::RemoveObserver(ExperimentalObserver* observer) {
|
| + observers_.RemoveObserver(observer);
|
| +}
|
| + {% endif %}
|
| +
|
| } // namespace {{domain.domain | camelcase_to_hacker_style}}
|
|
|
| } // namespace headless
|
|
|