Chromium Code Reviews| Index: headless/lib/browser/domain_cc.template |
| diff --git a/headless/lib/browser/domain_cc.template b/headless/lib/browser/domain_cc.template |
| index fb8ef76de9418475b7c4901ff9ec42e0d6b9cf48..ae30bcdb23653c09407bda0ec030ecaf9e74beb5 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() { |
|
altimin
2016/04/21 14:49:10
Nit: const?
Sami
2016/04/21 14:51:13
I thought about it but it doesn't quite work since
|
| + return static_cast<ExperimentalDomain*>(this); |
| } |
| {% if "events" in domain %} |
| @@ -35,30 +26,30 @@ 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 %} |
| -void Domain::{{method_name}}({##} |
| +void {{class_name}}::{{method_name}}({##} |
| {% for parameter in command.parameters -%} |
| {% if parameter.get("optional", False) -%} |
| {% break %} |
| @@ -113,14 +104,44 @@ void Domain::Dispatch{{event.name | to_title_case}}Event({# -#} |
| 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)); |
| {% else %} |
| - FOR_EACH_OBSERVER(Observer, observers_, On{{event.name | to_title_case}}()); |
| + FOR_EACH_OBSERVER(ExperimentalObserver, observers_, On{{event.name | to_title_case}}()); |
| {% endif %} |
| } |
| {% 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 |