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 #include <stddef.h> |
| 8 #include <iterator> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/logging.h" |
| 12 |
7 namespace extensions { | 13 namespace extensions { |
8 namespace api { | 14 namespace api { |
9 namespace bluetooth_low_energy { | 15 namespace bluetooth_low_energy { |
10 | 16 |
11 namespace { | 17 namespace { |
12 | 18 |
13 // Converts a list of CharacteristicProperty to a base::ListValue of strings. | 19 // Converts a list of CharacteristicProperty to a base::ListValue of strings. |
14 std::unique_ptr<base::ListValue> CharacteristicPropertiesToValue( | 20 std::unique_ptr<base::ListValue> CharacteristicPropertiesToValue( |
15 const std::vector<CharacteristicProperty> properties) { | 21 const std::vector<CharacteristicProperty> properties) { |
16 std::unique_ptr<base::ListValue> property_list(new base::ListValue()); | 22 std::unique_ptr<base::ListValue> property_list(new base::ListValue()); |
(...skipping 14 matching lines...) Expand all Loading... |
31 // failing. | 37 // failing. |
32 std::vector<CharacteristicProperty> properties = from->properties; | 38 std::vector<CharacteristicProperty> properties = from->properties; |
33 from->properties.clear(); | 39 from->properties.clear(); |
34 std::unique_ptr<base::DictionaryValue> to = from->ToValue(); | 40 std::unique_ptr<base::DictionaryValue> to = from->ToValue(); |
35 to->SetWithoutPathExpansion( | 41 to->SetWithoutPathExpansion( |
36 "properties", CharacteristicPropertiesToValue(properties).release()); | 42 "properties", CharacteristicPropertiesToValue(properties).release()); |
37 return to; | 43 return to; |
38 } | 44 } |
39 | 45 |
40 std::unique_ptr<base::DictionaryValue> DescriptorToValue(Descriptor* from) { | 46 std::unique_ptr<base::DictionaryValue> DescriptorToValue(Descriptor* from) { |
| 47 if (!from->characteristic) |
| 48 return from->ToValue(); |
| 49 |
41 // Copy the characteristic properties and set them later manually. | 50 // Copy the characteristic properties and set them later manually. |
42 std::vector<CharacteristicProperty> properties = | 51 std::vector<CharacteristicProperty> properties = |
43 from->characteristic.properties; | 52 from->characteristic->properties; |
44 from->characteristic.properties.clear(); | 53 from->characteristic->properties.clear(); |
45 std::unique_ptr<base::DictionaryValue> to = from->ToValue(); | 54 std::unique_ptr<base::DictionaryValue> to = from->ToValue(); |
46 | 55 |
47 base::DictionaryValue* chrc_value = NULL; | 56 base::DictionaryValue* chrc_value = NULL; |
48 to->GetDictionaryWithoutPathExpansion("characteristic", &chrc_value); | 57 to->GetDictionaryWithoutPathExpansion("characteristic", &chrc_value); |
49 DCHECK(chrc_value); | 58 DCHECK(chrc_value); |
50 chrc_value->SetWithoutPathExpansion( | 59 chrc_value->SetWithoutPathExpansion( |
51 "properties", CharacteristicPropertiesToValue(properties).release()); | 60 "properties", CharacteristicPropertiesToValue(properties).release()); |
52 return to; | 61 return to; |
53 } | 62 } |
54 | 63 |
55 } // namespace bluetooth_low_energy | 64 } // namespace bluetooth_low_energy |
56 } // namespace api | 65 } // namespace api |
57 } // namespace extensions | 66 } // namespace extensions |
OLD | NEW |