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

Unified Diff: tools/json_schema_compiler/cc_generator.py

Issue 10700194: Represent BINARY properties using std::string instead of BinaryValue, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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
Index: tools/json_schema_compiler/cc_generator.py
diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py
index 99e0eb3c16a324c6827499bef7f026cb3b3d8748..5777c554c54171f6767043a00d536c66bdd6cf16 100644
--- a/tools/json_schema_compiler/cc_generator.py
+++ b/tools/json_schema_compiler/cc_generator.py
@@ -344,7 +344,10 @@ class CCGenerator(object):
elif prop.type_ == PropertyType.ENUM:
return 'CreateEnumValue(%s).release()' % var
elif prop.type_ == PropertyType.BINARY:
- return '%s->DeepCopy()' % var
+ if prop.optional:
+ return 'base::BinaryValue::CreateWithCopiedBuffer(*%s)' % var
+ else:
+ return 'base::BinaryValue::CreateWithCopiedBuffer(%s)' % var
elif self._IsArrayOrArrayRef(prop):
return '%s.release()' % self._util_cc_helper.CreateValueFromArray(
self._cpp_type_generator.GetReferencedProperty(prop), var,
@@ -531,15 +534,20 @@ class CCGenerator(object):
c.Append('%(dst)s->%(name)s = enum_temp;')
c.Eblock('}')
elif prop.type_ == PropertyType.BINARY:
- # This is the same if the property is optional or not. We need a pointer
- # to the base::BinaryValue to be able to populate it, so a scoped_ptr is
- # used whether it is optional or required.
(c.Append('if (!%(value_var)s->IsType(%(value_type)s))')
.Append(' return %(failure_value)s;')
- .Append('%(dst)s->%(name)s.reset(')
- .Append(' static_cast<base::BinaryValue*>(%(value_var)s)'
- '->DeepCopy());')
- )
+ .Append('base::BinaryValue* binary_value =')
+ .Append(' static_cast<base::BinaryValue*>(%(value_var)s);')
+ )
+ if prop.optional:
+ (c.Append('%(dst)s->%(name)s.reset(')
+ .Append(' new std::string(binary_value->GetBuffer(),')
+ .Append(' binary_value->GetSize()));')
+ )
+ else:
+ (c.Append('%(dst)s->%(name)s.assign(binary_value->GetBuffer(),')
+ .Append(' binary_value->GetSize());')
+ )
else:
raise NotImplementedError(prop.type_)
c.Eblock('}')

Powered by Google App Engine
This is Rietveld 408576698