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

Side by Side Diff: headless/lib/browser/types_h.template

Issue 2473073003: [headless] Refactor headless devtools client API. (Closed)
Patch Set: Address nits Created 4 years, 1 month 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
« no previous file with comments | « headless/lib/browser/types_cc.template ('k') | headless/lib/embedder_mojo_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // This file is generated
2
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
5 // found in the LICENSE file.
6
7 #ifndef HEADLESS_PUBLIC_DOMAINS_TYPES_H_
8 #define HEADLESS_PUBLIC_DOMAINS_TYPES_H_
9
10 #include "base/optional.h"
11 #include "base/values.h"
12 #include "headless/public/headless_export.h"
13 #include "headless/public/util/error_reporter.h"
14
15 #include "base/memory/ptr_util.h"
16
17 namespace headless {
18
19 // ------------- Forward declarations and typedefs.
20
21 {% for domain in api.domains %}
22
23 namespace {{domain.domain | camelcase_to_hacker_style}} {
24 {% for type in domain.types %}
25 {% if type.type == "object" %}
26 {% if "properties" in type %}
27 class {{type.id}};
28 {% else %}
29 using {{type.id}} = base::Value;
30 {% endif %}
31 {% endif %}
32 {% endfor %}
33 } // namespace {{domain.domain}}
34 {% endfor %}
35
36 {% for domain in api.domains %}
37 namespace {{domain.domain | camelcase_to_hacker_style}} {
38 {% for type in domain.types %}
39 {% if "enum" in type %}
40 enum class {{type.id}} {
41 {% for literal in type.enum %}
42 {{ literal | sanitize_literal | dash_to_camelcase | camelcase_to_hacker_style | upper }}{{',' if not loop.last}}
43 {% endfor %}
44 };
45
46 {% endif %}
47 {% endfor %}
48 } // namespace {{domain.domain | camelcase_to_hacker_style}}
49
50 {% endfor %}
51
52 // ------------- Type and builder declarations.
53 {% for domain in api.domains %}
54
55 namespace {{domain.domain | camelcase_to_hacker_style}} {
56 {% for type in domain.types %}
57 {% if not (type.type == "object") or not ("properties" in type) %}{% continu e %}{% endif %}
58
59 {% if type.description %}
60 // {{type.description}}
61 {% endif %}
62 class HEADLESS_EXPORT {{type.id}} {
63 public:
64 static {{resolve_type(type).pass_type}} Parse(const base::Value& value, ErrorR eporter* errors);
65 ~{{type.id}}() { }
66 {% for property in type.properties %}
67
68 {% if property.description %}
69 // {{property.description}}
70 {% endif %}
71 {% if property.optional %}
72 bool Has{{property.name | to_title_case}}() const { return !!{{property.name | camelcase_to_hacker_style}}_; }
73 {{resolve_type(property).raw_return_type}} Get{{property.name | to_title_case} }() const { DCHECK(Has{{property.name | to_title_case}}()); return {{resolve_typ e(property).to_raw_return_type % ("%s_.value()" % property.name | camelcase_to_h acker_style)}}; }
74 void Set{{property.name | to_title_case}}({{resolve_type(property).pass_type}} value) { {{property.name | camelcase_to_hacker_style}}_ = {{resolve_type(proper ty).to_pass_type % 'value'}}; }
75 {% else %}
76 {{resolve_type(property).raw_return_type}} Get{{property.name | to_title_case} }() const { return {{resolve_type(property).to_raw_return_type % ("%s_" % proper ty.name | camelcase_to_hacker_style)}}; }
77 void Set{{property.name | to_title_case}}({{resolve_type(property).pass_type}} value) { {{property.name | camelcase_to_hacker_style}}_ = {{resolve_type(proper ty).to_pass_type % 'value'}}; }
78 {% endif %}
79 {% endfor %}
80
81 std::unique_ptr<base::Value> Serialize() const;
82 {{resolve_type(type).pass_type}} Clone() const;
83
84 template<int STATE>
85 class {{type.id}}Builder {
86 public:
87 enum {
88 kNoFieldsSet = 0,
89 {% set count = 0 %}
90 {% for property in type.properties %}
91 {% if not(property.optional) %}
92 {% set count = count + 1 %}
93 k{{property.name | to_title_case}}Set = 1 << {{count}},
94 {% endif %}
95 {% endfor %}
96 kAllRequiredFieldsSet = (
97 {%- for property in type.properties %}
98 {% if not(property.optional) %}k{{property.name | to_title_case}}Set | {%e ndif %}
99 {% endfor %}0)
100 };
101
102 {% for property in type.properties %}
103 {% if property.optional %}
104 {{type.id}}Builder<STATE>& Set{{property.name | to_title_case}}({{resolve_ty pe(property).pass_type}} value) {
105 result_->Set{{property.name | to_title_case}}({{resolve_type(property).to_ pass_type % 'value'}});
106 return *this;
107 }
108 {% else %}
109 {{type.id}}Builder<STATE | k{{property.name | to_title_case}}Set>& Set{{prop erty.name | to_title_case}}({{resolve_type(property).pass_type}} value) {
110 static_assert(!(STATE & k{{property.name | to_title_case}}Set), "property {{property.name}} should not have already been set");
111 result_->Set{{property.name | to_title_case}}({{resolve_type(property).to_ pass_type % 'value'}});
112 return CastState<k{{property.name | to_title_case}}Set>();
113 }
114 {% endif %}
115
116 {% endfor %}
117 {{resolve_type(type).pass_type}} Build() {
118 static_assert(STATE == kAllRequiredFieldsSet, "all required fields should have been set");
119 return std::move(result_);
120 }
121
122 private:
123 friend class {{type.id}};
124 {{type.id}}Builder() : result_(new {{type.id}}()) { }
125
126 template<int STEP> {{type.id}}Builder<STATE | STEP>& CastState() {
127 return *reinterpret_cast<{{type.id}}Builder<STATE | STEP>*>(this);
128 }
129
130 {{resolve_type(type).type}} result_;
131 };
132
133 static {{type.id}}Builder<0> Builder() {
134 return {{type.id}}Builder<0>();
135 }
136
137 private:
138 {{type.id}}() { }
139
140 {% for property in type.properties %}
141 {% if property.optional %}
142 base::Optional<{{resolve_type(property).type}}> {{property.name | camelcase_to _hacker_style}}_;
143 {% else %}
144 {{resolve_type(property).type}} {{property.name | camelcase_to_hacker_style}}_ ;
145 {% endif %}
146 {% endfor %}
147
148 DISALLOW_COPY_AND_ASSIGN({{type.id}});
149 };
150
151 {% endfor %}
152
153 } // namespace {{domain.domain | camelcase_to_hacker_style}}
154 {% endfor %}
155
156 } // namespace headless
157
158 #endif // HEADLESS_PUBLIC_DOMAINS_TYPES_H_
OLDNEW
« no previous file with comments | « headless/lib/browser/types_cc.template ('k') | headless/lib/embedder_mojo_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698