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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // This file is generated 1 // This file is generated
2 2
3 // Copyright 2016 The Chromium Authors. All rights reserved. 3 // Copyright 2016 The Chromium Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be 4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file. 5 // found in the LICENSE file.
6 6
7 #include "headless/public/domains/{{domain.domain | camelcase_to_hacker_style}}. h" 7 #include "headless/public/domains/{{domain.domain | camelcase_to_hacker_style}}. h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 10
11 namespace headless { 11 namespace headless {
12 12
13 namespace {{domain.domain | camelcase_to_hacker_style}} { 13 namespace {{domain.domain | camelcase_to_hacker_style}} {
14 14
15 Domain::Domain(internal::MessageDispatcher* dispatcher) : dispatcher_(dispatcher ) {} 15 Domain::Domain(internal::MessageDispatcher* dispatcher)
16 : dispatcher_(dispatcher) {
17 {% if "events" in domain %}
18 {# Register all events in this domain. #}
19 {% for event in domain.events %}
20 dispatcher_->RegisterEventHandler(
21 "{{domain.domain}}.{{event.name}}",
22 base::Bind(&Domain::Dispatch{{event.name | to_title_case}}Event,
23 base::Unretained(this)));
24 {% endfor %}
25 {% endif %}
26 }
27
28 {% if "events" in domain %}
29 void Domain::AddObserver(Observer* observer) {
30 observers_.AddObserver(observer);
31 }
32
33 void Domain::RemoveObserver(Observer* observer) {
34 observers_.RemoveObserver(observer);
35 }
36 {% endif %}
16 37
17 Domain::~Domain() {} 38 Domain::~Domain() {}
18 {% for command in domain.commands %} 39 {% for command in domain.commands %}
19 {# Skip redirected commands. #} 40 {# Skip redirected commands. #}
20 {% if "redirect" in command %}{% continue %}{% endif %} 41 {% if "redirect" in command %}{% continue %}{% endif %}
21 42
22 {% set method_name = command.name | to_title_case %} 43 {% set method_name = command.name | to_title_case %}
23 {% if "parameters" in command and "returns" in command %} 44 {% if "parameters" in command and "returns" in command %}
24 void Domain::{{method_name}}(std::unique_ptr<{{method_name}}Params> params, base ::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback) { 45 void Domain::{{method_name}}(std::unique_ptr<{{method_name}}Params> params, base ::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback) {
25 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali ze(), base::Bind(&Domain::Handle{{method_name}}Response, callback)); 46 dispatcher_->SendMessage("{{domain.domain}}.{{command.name}}", params->Seriali ze(), base::Bind(&Domain::Handle{{method_name}}Response, callback));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // static 94 // static
74 void Domain::Handle{{method_name}}Response(base::Callback<void(std::unique_ptr<{ {method_name}}Result>)> callback, const base::Value& response) { 95 void Domain::Handle{{method_name}}Response(base::Callback<void(std::unique_ptr<{ {method_name}}Result>)> callback, const base::Value& response) {
75 if (callback.is_null()) 96 if (callback.is_null())
76 return; 97 return;
77 ErrorReporter errors; 98 ErrorReporter errors;
78 std::unique_ptr<{{method_name}}Result> result = {{method_name}}Result::Parse(r esponse, &errors); 99 std::unique_ptr<{{method_name}}Result> result = {{method_name}}Result::Parse(r esponse, &errors);
79 DCHECK(!errors.HasErrors()); 100 DCHECK(!errors.HasErrors());
80 callback.Run(std::move(result)); 101 callback.Run(std::move(result));
81 } 102 }
82 {% endfor %} 103 {% endfor %}
104 {% if "events" in domain %}
105 {% for event in domain.events %}
106
107 {# Generate dispatchers which call registered observers for an event. #}
108 void Domain::Dispatch{{event.name | to_title_case}}Event({# -#}
109 {% if "parameters" in event %}{# -#}
110 const base::Value& params{# -#}
111 {% endif %}) {
112 {% if "parameters" in event %}
113 ErrorReporter errors;
114 std::unique_ptr<{{event.name | to_title_case}}Params> parsed_params({{event.na me | to_title_case}}Params::Parse(params, &errors));
115 DCHECK(!errors.HasErrors());
116 FOR_EACH_OBSERVER(Observer, observers_, On{{event.name | to_title_case}}(*pars ed_params));
117 {% else %}
118 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
119 {% endif %}
120 }
121 {% endfor %}
122 {% endif %}
83 123
84 } // namespace {{domain.domain | camelcase_to_hacker_style}} 124 } // namespace {{domain.domain | camelcase_to_hacker_style}}
85 125
86 } // namespace headless 126 } // namespace headless
OLDNEW
« 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