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

Unified Diff: headless/lib/browser/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
« no previous file with comments | « headless/lib/browser/type_conversions_h.template ('k') | headless/lib/browser/types_h.template » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: headless/lib/browser/types_cc.template
diff --git a/headless/lib/browser/types_cc.template b/headless/lib/browser/types_cc.template
deleted file mode 100644
index 5be72cf79240a5f5be27e902a802b040a4ada3ff..0000000000000000000000000000000000000000
--- a/headless/lib/browser/types_cc.template
+++ /dev/null
@@ -1,130 +0,0 @@
-// This file is generated
-
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// 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"
-
-#include "base/memory/ptr_util.h"
-#include "headless/public/domains/type_conversions.h"
-
-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();
-}
-
- {% 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 %}
-
-std::unique_ptr<{{type.id}}> {{type.id}}::Parse(const base::Value& value, ErrorReporter* errors) {
- errors->Push();
- errors->SetName("{{type.id}}");
- const base::DictionaryValue* object;
- if (!value.GetAsDictionary(&object)) {
- errors->AddError("object expected");
- errors->Pop();
- return nullptr;
- }
-
- 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" %}
- const base::Value* {{value_name}};
- if (object->Get("{{property.name}}", &{{value_name}})) {
- errors->SetName("{{property.name}}");
- {% if property.optional %}
- result->{{property.name | camelcase_to_hacker_style}}_ = internal::FromValue<{{resolve_type(property).raw_type}}>::Parse(*{{value_name}}, errors);
- {% else %}
- result->{{property.name | camelcase_to_hacker_style}}_ = internal::FromValue<{{resolve_type(property).raw_type}}>::Parse(*{{value_name}}, errors);
- {% endif %}
- {% if property.optional %}
- }
- {% else %}
- } else {
- errors->AddError("required property missing: {{property.name}}");
- }
- {% endif %}
- {% endfor %}
- errors->Pop();
- errors->Pop();
- if (errors->HasErrors())
- return nullptr;
- return result;
-}
-
-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 %}
- 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 %}
- result->Set("{{property.name}}", internal::ToValue({{type.to_raw_type % ("%s_" % property.name | camelcase_to_hacker_style)}}));
- {% endif %}
- {% endfor %}
- return std::move(result);
-}
-
-std::unique_ptr<{{type.id}}> {{type.id}}::Clone() const {
- ErrorReporter errors;
- std::unique_ptr<{{type.id}}> result = Parse(*Serialize(), &errors);
- DCHECK(!errors.HasErrors());
- return result;
-}
-
- {% endfor %}
-} // namespace {{domain.domain | camelcase_to_hacker_style}}
-{% endfor %}
-
-} // namespace headless
« no previous file with comments | « headless/lib/browser/type_conversions_h.template ('k') | headless/lib/browser/types_h.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698