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 23 matching lines...) Expand all Loading... | |
| 34 | 34 |
| 35 void WebBluetoothImpl::requestDevice( | 35 void WebBluetoothImpl::requestDevice( |
| 36 const blink::WebRequestDeviceOptions& options, | 36 const blink::WebRequestDeviceOptions& options, |
| 37 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { | 37 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { |
| 38 GetDispatcher()->requestDevice(frame_routing_id_, options, callbacks); | 38 GetDispatcher()->requestDevice(frame_routing_id_, options, callbacks); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void WebBluetoothImpl::connect( | 41 void WebBluetoothImpl::connect( |
| 42 const blink::WebString& device_id, | 42 const blink::WebString& device_id, |
| 43 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) { | 43 blink::WebBluetoothRemoteGATTServerConnectCallbacks* callbacks) { |
| 44 GetDispatcher()->connect(frame_routing_id_, device_id, callbacks); | 44 GetWebBluetoothService().RemoteServerConnect( |
| 45 mojo::String::From(device_id), | |
| 46 base::Bind(&WebBluetoothImpl::OnConnectComplete, base::Unretained(this), | |
| 47 base::Passed(base::WrapUnique(callbacks)))); | |
| 45 } | 48 } |
| 46 | 49 |
| 47 void WebBluetoothImpl::disconnect(const blink::WebString& device_id) { | 50 void WebBluetoothImpl::disconnect(const blink::WebString& device_id) { |
|
Jeffrey Yasskin
2016/05/03 01:15:57
We need this to cancel every in-progress operation
ortuno
2016/05/03 16:11:54
Acknowledged. Thanks for opening the issue!
| |
| 48 GetDispatcher()->disconnect(frame_routing_id_, device_id); | 51 GetWebBluetoothService().RemoteServerDisconnect( |
| 52 mojo::String::From(device_id)); | |
| 49 } | 53 } |
| 50 | 54 |
| 51 void WebBluetoothImpl::getPrimaryService( | 55 void WebBluetoothImpl::getPrimaryService( |
| 52 const blink::WebString& device_id, | 56 const blink::WebString& device_id, |
| 53 const blink::WebString& service_uuid, | 57 const blink::WebString& service_uuid, |
| 54 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { | 58 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { |
| 55 GetWebBluetoothService().RemoteServerGetPrimaryService( | 59 GetWebBluetoothService().RemoteServerGetPrimaryService( |
| 56 mojo::String::From(device_id), mojo::String::From(service_uuid), | 60 mojo::String::From(device_id), mojo::String::From(service_uuid), |
| 57 base::Bind(&WebBluetoothImpl::OnGetPrimaryServiceComplete, | 61 base::Bind(&WebBluetoothImpl::OnGetPrimaryServiceComplete, |
| 58 base::Unretained(this), device_id, | 62 base::Unretained(this), device_id, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 mojo::Array<uint8_t> value) { | 139 mojo::Array<uint8_t> value) { |
| 136 // We post a task so that the event is fired after any pending promises have | 140 // We post a task so that the event is fired after any pending promises have |
| 137 // resolved. | 141 // resolved. |
| 138 base::ThreadTaskRunnerHandle::Get()->PostTask( | 142 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 139 FROM_HERE, | 143 FROM_HERE, |
| 140 base::Bind(&WebBluetoothImpl::DispatchCharacteristicValueChanged, | 144 base::Bind(&WebBluetoothImpl::DispatchCharacteristicValueChanged, |
| 141 base::Unretained(this), characteristic_instance_id, | 145 base::Unretained(this), characteristic_instance_id, |
| 142 value.PassStorage())); | 146 value.PassStorage())); |
| 143 } | 147 } |
| 144 | 148 |
| 149 void WebBluetoothImpl::OnConnectComplete( | |
| 150 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks> | |
| 151 callbacks, | |
| 152 blink::mojom::WebBluetoothError error) { | |
| 153 if (error == blink::mojom::WebBluetoothError::SUCCESS) { | |
| 154 callbacks->onSuccess(); | |
| 155 } else { | |
| 156 callbacks->onError(error); | |
| 157 } | |
| 158 } | |
| 159 | |
| 145 void WebBluetoothImpl::OnGetPrimaryServiceComplete( | 160 void WebBluetoothImpl::OnGetPrimaryServiceComplete( |
| 146 const blink::WebString& device_id, | 161 const blink::WebString& device_id, |
| 147 std::unique_ptr<blink::WebBluetoothGetPrimaryServiceCallbacks> callbacks, | 162 std::unique_ptr<blink::WebBluetoothGetPrimaryServiceCallbacks> callbacks, |
| 148 blink::mojom::WebBluetoothError error, | 163 blink::mojom::WebBluetoothError error, |
| 149 blink::mojom::WebBluetoothRemoteGATTServicePtr service) { | 164 blink::mojom::WebBluetoothRemoteGATTServicePtr service) { |
| 150 if (error == blink::mojom::WebBluetoothError::SUCCESS) { | 165 if (error == blink::mojom::WebBluetoothError::SUCCESS) { |
| 151 callbacks->onSuccess( | 166 callbacks->onSuccess( |
| 152 base::WrapUnique(new blink::WebBluetoothRemoteGATTService( | 167 base::WrapUnique(new blink::WebBluetoothRemoteGATTService( |
| 153 blink::WebString::fromUTF8(service->instance_id), | 168 blink::WebString::fromUTF8(service->instance_id), |
| 154 blink::WebString::fromUTF8(service->uuid), true /* isPrimary */, | 169 blink::WebString::fromUTF8(service->uuid), true /* isPrimary */, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 // Create an associated interface ptr and pass it to the WebBluetoothService | 256 // Create an associated interface ptr and pass it to the WebBluetoothService |
| 242 // so that it can send us events without us prompting. | 257 // so that it can send us events without us prompting. |
| 243 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; | 258 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; |
| 244 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); | 259 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); |
| 245 web_bluetooth_service_->SetClient(std::move(ptr_info)); | 260 web_bluetooth_service_->SetClient(std::move(ptr_info)); |
| 246 } | 261 } |
| 247 return *web_bluetooth_service_; | 262 return *web_bluetooth_service_; |
| 248 } | 263 } |
| 249 | 264 |
| 250 } // namespace content | 265 } // namespace content |
| OLD | NEW |