Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 40 base::Unretained(this), | 40 base::Unretained(this), |
| 41 base::Passed(base::WrapUnique(callbacks)))); | 41 base::Passed(base::WrapUnique(callbacks)))); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void WebBluetoothImpl::connect( | 44 void WebBluetoothImpl::connect( |
| 45 const blink::WebString& device_id, | 45 const blink::WebString& device_id, |
| 46 blink::WebBluetoothDevice* device, | 46 blink::WebBluetoothDevice* device, |
| 47 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) { | 47 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) { |
| 48 // TODO(crbug.com/495270): After the Bluetooth Tree is implemented, there will | 48 // TODO(crbug.com/495270): After the Bluetooth Tree is implemented, there will |
| 49 // only be one object per device. But for now we replace the previous object. | 49 // only be one object per device. But for now we replace the previous object. |
| 50 connected_devices_[device_id.utf8()] = device; | 50 connected_devices_[device_id.utf8()] = device; |
|
Jeffrey Yasskin
2016/06/03 17:22:05
Could you convert connected_devices_ to store Blue
ortuno
2016/06/06 22:23:00
Done.
| |
| 51 | 51 |
| 52 GetWebBluetoothService().RemoteServerConnect( | 52 GetWebBluetoothService().RemoteServerConnect( |
| 53 mojo::String::From(device_id), | 53 BluetoothDeviceId(device_id.utf8()), |
| 54 base::Bind(&WebBluetoothImpl::OnConnectComplete, base::Unretained(this), | 54 base::Bind(&WebBluetoothImpl::OnConnectComplete, base::Unretained(this), |
| 55 base::Passed(base::WrapUnique(callbacks)))); | 55 base::Passed(base::WrapUnique(callbacks)))); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void WebBluetoothImpl::disconnect(const blink::WebString& device_id) { | 58 void WebBluetoothImpl::disconnect(const blink::WebString& device_id) { |
| 59 connected_devices_.erase(device_id.utf8()); | 59 connected_devices_.erase(device_id.utf8()); |
| 60 | 60 |
| 61 GetWebBluetoothService().RemoteServerDisconnect( | 61 GetWebBluetoothService().RemoteServerDisconnect( |
| 62 mojo::String::From(device_id)); | 62 BluetoothDeviceId(device_id.utf8())); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void WebBluetoothImpl::getPrimaryService( | 65 void WebBluetoothImpl::getPrimaryService( |
| 66 const blink::WebString& device_id, | 66 const blink::WebString& device_id, |
| 67 const blink::WebString& service_uuid, | 67 const blink::WebString& service_uuid, |
| 68 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { | 68 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { |
| 69 GetWebBluetoothService().RemoteServerGetPrimaryService( | 69 GetWebBluetoothService().RemoteServerGetPrimaryService( |
| 70 mojo::String::From(device_id), | 70 BluetoothDeviceId(device_id.utf8()), |
| 71 base::make_optional(device::BluetoothUUID(service_uuid.utf8())), | 71 base::make_optional(device::BluetoothUUID(service_uuid.utf8())), |
| 72 base::Bind(&WebBluetoothImpl::OnGetPrimaryServiceComplete, | 72 base::Bind(&WebBluetoothImpl::OnGetPrimaryServiceComplete, |
| 73 base::Unretained(this), device_id, | 73 base::Unretained(this), device_id, |
| 74 base::Passed(base::WrapUnique(callbacks)))); | 74 base::Passed(base::WrapUnique(callbacks)))); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void WebBluetoothImpl::getCharacteristics( | 77 void WebBluetoothImpl::getCharacteristics( |
| 78 const blink::WebString& service_instance_id, | 78 const blink::WebString& service_instance_id, |
| 79 blink::mojom::WebBluetoothGATTQueryQuantity quantity, | 79 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
| 80 const blink::WebString& characteristics_uuid, | 80 const blink::WebString& characteristics_uuid, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 void WebBluetoothImpl::OnRequestDeviceComplete( | 162 void WebBluetoothImpl::OnRequestDeviceComplete( |
| 163 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks, | 163 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks, |
| 164 const blink::mojom::WebBluetoothError error, | 164 const blink::mojom::WebBluetoothError error, |
| 165 blink::mojom::WebBluetoothDevicePtr device) { | 165 blink::mojom::WebBluetoothDevicePtr device) { |
| 166 if (error == blink::mojom::WebBluetoothError::SUCCESS) { | 166 if (error == blink::mojom::WebBluetoothError::SUCCESS) { |
| 167 blink::WebVector<blink::WebString> uuids(device->uuids.size()); | 167 blink::WebVector<blink::WebString> uuids(device->uuids.size()); |
| 168 for (size_t i = 0; i < device->uuids.size(); ++i) | 168 for (size_t i = 0; i < device->uuids.size(); ++i) |
| 169 uuids[i] = blink::WebString::fromUTF8(device->uuids[i]); | 169 uuids[i] = blink::WebString::fromUTF8(device->uuids[i]); |
| 170 | 170 |
| 171 callbacks->onSuccess(base::WrapUnique(new blink::WebBluetoothDeviceInit( | 171 callbacks->onSuccess(base::WrapUnique(new blink::WebBluetoothDeviceInit( |
| 172 blink::WebString::fromUTF8(device->id), | 172 blink::WebString::fromUTF8(device->id.str()), |
| 173 blink::WebString::fromUTF8(device->name), uuids))); | 173 blink::WebString::fromUTF8(device->name), uuids))); |
| 174 } else { | 174 } else { |
| 175 callbacks->onError(error); | 175 callbacks->onError(error); |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 void WebBluetoothImpl::GattServerDisconnected(const mojo::String& device_id) { | 179 void WebBluetoothImpl::GattServerDisconnected( |
| 180 auto device_iter = connected_devices_.find(device_id); | 180 const BluetoothDeviceId& device_id) { |
| 181 auto device_iter = connected_devices_.find(device_id.str()); | |
| 181 if (device_iter != connected_devices_.end()) { | 182 if (device_iter != connected_devices_.end()) { |
| 182 device_iter->second->dispatchGattServerDisconnected(); | 183 device_iter->second->dispatchGattServerDisconnected(); |
| 183 connected_devices_.erase(device_iter); | 184 connected_devices_.erase(device_iter); |
| 184 } | 185 } |
| 185 } | 186 } |
| 186 | 187 |
| 187 void WebBluetoothImpl::OnConnectComplete( | 188 void WebBluetoothImpl::OnConnectComplete( |
| 188 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks> | 189 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks> |
| 189 callbacks, | 190 callbacks, |
| 190 blink::mojom::WebBluetoothError error) { | 191 blink::mojom::WebBluetoothError error) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 // Create an associated interface ptr and pass it to the WebBluetoothService | 290 // Create an associated interface ptr and pass it to the WebBluetoothService |
| 290 // so that it can send us events without us prompting. | 291 // so that it can send us events without us prompting. |
| 291 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; | 292 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; |
| 292 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); | 293 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); |
| 293 web_bluetooth_service_->SetClient(std::move(ptr_info)); | 294 web_bluetooth_service_->SetClient(std::move(ptr_info)); |
| 294 } | 295 } |
| 295 return *web_bluetooth_service_; | 296 return *web_bluetooth_service_; |
| 296 } | 297 } |
| 297 | 298 |
| 298 } // namespace content | 299 } // namespace content |
| OLD | NEW |