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 "chrome/browser/extensions/api/bluetooth_low_energy/utils.h" | 5 #include "chrome/browser/extensions/api/bluetooth_low_energy/utils.h" |
6 | 6 |
7 namespace extensions { | 7 namespace extensions { |
8 namespace api { | 8 namespace api { |
9 namespace bluetooth_low_energy { | 9 namespace bluetooth_low_energy { |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 // Converts a list of CharacteristicProperty to a base::ListValue of strings. | 13 // Converts a list of CharacteristicProperty to a base::ListValue of strings. |
14 scoped_ptr<base::ListValue> CharacteristicPropertiesToValue( | 14 std::unique_ptr<base::ListValue> CharacteristicPropertiesToValue( |
15 const std::vector<CharacteristicProperty> properties) { | 15 const std::vector<CharacteristicProperty> properties) { |
16 scoped_ptr<base::ListValue> property_list(new base::ListValue()); | 16 std::unique_ptr<base::ListValue> property_list(new base::ListValue()); |
17 for (std::vector<CharacteristicProperty>::const_iterator iter = | 17 for (std::vector<CharacteristicProperty>::const_iterator iter = |
18 properties.begin(); | 18 properties.begin(); |
19 iter != properties.end(); | 19 iter != properties.end(); |
20 ++iter) | 20 ++iter) |
21 property_list->Append(new base::StringValue(ToString(*iter))); | 21 property_list->Append(new base::StringValue(ToString(*iter))); |
22 return property_list; | 22 return property_list; |
23 } | 23 } |
24 | 24 |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 scoped_ptr<base::DictionaryValue> CharacteristicToValue(Characteristic* from) { | 27 std::unique_ptr<base::DictionaryValue> CharacteristicToValue( |
| 28 Characteristic* from) { |
28 // Copy the properties. Use Characteristic::ToValue to generate the result | 29 // Copy the properties. Use Characteristic::ToValue to generate the result |
29 // dictionary without the properties, to prevent json_schema_compiler from | 30 // dictionary without the properties, to prevent json_schema_compiler from |
30 // failing. | 31 // failing. |
31 std::vector<CharacteristicProperty> properties = from->properties; | 32 std::vector<CharacteristicProperty> properties = from->properties; |
32 from->properties.clear(); | 33 from->properties.clear(); |
33 scoped_ptr<base::DictionaryValue> to = from->ToValue(); | 34 std::unique_ptr<base::DictionaryValue> to = from->ToValue(); |
34 to->SetWithoutPathExpansion( | 35 to->SetWithoutPathExpansion( |
35 "properties", CharacteristicPropertiesToValue(properties).release()); | 36 "properties", CharacteristicPropertiesToValue(properties).release()); |
36 return to; | 37 return to; |
37 } | 38 } |
38 | 39 |
39 scoped_ptr<base::DictionaryValue> DescriptorToValue(Descriptor* from) { | 40 std::unique_ptr<base::DictionaryValue> DescriptorToValue(Descriptor* from) { |
40 // Copy the characteristic properties and set them later manually. | 41 // Copy the characteristic properties and set them later manually. |
41 std::vector<CharacteristicProperty> properties = | 42 std::vector<CharacteristicProperty> properties = |
42 from->characteristic.properties; | 43 from->characteristic.properties; |
43 from->characteristic.properties.clear(); | 44 from->characteristic.properties.clear(); |
44 scoped_ptr<base::DictionaryValue> to = from->ToValue(); | 45 std::unique_ptr<base::DictionaryValue> to = from->ToValue(); |
45 | 46 |
46 base::DictionaryValue* chrc_value = NULL; | 47 base::DictionaryValue* chrc_value = NULL; |
47 to->GetDictionaryWithoutPathExpansion("characteristic", &chrc_value); | 48 to->GetDictionaryWithoutPathExpansion("characteristic", &chrc_value); |
48 DCHECK(chrc_value); | 49 DCHECK(chrc_value); |
49 chrc_value->SetWithoutPathExpansion( | 50 chrc_value->SetWithoutPathExpansion( |
50 "properties", CharacteristicPropertiesToValue(properties).release()); | 51 "properties", CharacteristicPropertiesToValue(properties).release()); |
51 return to; | 52 return to; |
52 } | 53 } |
53 | 54 |
54 } // namespace bluetooth_low_energy | 55 } // namespace bluetooth_low_energy |
55 } // namespace api | 56 } // namespace api |
56 } // namespace extensions | 57 } // namespace extensions |
OLD | NEW |