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

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

Issue 1907533002: headless: Implement DevTools events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add parameters to all events Created 4 years, 8 months 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/client_api_generator_unittest.py ('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
index 9a99bdec8e1169b977542169f7150677afafd78d..9ce250ab9a7ba8a07409c4f944c788d3b68ccb8f 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,18 @@ 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(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_EACH_OBSERVER(Observer, observers_, On{{event.name | to_title_case}}(*parsed_params));
+}
+ {% endfor %}
+{% endif %}
} // namespace {{domain.domain | camelcase_to_hacker_style}}
« no previous file with comments | « headless/lib/browser/client_api_generator_unittest.py ('k') | headless/lib/browser/domain_h.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698