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

Unified Diff: third_party/dom_distiller_js/protoc_plugins/json_values_converter.py

Issue 2911033002: Remove raw base::DictionaryValue::Set (Closed)
Patch Set: Proper Windows Fix Created 3 years, 6 months 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 | « skia/ext/benchmarking_canvas.cc ('k') | third_party/dom_distiller_js/test_sample_json_converter.h.golden » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/dom_distiller_js/protoc_plugins/json_values_converter.py
diff --git a/third_party/dom_distiller_js/protoc_plugins/json_values_converter.py b/third_party/dom_distiller_js/protoc_plugins/json_values_converter.py
index 6a39167c671f5d6e6b0d34b1543692ba38b701ca..ba9ad54ac18eacc5007b0b1a85857a24020c2198 100755
--- a/third_party/dom_distiller_js/protoc_plugins/json_values_converter.py
+++ b/third_party/dom_distiller_js/protoc_plugins/json_values_converter.py
@@ -32,6 +32,7 @@ class CppConverterWriter(writer.CodeWriter):
assert [] == proto_file.GetDependencies()
self.Output('// base dependencies')
+ self.Output('#include "base/memory/ptr_util.h"')
self.Output('#include "base/values.h"')
self.Output('')
self.Output('#include <memory>')
@@ -116,8 +117,7 @@ class CppConverterWriter(writer.CodeWriter):
def RepeatedMemberFieldWriteToValue(self, field):
prologue = (
- 'base::ListValue* field_list = new base::ListValue();\n'
- 'dict->Set("{field_number}", field_list);\n'
+ 'auto field_list = base::MakeUnique<base::ListValue>();\n'
'for (int i = 0; i < message.{field_name}_size(); ++i) {{\n'
)
@@ -131,8 +131,13 @@ class CppConverterWriter(writer.CodeWriter):
middle = (
'field_list->Append{value_type}(message.{field_name}(i));\n'
)
+
+ epilogue = (
+ '\n}}\n'
+ 'dict->Set("{field_number}", std::move(field_list));'
+ )
self.Output(
- prologue + Indented(middle) + '\n}}',
+ prologue + Indented(middle) + epilogue,
field_number=field.JavascriptIndex(),
field_name=field.name,
value_type=field.CppValueType() if not field.IsClassType() else None,
« no previous file with comments | « skia/ext/benchmarking_canvas.cc ('k') | third_party/dom_distiller_js/test_sample_json_converter.h.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698