OLD | NEW |
1 // This file is generated | 1 // This file is generated |
2 | 2 |
3 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 3 // Copyright (c) 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 #ifndef HEADLESS_PUBLIC_DOMAINS_{{domain.domain | camelcase_to_hacker_style | up
per}}_H_ | 7 #ifndef HEADLESS_PUBLIC_DOMAINS_{{domain.domain | camelcase_to_hacker_style | up
per}}_H_ |
8 #define HEADLESS_PUBLIC_DOMAINS_{{domain.domain | camelcase_to_hacker_style | up
per}}_H_ | 8 #define HEADLESS_PUBLIC_DOMAINS_{{domain.domain | camelcase_to_hacker_style | up
per}}_H_ |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/observer_list.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "headless/public/domains/types.h" | 13 #include "headless/public/domains/types.h" |
13 #include "headless/public/headless_export.h" | 14 #include "headless/public/headless_export.h" |
14 #include "headless/public/internal/message_dispatcher.h" | 15 #include "headless/public/internal/message_dispatcher.h" |
15 | 16 |
16 namespace headless { | 17 namespace headless { |
17 namespace {{domain.domain | camelcase_to_hacker_style}} { | 18 namespace {{domain.domain | camelcase_to_hacker_style}} { |
| 19 {% if "events" in domain %} |
| 20 class Observer { |
| 21 public: |
| 22 virtual ~Observer() {} |
| 23 {% for event in domain.events %} |
| 24 virtual void On{{event.name | to_title_case}}({# -#} |
| 25 {% if "parameters" in event %}{# -#} |
| 26 const {{event.name | to_title_case}}Params& params{# -#} |
| 27 {% endif %}) {} |
| 28 {% endfor %} |
| 29 }; |
| 30 {% endif %} |
18 | 31 |
19 {% if domain.description %} | 32 {% if domain.description %} |
20 // {{domain.description}} | 33 // {{domain.description}} |
21 {% endif %} | 34 {% endif %} |
22 class HEADLESS_EXPORT Domain { | 35 class HEADLESS_EXPORT Domain { |
23 public: | 36 public: |
24 Domain(internal::MessageDispatcher* dispatcher); | 37 Domain(internal::MessageDispatcher* dispatcher); |
25 ~Domain(); | 38 ~Domain(); |
26 | 39 |
| 40 {% if "events" in domain %} |
| 41 // Add or remove an observer. |observer| must be removed before being |
| 42 // destroyed. |
| 43 void AddObserver(Observer* observer); |
| 44 void RemoveObserver(Observer* observer); |
| 45 {% endif %} |
| 46 |
27 {# Generate methods for each command. #} | 47 {# Generate methods for each command. #} |
28 {% for command in domain.commands %} | 48 {% for command in domain.commands %} |
29 {# Skip redirected commands. #} | 49 {# Skip redirected commands. #} |
30 {% if "redirect" in command %}{% continue %}{% endif %} | 50 {% if "redirect" in command %}{% continue %}{% endif %} |
31 {% set method_name = command.name | to_title_case %} | 51 {% set method_name = command.name | to_title_case %} |
32 {% if command.description %} | 52 {% if command.description %} |
33 // {{ command.description }} | 53 // {{ command.description }} |
34 {% endif %} | 54 {% endif %} |
35 {% if "parameters" in command and "returns" in command %} | 55 {% if "parameters" in command and "returns" in command %} |
36 void {{method_name}}(std::unique_ptr<{{method_name}}Params> params, base::Call
back<void(std::unique_ptr<{{method_name}}Result>)> callback = base::Callback<voi
d(std::unique_ptr<{{method_name}}Result>)>()); | 56 void {{method_name}}(std::unique_ptr<{{method_name}}Params> params, base::Call
back<void(std::unique_ptr<{{method_name}}Result>)> callback = base::Callback<voi
d(std::unique_ptr<{{method_name}}Result>)>()); |
(...skipping 22 matching lines...) Expand all Loading... |
59 {% endif %}); | 79 {% endif %}); |
60 {% endfor %} | 80 {% endfor %} |
61 private: | 81 private: |
62 {# Generate response handlers for commands that need them. #} | 82 {# Generate response handlers for commands that need them. #} |
63 {% for command in domain.commands %} | 83 {% for command in domain.commands %} |
64 {% if not "returns" in command %}{% continue %}{% endif %} | 84 {% if not "returns" in command %}{% continue %}{% endif %} |
65 {% set method_name = command.name | to_title_case %} | 85 {% set method_name = command.name | to_title_case %} |
66 static void Handle{{method_name}}Response(base::Callback<void(std::unique_ptr<
{{method_name}}Result>)> callback, const base::Value& response); | 86 static void Handle{{method_name}}Response(base::Callback<void(std::unique_ptr<
{{method_name}}Result>)> callback, const base::Value& response); |
67 {% endfor %} | 87 {% endfor %} |
68 | 88 |
| 89 {# Generate event dispatchers. #} |
| 90 {% for event in domain.events %} |
| 91 void Dispatch{{event.name | to_title_case}}Event({# -#} |
| 92 {% if "parameters" in event %}{# -#} |
| 93 const base::Value& params{# -#} |
| 94 {% endif %}); |
| 95 {% endfor %} |
| 96 |
69 internal::MessageDispatcher* dispatcher_; // Not owned. | 97 internal::MessageDispatcher* dispatcher_; // Not owned. |
| 98 {% if "events" in domain %} |
| 99 base::ObserverList<Observer> observers_; |
| 100 {% endif %} |
70 | 101 |
71 DISALLOW_COPY_AND_ASSIGN(Domain); | 102 DISALLOW_COPY_AND_ASSIGN(Domain); |
72 }; | 103 }; |
73 | 104 |
74 } // namespace {{domain.domain | camelcase_to_hacker_style}} | 105 } // namespace {{domain.domain | camelcase_to_hacker_style}} |
75 } // namespace headless | 106 } // namespace headless |
76 | 107 |
77 #endif // HEADLESS_PUBLIC_DOMAINS_{{domain.domain | camelcase_to_hacker_style |
upper}}_H_ | 108 #endif // HEADLESS_PUBLIC_DOMAINS_{{domain.domain | camelcase_to_hacker_style |
upper}}_H_ |
OLD | NEW |