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

Unified Diff: headless/lib/browser/devtools_api/domain_type_conversions_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_type_conversions_h.template
diff --git a/headless/lib/browser/type_conversions_h.template b/headless/lib/browser/devtools_api/domain_type_conversions_h.template
similarity index 64%
rename from headless/lib/browser/type_conversions_h.template
rename to headless/lib/browser/devtools_api/domain_type_conversions_h.template
index 1c918ac9ea3f138223957684314682c830ada722..f14b423a66a397733d4f6d81b9b0377817a77d1d 100644
--- a/headless/lib/browser/type_conversions_h.template
+++ b/headless/lib/browser/devtools_api/domain_type_conversions_h.template
@@ -4,33 +4,32 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef HEADLESS_PUBLIC_DOMAINS_TYPE_CONVERSIONS_H_
-#define HEADLESS_PUBLIC_DOMAINS_TYPE_CONVERSIONS_H_
+#ifndef HEADLESS_PUBLIC_DEVTOOLS_INTERNAL_TYPE_CONVERSIONS_{{domain.domain | camelcase_to_hacker_style | upper}}_H_
+#define HEADLESS_PUBLIC_DEVTOOLS_INTERNAL_TYPE_CONVERSIONS_{{domain.domain | camelcase_to_hacker_style | upper}}_H_
-#include "headless/public/domains/types.h"
+#include "headless/public/devtools/domains/types_{{domain.domain | camelcase_to_hacker_style}}.h"
#include "headless/public/internal/value_conversions.h"
namespace headless {
namespace internal {
-{% for domain in api.domains %}
- {% for type in domain.types %}
- {% set namespace = domain.domain | camelcase_to_hacker_style %}
- {% if "enum" in type %}
+{% for type in domain.types %}
+ {% set namespace = domain.domain | camelcase_to_hacker_style %}
+ {% if "enum" in type %}
template <>
struct FromValue<{{namespace}}::{{type.id}}> {
static {{namespace}}::{{type.id}} Parse(const base::Value& value, ErrorReporter* errors) {
- {% set default = namespace + '::' + type.id + '::' + type.enum[0] | sanitize_literal | dash_to_camelcase | camelcase_to_hacker_style | upper %}
+ {% set default = namespace + '::' + type.id + '::' + type.enum[0] | sanitize_literal | dash_to_camelcase | camelcase_to_hacker_style | upper %}
std::string string_value;
if (!value.GetAsString(&string_value)) {
errors->AddError("string enum value expected");
{# Return an arbitrary enum member -- the caller will just ignore it. #}
return {{default}};
}
- {% for literal in type.enum %}
+ {% for literal in type.enum %}
if (string_value == "{{literal}}")
return {{namespace}}::{{type.id}}::{{literal | sanitize_literal | dash_to_camelcase | camelcase_to_hacker_style | upper }};
- {% endfor %}
+ {% endfor %}
errors->AddError("invalid enum value");
return {{default}};
}
@@ -39,18 +38,18 @@ struct FromValue<{{namespace}}::{{type.id}}> {
template <typename T>
std::unique_ptr<base::Value> ToValueImpl(const {{namespace}}::{{type.id}}& value, T*) {
switch (value) {
- {% for literal in type.enum %}
+ {% for literal in type.enum %}
case {{namespace}}::{{type.id}}::{{literal | sanitize_literal | dash_to_camelcase | camelcase_to_hacker_style | upper }}:
return base::WrapUnique(new base::StringValue("{{literal}}"));
- {% endfor %}
+ {% endfor %}
};
NOTREACHED();
return nullptr;
}
- {% continue %}
- {% endif %}
+ {% continue %}
+ {% endif %}
- {% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %}
+ {% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %}
template <>
struct FromValue<{{namespace}}::{{type.id}}> {
static std::unique_ptr<{{namespace}}::{{type.id}}> Parse(const base::Value& value, ErrorReporter* errors) {
@@ -63,15 +62,9 @@ std::unique_ptr<base::Value> ToValueImpl(const {{namespace}}::{{type.id}}& value
return value.Serialize();
}
- {% endfor %}
{% endfor %}
-template <typename T>
-std::unique_ptr<base::Value> ToValue(const T& value) {
- return ToValueImpl(value, static_cast<T*>(nullptr));
-}
-
} // namespace internal
} // namespace headless
-#endif // HEADLESS_PUBLIC_DOMAINS_TYPE_CONVERSIONS_H_
+#endif // HEADLESS_PUBLIC_DEVTOOLS_INTERNAL_TYPE_CONVERSIONS_{{domain.domain | camelcase_to_hacker_style | upper}}_H_
« no previous file with comments | « headless/lib/browser/devtools_api/domain_h.template ('k') | headless/lib/browser/devtools_api/domain_types_cc.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698