Chromium Code Reviews| Index: content/renderer/bluetooth/web_bluetooth_impl.cc |
| diff --git a/content/renderer/bluetooth/web_bluetooth_impl.cc b/content/renderer/bluetooth/web_bluetooth_impl.cc |
| index 2df80b3ad7421d2ef0dc55b3a12fa2c0ff923dba..8ae90cf611419b5b8b37e5ce8521cbf596eee744 100644 |
| --- a/content/renderer/bluetooth/web_bluetooth_impl.cc |
| +++ b/content/renderer/bluetooth/web_bluetooth_impl.cc |
| @@ -4,18 +4,20 @@ |
| #include "content/renderer/bluetooth/web_bluetooth_impl.h" |
| +#include "content/child/mojo/type_converters.h" |
| #include "content/child/thread_safe_sender.h" |
| +#include "content/public/common/service_registry.h" |
| #include "content/renderer/bluetooth/bluetooth_dispatcher.h" |
| #include "ipc/ipc_message.h" |
| +#include "mojo/public/cpp/bindings/array.h" |
| namespace content { |
| -WebBluetoothImpl::WebBluetoothImpl(ThreadSafeSender* thread_safe_sender) |
| - : WebBluetoothImpl(thread_safe_sender, MSG_ROUTING_NONE) {} |
| - |
| -WebBluetoothImpl::WebBluetoothImpl(ThreadSafeSender* thread_safe_sender, |
| +WebBluetoothImpl::WebBluetoothImpl(ServiceRegistry* service_registry, |
| + ThreadSafeSender* thread_safe_sender, |
| int frame_routing_id) |
| - : thread_safe_sender_(thread_safe_sender), |
| + : service_registry_(service_registry), |
| + thread_safe_sender_(thread_safe_sender), |
| frame_routing_id_(frame_routing_id) {} |
| WebBluetoothImpl::~WebBluetoothImpl() { |
| @@ -72,8 +74,11 @@ void WebBluetoothImpl::writeValue( |
| const blink::WebString& characteristic_instance_id, |
| const blink::WebVector<uint8_t>& value, |
| blink::WebBluetoothWriteValueCallbacks* callbacks) { |
| - GetDispatcher()->writeValue(frame_routing_id_, characteristic_instance_id, |
| - value, callbacks); |
| + GetWebBluetoothService()->RemoteCharacteristicWriteValue( |
| + mojo::String::From(characteristic_instance_id), |
| + mojo::Array<uint8_t>::From(value), |
| + base::Bind(&WebBluetoothImpl::OnWriteValue, base::Unretained(this), value, |
|
Ken Rockot(use gerrit already)
2016/03/17 18:16:13
Here's a fun problem. If you can't get a WebBlueto
ortuno
2016/03/18 01:19:20
As discussed offline, ScriptPromiseResolver only D
|
| + base::Passed(make_scoped_ptr(callbacks)))); |
| } |
| void WebBluetoothImpl::startNotifications( |
| @@ -106,9 +111,29 @@ void WebBluetoothImpl::registerCharacteristicObject( |
| frame_routing_id_, characteristic_instance_id, characteristic); |
| } |
| +void WebBluetoothImpl::OnWriteValue( |
| + const blink::WebVector<uint8_t>& value, |
| + scoped_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks, |
| + blink::mojom::WebBluetoothError error) { |
| + if (error == blink::mojom::WebBluetoothError::SUCCESS) { |
| + callbacks->onSuccess(value); |
| + } else { |
| + callbacks->onError(error); |
| + } |
| +} |
| + |
| BluetoothDispatcher* WebBluetoothImpl::GetDispatcher() { |
| return BluetoothDispatcher::GetOrCreateThreadSpecificInstance( |
| thread_safe_sender_.get()); |
| } |
| +blink::mojom::WebBluetoothServicePtr& |
| +WebBluetoothImpl::GetWebBluetoothService() { |
| + if (!web_bluetooth_service_) { |
| + service_registry_->ConnectToRemoteService( |
| + mojo::GetProxy(&web_bluetooth_service_)); |
| + } |
| + return web_bluetooth_service_; |
| +} |
| + |
| } // namespace content |