| 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}}(const {{event.name | to_title_ca
se}}Params& params) {} |
| 25 {% endfor %} |
| 26 }; |
| 27 {% endif %} |
| 18 | 28 |
| 19 {% if domain.description %} | 29 {% if domain.description %} |
| 20 // {{domain.description}} | 30 // {{domain.description}} |
| 21 {% endif %} | 31 {% endif %} |
| 22 class HEADLESS_EXPORT Domain { | 32 class HEADLESS_EXPORT Domain { |
| 23 public: | 33 public: |
| 24 Domain(internal::MessageDispatcher* dispatcher); | 34 Domain(internal::MessageDispatcher* dispatcher); |
| 25 ~Domain(); | 35 ~Domain(); |
| 26 | 36 |
| 37 {% if "events" in domain %} |
| 38 // Add or remove an observer. |observer| must be removed before being |
| 39 // destroyed. |
| 40 void AddObserver(Observer* observer); |
| 41 void RemoveObserver(Observer* observer); |
| 42 {% endif %} |
| 43 |
| 27 {# Generate methods for each command. #} | 44 {# Generate methods for each command. #} |
| 28 {% for command in domain.commands %} | 45 {% for command in domain.commands %} |
| 29 {# Skip redirected commands. #} | 46 {# Skip redirected commands. #} |
| 30 {% if "redirect" in command %}{% continue %}{% endif %} | 47 {% if "redirect" in command %}{% continue %}{% endif %} |
| 31 {% set method_name = command.name | to_title_case %} | 48 {% set method_name = command.name | to_title_case %} |
| 32 {% if command.description %} | 49 {% if command.description %} |
| 33 // {{ command.description }} | 50 // {{ command.description }} |
| 34 {% endif %} | 51 {% endif %} |
| 35 {% if "parameters" in command and "returns" in command %} | 52 {% 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>)>()); | 53 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 %}); | 76 {% endif %}); |
| 60 {% endfor %} | 77 {% endfor %} |
| 61 private: | 78 private: |
| 62 {# Generate response handlers for commands that need them. #} | 79 {# Generate response handlers for commands that need them. #} |
| 63 {% for command in domain.commands %} | 80 {% for command in domain.commands %} |
| 64 {% if not "returns" in command %}{% continue %}{% endif %} | 81 {% if not "returns" in command %}{% continue %}{% endif %} |
| 65 {% set method_name = command.name | to_title_case %} | 82 {% 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); | 83 static void Handle{{method_name}}Response(base::Callback<void(std::unique_ptr<
{{method_name}}Result>)> callback, const base::Value& response); |
| 67 {% endfor %} | 84 {% endfor %} |
| 68 | 85 |
| 86 {# Generate event dispatchers. #} |
| 87 {% for event in domain.events %} |
| 88 void Dispatch{{event.name | to_title_case}}Event(const base::Value& params); |
| 89 {% endfor %} |
| 90 |
| 69 internal::MessageDispatcher* dispatcher_; // Not owned. | 91 internal::MessageDispatcher* dispatcher_; // Not owned. |
| 92 {% if "events" in domain %} |
| 93 base::ObserverList<Observer> observers_; |
| 94 {% endif %} |
| 70 | 95 |
| 71 DISALLOW_COPY_AND_ASSIGN(Domain); | 96 DISALLOW_COPY_AND_ASSIGN(Domain); |
| 72 }; | 97 }; |
| 73 | 98 |
| 74 } // namespace {{domain.domain | camelcase_to_hacker_style}} | 99 } // namespace {{domain.domain | camelcase_to_hacker_style}} |
| 75 } // namespace headless | 100 } // namespace headless |
| 76 | 101 |
| 77 #endif // HEADLESS_PUBLIC_DOMAINS_{{domain.domain | camelcase_to_hacker_style |
upper}}_H_ | 102 #endif // HEADLESS_PUBLIC_DOMAINS_{{domain.domain | camelcase_to_hacker_style |
upper}}_H_ |
| OLD | NEW |