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 "content/renderer/bluetooth/web_bluetooth_impl.h" | 5 #include "content/renderer/bluetooth/web_bluetooth_impl.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks, | 182 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks, |
183 const blink::mojom::WebBluetoothError error, | 183 const blink::mojom::WebBluetoothError error, |
184 blink::mojom::WebBluetoothDevicePtr device) { | 184 blink::mojom::WebBluetoothDevicePtr device) { |
185 if (error == blink::mojom::WebBluetoothError::SUCCESS) { | 185 if (error == blink::mojom::WebBluetoothError::SUCCESS) { |
186 blink::WebVector<blink::WebString> uuids(device->uuids.size()); | 186 blink::WebVector<blink::WebString> uuids(device->uuids.size()); |
187 for (size_t i = 0; i < device->uuids.size(); ++i) | 187 for (size_t i = 0; i < device->uuids.size(); ++i) |
188 uuids[i] = blink::WebString::fromUTF8(device->uuids[i]); | 188 uuids[i] = blink::WebString::fromUTF8(device->uuids[i]); |
189 | 189 |
190 callbacks->onSuccess(base::WrapUnique(new blink::WebBluetoothDeviceInit( | 190 callbacks->onSuccess(base::WrapUnique(new blink::WebBluetoothDeviceInit( |
191 blink::WebString::fromUTF8(device->id), | 191 blink::WebString::fromUTF8(device->id), |
192 blink::WebString::fromUTF8(device->name), uuids))); | 192 device->name.is_null() ? blink::WebString() |
| 193 : blink::WebString::fromUTF8(device->name), |
| 194 uuids))); |
193 } else { | 195 } else { |
194 callbacks->onError(ToInt32(error)); | 196 callbacks->onError(ToInt32(error)); |
195 } | 197 } |
196 } | 198 } |
197 | 199 |
198 void WebBluetoothImpl::GattServerDisconnected(const mojo::String& device_id) { | 200 void WebBluetoothImpl::GattServerDisconnected(const mojo::String& device_id) { |
199 auto device_iter = connected_devices_.find(device_id); | 201 auto device_iter = connected_devices_.find(device_id); |
200 if (device_iter != connected_devices_.end()) { | 202 if (device_iter != connected_devices_.end()) { |
201 // Remove device from the map before calling dispatchGattServerDisconnected | 203 // Remove device from the map before calling dispatchGattServerDisconnected |
202 // to avoid removing a device the gattserverdisconnected event handler might | 204 // to avoid removing a device the gattserverdisconnected event handler might |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 // Create an associated interface ptr and pass it to the WebBluetoothService | 319 // Create an associated interface ptr and pass it to the WebBluetoothService |
318 // so that it can send us events without us prompting. | 320 // so that it can send us events without us prompting. |
319 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; | 321 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; |
320 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); | 322 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); |
321 web_bluetooth_service_->SetClient(std::move(ptr_info)); | 323 web_bluetooth_service_->SetClient(std::move(ptr_info)); |
322 } | 324 } |
323 return *web_bluetooth_service_; | 325 return *web_bluetooth_service_; |
324 } | 326 } |
325 | 327 |
326 } // namespace content | 328 } // namespace content |
OLD | NEW |