| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/browser/api/bluetooth_low_energy/utils.h" | 5 #include "extensions/browser/api/bluetooth_low_energy/utils.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 std::unique_ptr<base::DictionaryValue> CharacteristicToValue( | 32 std::unique_ptr<base::DictionaryValue> CharacteristicToValue( |
| 33 Characteristic* from) { | 33 Characteristic* from) { |
| 34 // Copy the properties. Use Characteristic::ToValue to generate the result | 34 // Copy the properties. Use Characteristic::ToValue to generate the result |
| 35 // dictionary without the properties, to prevent json_schema_compiler from | 35 // dictionary without the properties, to prevent json_schema_compiler from |
| 36 // failing. | 36 // failing. |
| 37 std::vector<CharacteristicProperty> properties = from->properties; | 37 std::vector<CharacteristicProperty> properties = from->properties; |
| 38 from->properties.clear(); | 38 from->properties.clear(); |
| 39 std::unique_ptr<base::DictionaryValue> to = from->ToValue(); | 39 std::unique_ptr<base::DictionaryValue> to = from->ToValue(); |
| 40 to->SetWithoutPathExpansion( | 40 to->SetWithoutPathExpansion("properties", |
| 41 "properties", CharacteristicPropertiesToValue(properties).release()); | 41 CharacteristicPropertiesToValue(properties)); |
| 42 return to; | 42 return to; |
| 43 } | 43 } |
| 44 | 44 |
| 45 std::unique_ptr<base::DictionaryValue> DescriptorToValue(Descriptor* from) { | 45 std::unique_ptr<base::DictionaryValue> DescriptorToValue(Descriptor* from) { |
| 46 if (!from->characteristic) | 46 if (!from->characteristic) |
| 47 return from->ToValue(); | 47 return from->ToValue(); |
| 48 | 48 |
| 49 // Copy the characteristic properties and set them later manually. | 49 // Copy the characteristic properties and set them later manually. |
| 50 std::vector<CharacteristicProperty> properties = | 50 std::vector<CharacteristicProperty> properties = |
| 51 from->characteristic->properties; | 51 from->characteristic->properties; |
| 52 from->characteristic->properties.clear(); | 52 from->characteristic->properties.clear(); |
| 53 std::unique_ptr<base::DictionaryValue> to = from->ToValue(); | 53 std::unique_ptr<base::DictionaryValue> to = from->ToValue(); |
| 54 | 54 |
| 55 base::DictionaryValue* chrc_value = NULL; | 55 base::DictionaryValue* chrc_value = NULL; |
| 56 to->GetDictionaryWithoutPathExpansion("characteristic", &chrc_value); | 56 to->GetDictionaryWithoutPathExpansion("characteristic", &chrc_value); |
| 57 DCHECK(chrc_value); | 57 DCHECK(chrc_value); |
| 58 chrc_value->SetWithoutPathExpansion( | 58 chrc_value->SetWithoutPathExpansion( |
| 59 "properties", CharacteristicPropertiesToValue(properties).release()); | 59 "properties", CharacteristicPropertiesToValue(properties)); |
| 60 return to; | 60 return to; |
| 61 } | 61 } |
| 62 | 62 |
| 63 } // namespace bluetooth_low_energy | 63 } // namespace bluetooth_low_energy |
| 64 } // namespace api | 64 } // namespace api |
| 65 } // namespace extensions | 65 } // namespace extensions |
| OLD | NEW |