| 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 "base/memory/ptr_util.h" |
| 7 #include "content/child/mojo/type_converters.h" | 8 #include "content/child/mojo/type_converters.h" |
| 8 #include "content/child/thread_safe_sender.h" | 9 #include "content/child/thread_safe_sender.h" |
| 9 #include "content/public/common/service_registry.h" | 10 #include "content/public/common/service_registry.h" |
| 10 #include "content/renderer/bluetooth/bluetooth_dispatcher.h" | 11 #include "content/renderer/bluetooth/bluetooth_dispatcher.h" |
| 11 #include "ipc/ipc_message.h" | 12 #include "ipc/ipc_message.h" |
| 12 #include "mojo/public/cpp/bindings/array.h" | 13 #include "mojo/public/cpp/bindings/array.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 WebBluetoothImpl::WebBluetoothImpl(ServiceRegistry* service_registry, | 17 WebBluetoothImpl::WebBluetoothImpl(ServiceRegistry* service_registry, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 73 |
| 73 void WebBluetoothImpl::writeValue( | 74 void WebBluetoothImpl::writeValue( |
| 74 const blink::WebString& characteristic_instance_id, | 75 const blink::WebString& characteristic_instance_id, |
| 75 const blink::WebVector<uint8_t>& value, | 76 const blink::WebVector<uint8_t>& value, |
| 76 blink::WebBluetoothWriteValueCallbacks* callbacks) { | 77 blink::WebBluetoothWriteValueCallbacks* callbacks) { |
| 77 GetWebBluetoothService().RemoteCharacteristicWriteValue( | 78 GetWebBluetoothService().RemoteCharacteristicWriteValue( |
| 78 mojo::String::From(characteristic_instance_id), | 79 mojo::String::From(characteristic_instance_id), |
| 79 mojo::Array<uint8_t>::From(value), | 80 mojo::Array<uint8_t>::From(value), |
| 80 base::Bind(&WebBluetoothImpl::OnWriteValueComplete, | 81 base::Bind(&WebBluetoothImpl::OnWriteValueComplete, |
| 81 base::Unretained(this), value, | 82 base::Unretained(this), value, |
| 82 base::Passed(make_scoped_ptr(callbacks)))); | 83 base::Passed(base::WrapUnique(callbacks)))); |
| 83 } | 84 } |
| 84 | 85 |
| 85 void WebBluetoothImpl::startNotifications( | 86 void WebBluetoothImpl::startNotifications( |
| 86 const blink::WebString& characteristic_instance_id, | 87 const blink::WebString& characteristic_instance_id, |
| 87 blink::WebBluetoothRemoteGATTCharacteristic* characteristic, | 88 blink::WebBluetoothRemoteGATTCharacteristic* characteristic, |
| 88 blink::WebBluetoothNotificationsCallbacks* callbacks) { | 89 blink::WebBluetoothNotificationsCallbacks* callbacks) { |
| 89 GetDispatcher()->startNotifications( | 90 GetDispatcher()->startNotifications( |
| 90 frame_routing_id_, characteristic_instance_id, characteristic, callbacks); | 91 frame_routing_id_, characteristic_instance_id, characteristic, callbacks); |
| 91 } | 92 } |
| 92 | 93 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 107 | 108 |
| 108 void WebBluetoothImpl::registerCharacteristicObject( | 109 void WebBluetoothImpl::registerCharacteristicObject( |
| 109 const blink::WebString& characteristic_instance_id, | 110 const blink::WebString& characteristic_instance_id, |
| 110 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) { | 111 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) { |
| 111 GetDispatcher()->registerCharacteristicObject( | 112 GetDispatcher()->registerCharacteristicObject( |
| 112 frame_routing_id_, characteristic_instance_id, characteristic); | 113 frame_routing_id_, characteristic_instance_id, characteristic); |
| 113 } | 114 } |
| 114 | 115 |
| 115 void WebBluetoothImpl::OnWriteValueComplete( | 116 void WebBluetoothImpl::OnWriteValueComplete( |
| 116 const blink::WebVector<uint8_t>& value, | 117 const blink::WebVector<uint8_t>& value, |
| 117 scoped_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks, | 118 std::unique_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks, |
| 118 blink::mojom::WebBluetoothError error) { | 119 blink::mojom::WebBluetoothError error) { |
| 119 if (error == blink::mojom::WebBluetoothError::SUCCESS) { | 120 if (error == blink::mojom::WebBluetoothError::SUCCESS) { |
| 120 callbacks->onSuccess(value); | 121 callbacks->onSuccess(value); |
| 121 } else { | 122 } else { |
| 122 callbacks->onError(error); | 123 callbacks->onError(error); |
| 123 } | 124 } |
| 124 } | 125 } |
| 125 | 126 |
| 126 BluetoothDispatcher* WebBluetoothImpl::GetDispatcher() { | 127 BluetoothDispatcher* WebBluetoothImpl::GetDispatcher() { |
| 127 return BluetoothDispatcher::GetOrCreateThreadSpecificInstance( | 128 return BluetoothDispatcher::GetOrCreateThreadSpecificInstance( |
| 128 thread_safe_sender_.get()); | 129 thread_safe_sender_.get()); |
| 129 } | 130 } |
| 130 | 131 |
| 131 blink::mojom::WebBluetoothService& WebBluetoothImpl::GetWebBluetoothService() { | 132 blink::mojom::WebBluetoothService& WebBluetoothImpl::GetWebBluetoothService() { |
| 132 if (!web_bluetooth_service_) { | 133 if (!web_bluetooth_service_) { |
| 133 service_registry_->ConnectToRemoteService( | 134 service_registry_->ConnectToRemoteService( |
| 134 mojo::GetProxy(&web_bluetooth_service_)); | 135 mojo::GetProxy(&web_bluetooth_service_)); |
| 135 } | 136 } |
| 136 return *web_bluetooth_service_; | 137 return *web_bluetooth_service_; |
| 137 } | 138 } |
| 138 | 139 |
| 139 } // namespace content | 140 } // namespace content |
| OLD | NEW |