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

Side by Side Diff: content/renderer/bluetooth/bluetooth_type_converters.cc

Issue 2506813003: Use new wrapper types for web_bluetooth.mojom (Closed)
Patch Set: updated web_bluetooth_impl.cc Created 4 years, 1 month 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/renderer/bluetooth/bluetooth_type_converters.h" 5 #include "content/renderer/bluetooth/bluetooth_type_converters.h"
6 6
7 #include "content/child/mojo/type_converters.h" 7 #include "content/child/mojo/type_converters.h"
8 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO ptions.h" 8 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO ptions.h"
9 9
10 namespace mojo { 10 namespace mojo {
11 11
12 // static 12 // static
13 blink::mojom::WebBluetoothScanFilterPtr TypeConverter< 13 blink::mojom::WebBluetoothScanFilterPtr TypeConverter<
14 blink::mojom::WebBluetoothScanFilterPtr, 14 blink::mojom::WebBluetoothScanFilterPtr,
15 blink::WebBluetoothScanFilter>::Convert(const blink::WebBluetoothScanFilter& 15 blink::WebBluetoothScanFilter>::Convert(const blink::WebBluetoothScanFilter&
16 web_filter) { 16 web_filter) {
17 blink::mojom::WebBluetoothScanFilterPtr filter = 17 blink::mojom::WebBluetoothScanFilterPtr filter =
18 blink::mojom::WebBluetoothScanFilter::New(); 18 blink::mojom::WebBluetoothScanFilter::New();
19 19
20 if (!web_filter.services.isEmpty()) 20 if (!web_filter.services.isEmpty()) {
21 filter->services = 21 filter->services = std::vector<device::BluetoothUUID>();
22 Array<base::Optional<device::BluetoothUUID>>::From(web_filter.services); 22 for (const auto service : web_filter.services) {
ortuno 2016/11/21 04:42:31 Make it a reference.
juncai 2016/11/21 21:27:05 Done.
23 filter->services->push_back(device::BluetoothUUID(service.utf8()));
24 }
25 }
23 26
24 if (web_filter.hasName) 27 if (web_filter.hasName)
25 filter->name = String::From(web_filter.name); 28 filter->name = web_filter.name.utf8();
26 29
27 if (!web_filter.namePrefix.isEmpty()) 30 if (!web_filter.namePrefix.isEmpty())
28 filter->name_prefix = String::From(web_filter.namePrefix); 31 filter->name_prefix = web_filter.namePrefix.utf8();
29 return filter; 32 return filter;
30 } 33 }
31 34
32 // static 35 // static
33 blink::mojom::WebBluetoothRequestDeviceOptionsPtr 36 blink::mojom::WebBluetoothRequestDeviceOptionsPtr
34 TypeConverter<blink::mojom::WebBluetoothRequestDeviceOptionsPtr, 37 TypeConverter<blink::mojom::WebBluetoothRequestDeviceOptionsPtr,
35 blink::WebRequestDeviceOptions>:: 38 blink::WebRequestDeviceOptions>::
36 Convert(const blink::WebRequestDeviceOptions& web_options) { 39 Convert(const blink::WebRequestDeviceOptions& web_options) {
37 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options = 40 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options =
38 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 41 blink::mojom::WebBluetoothRequestDeviceOptions::New();
39 42
40 options->filters = mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>::From( 43 for (const auto& filter : web_options.filters) {
41 web_options.filters); 44 options->filters.push_back(blink::mojom::WebBluetoothScanFilter::From<
42 options->optional_services = 45 blink::WebBluetoothScanFilter>(filter));
43 mojo::Array<base::Optional<device::BluetoothUUID>>::From( 46 }
44 web_options.optionalServices); 47 for (const auto& optional_service : web_options.optionalServices) {
48 options->optional_services.push_back(
49 device::BluetoothUUID(optional_service.utf8()));
50 }
45 return options; 51 return options;
46 } 52 }
47 53
48 // static 54 // static
49 base::Optional<device::BluetoothUUID> 55 device::BluetoothUUID
50 TypeConverter<base::Optional<device::BluetoothUUID>, blink::WebString>::Convert( 56 TypeConverter<device::BluetoothUUID, blink::WebString>::Convert(
51 const blink::WebString& web_string) { 57 const blink::WebString& web_string) {
52 base::Optional<device::BluetoothUUID> uuid = 58 device::BluetoothUUID uuid = device::BluetoothUUID(web_string.utf8());
53 device::BluetoothUUID(web_string.utf8());
54 59
55 DCHECK(uuid->IsValid()); 60 DCHECK(uuid.IsValid());
56 61
57 return uuid; 62 return uuid;
58 } 63 }
59 64
60 } // namespace mojo 65 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698