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

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: Undo values.h change. 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..81f897c16d5a6eff5c366981156c46d05b09d573 100644
--- a/tools/json_schema_compiler/cc_generator.py
+++ b/tools/json_schema_compiler/cc_generator.py
@@ -344,7 +344,12 @@ 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:
+ vardot = var + '->'
+ else:
+ vardot = var + '.'
+ return ('base::BinaryValue::CreateWithCopiedBuffer(%sdata(), %ssize())' %
+ (vardot, vardot))
elif self._IsArrayOrArrayRef(prop):
return '%s.release()' % self._util_cc_helper.CreateValueFromArray(
self._cpp_type_generator.GetReferencedProperty(prop), var,
@@ -531,15 +536,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('}')
« no previous file with comments | « chrome/browser/extensions/api/usb/usb_device_resource.cc ('k') | tools/json_schema_compiler/cpp_type_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698