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

Unified Diff: headless/lib/browser/devtools_api/domain_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 side-by-side diff with in-line comments
Download patch
Index: headless/lib/browser/devtools_api/domain_types_h.template
diff --git a/headless/lib/browser/types_h.template b/headless/lib/browser/devtools_api/domain_types_h.template
similarity index 65%
rename from headless/lib/browser/types_h.template
rename to headless/lib/browser/devtools_api/domain_types_h.template
index 84b09cbeb24b17bafd7c81cfa95b7c1b6202d82f..f53f8ae1a529a3dbe3d02dbeecc5817fec56c5ce 100644
--- a/headless/lib/browser/types_h.template
+++ b/headless/lib/browser/devtools_api/domain_types_h.template
@@ -4,11 +4,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef HEADLESS_PUBLIC_DOMAINS_TYPES_H_
-#define HEADLESS_PUBLIC_DOMAINS_TYPES_H_
+#ifndef HEADLESS_PUBLIC_DEVTOOLS_DOMAINS_TYPES_{{domain.domain | camelcase_to_hacker_style | upper}}_H_
+#define HEADLESS_PUBLIC_DEVTOOLS_DOMAINS_TYPES_{{domain.domain | camelcase_to_hacker_style | upper}}_H_
#include "base/optional.h"
#include "base/values.h"
+{% for domain_name in domain.dependencies %}
+#include "headless/public/devtools/internal/types_forward_declaration_{{domain_name | camelcase_to_hacker_style}}.h"
+{% endfor %}
#include "headless/public/headless_export.h"
#include "headless/public/util/error_reporter.h"
@@ -16,67 +19,31 @@
namespace headless {
-// ------------- Forward declarations and typedefs.
-
-{% for domain in api.domains %}
-
-namespace {{domain.domain | camelcase_to_hacker_style}} {
- {% for type in domain.types %}
- {% if type.type == "object" %}
- {% if "properties" in type %}
-class {{type.id}};
- {% else %}
-using {{type.id}} = base::Value;
- {% endif %}
- {% endif %}
- {% endfor %}
-} // namespace {{domain.domain}}
-{% endfor %}
-
-{% for domain in api.domains %}
namespace {{domain.domain | camelcase_to_hacker_style}} {
- {% for type in domain.types %}
- {% if "enum" in type %}
-enum class {{type.id}} {
- {% for literal in type.enum %}
- {{ literal | sanitize_literal | dash_to_camelcase | camelcase_to_hacker_style | upper }}{{',' if not loop.last}}
- {% endfor %}
-};
-
- {% endif %}
- {% endfor %}
-} // namespace {{domain.domain | camelcase_to_hacker_style}}
-
-{% endfor %}
-
-// ------------- Type and builder declarations.
-{% for domain in api.domains %}
+{% for type in domain.types %}
+ {% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %}
-namespace {{domain.domain | camelcase_to_hacker_style}} {
- {% for type in domain.types %}
- {% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %}
-
- {% if type.description %}
+ {% if type.description %}
// {{type.description}}
- {% endif %}
+ {% endif %}
class HEADLESS_EXPORT {{type.id}} {
public:
static {{resolve_type(type).pass_type}} Parse(const base::Value& value, ErrorReporter* errors);
~{{type.id}}() { }
- {% for property in type.properties %}
+ {% for property in type.properties %}
- {% if property.description %}
+ {% if property.description %}
// {{property.description}}
- {% endif %}
- {% if property.optional %}
+ {% endif %}
+ {% if property.optional %}
bool Has{{property.name | to_title_case}}() const { return !!{{property.name | camelcase_to_hacker_style}}_; }
{{resolve_type(property).raw_return_type}} Get{{property.name | to_title_case}}() const { DCHECK(Has{{property.name | to_title_case}}()); return {{resolve_type(property).to_raw_return_type % ("%s_.value()" % property.name | camelcase_to_hacker_style)}}; }
void Set{{property.name | to_title_case}}({{resolve_type(property).pass_type}} value) { {{property.name | camelcase_to_hacker_style}}_ = {{resolve_type(property).to_pass_type % 'value'}}; }
- {% else %}
+ {% else %}
{{resolve_type(property).raw_return_type}} Get{{property.name | to_title_case}}() const { return {{resolve_type(property).to_raw_return_type % ("%s_" % property.name | camelcase_to_hacker_style)}}; }
void Set{{property.name | to_title_case}}({{resolve_type(property).pass_type}} value) { {{property.name | camelcase_to_hacker_style}}_ = {{resolve_type(property).to_pass_type % 'value'}}; }
- {% endif %}
- {% endfor %}
+ {% endif %}
+ {% endfor %}
std::unique_ptr<base::Value> Serialize() const;
{{resolve_type(type).pass_type}} Clone() const;
@@ -86,34 +53,34 @@ class HEADLESS_EXPORT {{type.id}} {
public:
enum {
kNoFieldsSet = 0,
- {% set count = 0 %}
- {% for property in type.properties %}
- {% if not(property.optional) %}
- {% set count = count + 1 %}
+ {% set count = 0 %}
+ {% for property in type.properties %}
+ {% if not(property.optional) %}
+ {% set count = count + 1 %}
k{{property.name | to_title_case}}Set = 1 << {{count}},
- {% endif %}
- {% endfor %}
+ {% endif %}
+ {% endfor %}
kAllRequiredFieldsSet = (
- {%- for property in type.properties %}
- {% if not(property.optional) %}k{{property.name | to_title_case}}Set | {%endif %}
- {% endfor %}0)
+ {%- for property in type.properties %}
+ {% if not(property.optional) %}k{{property.name | to_title_case}}Set | {%endif %}
+ {% endfor %}0)
};
- {% for property in type.properties %}
- {% if property.optional %}
+ {% for property in type.properties %}
+ {% if property.optional %}
{{type.id}}Builder<STATE>& Set{{property.name | to_title_case}}({{resolve_type(property).pass_type}} value) {
result_->Set{{property.name | to_title_case}}({{resolve_type(property).to_pass_type % 'value'}});
return *this;
}
- {% else %}
+ {% else %}
{{type.id}}Builder<STATE | k{{property.name | to_title_case}}Set>& Set{{property.name | to_title_case}}({{resolve_type(property).pass_type}} value) {
static_assert(!(STATE & k{{property.name | to_title_case}}Set), "property {{property.name}} should not have already been set");
result_->Set{{property.name | to_title_case}}({{resolve_type(property).to_pass_type % 'value'}});
return CastState<k{{property.name | to_title_case}}Set>();
}
- {% endif %}
+ {% endif %}
- {% endfor %}
+ {% endfor %}
{{resolve_type(type).pass_type}} Build() {
static_assert(STATE == kAllRequiredFieldsSet, "all required fields should have been set");
return std::move(result_);
@@ -137,22 +104,21 @@ class HEADLESS_EXPORT {{type.id}} {
private:
{{type.id}}() { }
- {% for property in type.properties %}
- {% if property.optional %}
+ {% for property in type.properties %}
+ {% if property.optional %}
base::Optional<{{resolve_type(property).type}}> {{property.name | camelcase_to_hacker_style}}_;
- {% else %}
+ {% else %}
{{resolve_type(property).type}} {{property.name | camelcase_to_hacker_style}}_;
- {% endif %}
- {% endfor %}
+ {% endif %}
+ {% endfor %}
DISALLOW_COPY_AND_ASSIGN({{type.id}});
};
- {% endfor %}
+{% endfor %}
} // namespace {{domain.domain | camelcase_to_hacker_style}}
-{% endfor %}
} // namespace headless
-#endif // HEADLESS_PUBLIC_DOMAINS_TYPES_H_
+#endif // HEADLESS_PUBLIC_DEVTOOLS_DOMAINS_TYPES_{{domain.domain | camelcase_to_hacker_style | upper}}_H_
« no previous file with comments | « headless/lib/browser/devtools_api/domain_types_forward_declaration_h.template ('k') | headless/lib/browser/domain_cc.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698