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

Unified Diff: headless/lib/browser/devtools_api/domain_types_cc.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_cc.template
diff --git a/headless/lib/browser/types_cc.template b/headless/lib/browser/devtools_api/domain_types_cc.template
similarity index 53%
rename from headless/lib/browser/types_cc.template
rename to headless/lib/browser/devtools_api/domain_types_cc.template
index 5be72cf79240a5f5be27e902a802b040a4ada3ff..bd1c2773dd4eb80b92c766826cb471fac4833ae8 100644
--- a/headless/lib/browser/types_cc.template
+++ b/headless/lib/browser/devtools_api/domain_types_cc.template
@@ -4,65 +4,29 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "headless/public/domains/types.h"
+{% for domain_name in domain.dependencies %}
+#include "headless/public/devtools/domains/types_{{domain_name | camelcase_to_hacker_style}}.h"
+{% endfor %}
#include "base/memory/ptr_util.h"
-#include "headless/public/domains/type_conversions.h"
+{% for dep in domain.dependencies %}
+#include "headless/public/devtools/internal/type_conversions_{{dep | camelcase_to_hacker_style}}.h"
+{% endfor %}
namespace headless {
-// ------------- Enum values from types.
-{% for domain in api.domains %}
- {% continue %}
-
namespace internal {
- {% for type in domain.types %}
-// {{type}}
- {% if type.type == "array" %}
-template <>
-struct FromValue<{{resolve_type(type).raw_type}}> {
- static {{resolve_type(type).raw_type}} Parse(const base::Value& value, ErrorReporter* errors) {
- {{resolve_type(type).raw_type}} result;
- const base::ListValue* list;
- if (!value.GetAsList(&list)) {
- errors->AddError("list value expected");
- return result;
- }
- errors->Push();
- for (const auto& item : *list)
- result.push_back(FromValue<{{resolve_type(type).raw_type}}::value_type>::Parse(*item, errors));
- errors->Pop();
- return result;
- }
-};
-
- {% continue %}
- {% endif %}
-#}
- {% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %}
- {% set namespace = domain.domain | camelcase_to_hacker_style %}
-template <>
-struct FromValue<{{namespace}}::{{type.id}}> {
- static std::unique_ptr<{{namespace}}::{{type.id}}> Parse(const base::Value& value, ErrorReporter* errors) {
- return {{namespace}}::{{type.id}}::Parse(value, errors);
- }
-};
-
template <typename T>
-std::unique_ptr<base::Value> ToValueImpl(const {{namespace}}::{{type.id}}& value, T*) {
- return value.Serialize();
+std::unique_ptr<base::Value> ToValue(const T& value) {
+ return ToValueImpl(value, static_cast<T*>(nullptr));
}
- {% endfor %}
} // namespace internal
-{% endfor %}
-
-{% for domain in api.domains %}
namespace {{domain.domain | camelcase_to_hacker_style}} {
- {% for type in domain.types %}
- {% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %}
+{% for type in domain.types %}
+ {% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %}
std::unique_ptr<{{type.id}}> {{type.id}}::Parse(const base::Value& value, ErrorReporter* errors) {
errors->Push();
@@ -77,24 +41,24 @@ std::unique_ptr<{{type.id}}> {{type.id}}::Parse(const base::Value& value, ErrorR
std::unique_ptr<{{type.id}}> result(new {{type.id}}());
errors->Push();
errors->SetName("{{type.id}}");
- {% for property in type.properties %}
- {% set value_name = property.name | camelcase_to_hacker_style + "_value" %}
+ {% for property in type.properties %}
+ {% set value_name = property.name | camelcase_to_hacker_style + "_value" %}
const base::Value* {{value_name}};
if (object->Get("{{property.name}}", &{{value_name}})) {
errors->SetName("{{property.name}}");
- {% if property.optional %}
+ {% if property.optional %}
result->{{property.name | camelcase_to_hacker_style}}_ = internal::FromValue<{{resolve_type(property).raw_type}}>::Parse(*{{value_name}}, errors);
- {% else %}
+ {% else %}
result->{{property.name | camelcase_to_hacker_style}}_ = internal::FromValue<{{resolve_type(property).raw_type}}>::Parse(*{{value_name}}, errors);
- {% endif %}
- {% if property.optional %}
+ {% endif %}
+ {% if property.optional %}
}
- {% else %}
+ {% else %}
} else {
errors->AddError("required property missing: {{property.name}}");
}
- {% endif %}
- {% endfor %}
+ {% endif %}
+ {% endfor %}
errors->Pop();
errors->Pop();
if (errors->HasErrors())
@@ -104,15 +68,15 @@ std::unique_ptr<{{type.id}}> {{type.id}}::Parse(const base::Value& value, ErrorR
std::unique_ptr<base::Value> {{type.id}}::Serialize() const {
std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
- {% for property in type.properties %}
- {% set type = resolve_type(property) %}
- {% if property.optional %}
+ {% for property in type.properties %}
+ {% set type = resolve_type(property) %}
+ {% if property.optional %}
if ({{property.name | camelcase_to_hacker_style}}_)
result->Set("{{property.name}}", internal::ToValue({{type.to_raw_type % ("%s_.value()" % property.name | camelcase_to_hacker_style)}}));
- {% else %}
+ {% else %}
result->Set("{{property.name}}", internal::ToValue({{type.to_raw_type % ("%s_" % property.name | camelcase_to_hacker_style)}}));
- {% endif %}
- {% endfor %}
+ {% endif %}
+ {% endfor %}
return std::move(result);
}
@@ -123,8 +87,7 @@ std::unique_ptr<{{type.id}}> {{type.id}}::Clone() const {
return result;
}
- {% endfor %}
-} // namespace {{domain.domain | camelcase_to_hacker_style}}
{% endfor %}
-} // namespace headless
+} // namespace {{domain.domain | camelcase_to_hacker_style}}
+} // namespace headless

Powered by Google App Engine
This is Rietveld 408576698