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

Side by Side Diff: chrome/browser/extensions/api/bluetooth_low_energy/utils.cc

Issue 2370373002: Move chrome.bluetoothLowEnergy out of //chrome. (Closed)
Patch Set: build fix Created 4 years, 2 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/api/bluetooth_low_energy/utils.h"
6
7 #include <stddef.h>
8 #include <iterator>
9 #include <vector>
10
11 #include "base/logging.h"
12
13 namespace extensions {
14 namespace api {
15 namespace bluetooth_low_energy {
16
17 namespace {
18
19 // Converts a list of CharacteristicProperty to a base::ListValue of strings.
20 std::unique_ptr<base::ListValue> CharacteristicPropertiesToValue(
21 const std::vector<CharacteristicProperty> properties) {
22 std::unique_ptr<base::ListValue> property_list(new base::ListValue());
23 for (std::vector<CharacteristicProperty>::const_iterator iter =
24 properties.begin();
25 iter != properties.end();
26 ++iter)
27 property_list->AppendString(ToString(*iter));
28 return property_list;
29 }
30
31 } // namespace
32
33 std::unique_ptr<base::DictionaryValue> CharacteristicToValue(
34 Characteristic* from) {
35 // Copy the properties. Use Characteristic::ToValue to generate the result
36 // dictionary without the properties, to prevent json_schema_compiler from
37 // failing.
38 std::vector<CharacteristicProperty> properties = from->properties;
39 from->properties.clear();
40 std::unique_ptr<base::DictionaryValue> to = from->ToValue();
41 to->SetWithoutPathExpansion(
42 "properties", CharacteristicPropertiesToValue(properties).release());
43 return to;
44 }
45
46 std::unique_ptr<base::DictionaryValue> DescriptorToValue(Descriptor* from) {
47 if (!from->characteristic)
48 return from->ToValue();
49
50 // Copy the characteristic properties and set them later manually.
51 std::vector<CharacteristicProperty> properties =
52 from->characteristic->properties;
53 from->characteristic->properties.clear();
54 std::unique_ptr<base::DictionaryValue> to = from->ToValue();
55
56 base::DictionaryValue* chrc_value = NULL;
57 to->GetDictionaryWithoutPathExpansion("characteristic", &chrc_value);
58 DCHECK(chrc_value);
59 chrc_value->SetWithoutPathExpansion(
60 "properties", CharacteristicPropertiesToValue(properties).release());
61 return to;
62 }
63
64 } // namespace bluetooth_low_energy
65 } // namespace api
66 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698