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 9a99bdec8e1169b977542169f7150677afafd78d..fb8ef76de9418475b7c4901ff9ec42e0d6b9cf48 100644 |
| --- a/headless/lib/browser/domain_cc.template |
| +++ b/headless/lib/browser/domain_cc.template |
| @@ -12,7 +12,28 @@ namespace headless { |
| namespace {{domain.domain | camelcase_to_hacker_style}} { |
| -Domain::Domain(internal::MessageDispatcher* dispatcher) : dispatcher_(dispatcher) {} |
| +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 %} |
| +} |
| + |
| + {% if "events" in domain %} |
| +void Domain::AddObserver(Observer* observer) { |
| + observers_.AddObserver(observer); |
| +} |
| + |
| +void Domain::RemoveObserver(Observer* observer) { |
| + observers_.RemoveObserver(observer); |
| +} |
| + {% endif %} |
| Domain::~Domain() {} |
| {% for command in domain.commands %} |
| @@ -80,6 +101,25 @@ void Domain::Handle{{method_name}}Response(base::Callback<void(std::unique_ptr<{ |
| 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({# -#} |
| + {% if "parameters" in event %}{# -#} |
| + const base::Value& params{# -#} |
| + {% endif %}) { |
| + {% if "parameters" in 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)); |
| + {% else %} |
| + FOR_EACH_OBSERVER(Observer, observers_, On{{event.name | to_title_case}}()); |
|
dgozman
2016/04/21 17:21:36
It could be easier for clients to roll new version
Sami
2016/04/22 10:36:22
Great points, I didn't consider that we might add
|
| + {% endif %} |
| +} |
| + {% endfor %} |
| +{% endif %} |
| } // namespace {{domain.domain | camelcase_to_hacker_style}} |