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 "content/child/mojo/type_converters.h" | |
| 7 #include "content/child/thread_safe_sender.h" | 8 #include "content/child/thread_safe_sender.h" |
| 9 #include "content/public/common/service_registry.h" | |
| 8 #include "content/renderer/bluetooth/bluetooth_dispatcher.h" | 10 #include "content/renderer/bluetooth/bluetooth_dispatcher.h" |
| 9 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
| 12 #include "mojo/public/cpp/bindings/array.h" | |
| 10 | 13 |
| 11 namespace content { | 14 namespace content { |
| 12 | 15 |
| 13 WebBluetoothImpl::WebBluetoothImpl(ThreadSafeSender* thread_safe_sender) | 16 WebBluetoothImpl::WebBluetoothImpl(ServiceRegistry* service_registry, |
| 14 : WebBluetoothImpl(thread_safe_sender, MSG_ROUTING_NONE) {} | 17 ThreadSafeSender* thread_safe_sender, |
| 15 | |
| 16 WebBluetoothImpl::WebBluetoothImpl(ThreadSafeSender* thread_safe_sender, | |
| 17 int frame_routing_id) | 18 int frame_routing_id) |
| 18 : thread_safe_sender_(thread_safe_sender), | 19 : service_registry_(service_registry), |
| 20 thread_safe_sender_(thread_safe_sender), | |
| 19 frame_routing_id_(frame_routing_id) {} | 21 frame_routing_id_(frame_routing_id) {} |
| 20 | 22 |
| 21 WebBluetoothImpl::~WebBluetoothImpl() { | 23 WebBluetoothImpl::~WebBluetoothImpl() { |
| 22 } | 24 } |
| 23 | 25 |
| 24 void WebBluetoothImpl::requestDevice( | 26 void WebBluetoothImpl::requestDevice( |
| 25 const blink::WebRequestDeviceOptions& options, | 27 const blink::WebRequestDeviceOptions& options, |
| 26 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { | 28 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { |
| 27 GetDispatcher()->requestDevice(frame_routing_id_, options, callbacks); | 29 GetDispatcher()->requestDevice(frame_routing_id_, options, callbacks); |
| 28 } | 30 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 const blink::WebString& characteristic_instance_id, | 67 const blink::WebString& characteristic_instance_id, |
| 66 blink::WebBluetoothReadValueCallbacks* callbacks) { | 68 blink::WebBluetoothReadValueCallbacks* callbacks) { |
| 67 GetDispatcher()->readValue(frame_routing_id_, characteristic_instance_id, | 69 GetDispatcher()->readValue(frame_routing_id_, characteristic_instance_id, |
| 68 callbacks); | 70 callbacks); |
| 69 } | 71 } |
| 70 | 72 |
| 71 void WebBluetoothImpl::writeValue( | 73 void WebBluetoothImpl::writeValue( |
| 72 const blink::WebString& characteristic_instance_id, | 74 const blink::WebString& characteristic_instance_id, |
| 73 const blink::WebVector<uint8_t>& value, | 75 const blink::WebVector<uint8_t>& value, |
| 74 blink::WebBluetoothWriteValueCallbacks* callbacks) { | 76 blink::WebBluetoothWriteValueCallbacks* callbacks) { |
| 75 GetDispatcher()->writeValue(frame_routing_id_, characteristic_instance_id, | 77 GetWebBluetoothService()->RemoteCharacteristicWriteValue( |
| 76 value, callbacks); | 78 mojo::String::From(characteristic_instance_id), |
| 79 mojo::Array<uint8_t>::From(value), | |
| 80 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
| |
| 81 base::Passed(make_scoped_ptr(callbacks)))); | |
| 77 } | 82 } |
| 78 | 83 |
| 79 void WebBluetoothImpl::startNotifications( | 84 void WebBluetoothImpl::startNotifications( |
| 80 const blink::WebString& characteristic_instance_id, | 85 const blink::WebString& characteristic_instance_id, |
| 81 blink::WebBluetoothRemoteGATTCharacteristic* characteristic, | 86 blink::WebBluetoothRemoteGATTCharacteristic* characteristic, |
| 82 blink::WebBluetoothNotificationsCallbacks* callbacks) { | 87 blink::WebBluetoothNotificationsCallbacks* callbacks) { |
| 83 GetDispatcher()->startNotifications( | 88 GetDispatcher()->startNotifications( |
| 84 frame_routing_id_, characteristic_instance_id, characteristic, callbacks); | 89 frame_routing_id_, characteristic_instance_id, characteristic, callbacks); |
| 85 } | 90 } |
| 86 | 91 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 99 frame_routing_id_, characteristic_instance_id, characteristic); | 104 frame_routing_id_, characteristic_instance_id, characteristic); |
| 100 } | 105 } |
| 101 | 106 |
| 102 void WebBluetoothImpl::registerCharacteristicObject( | 107 void WebBluetoothImpl::registerCharacteristicObject( |
| 103 const blink::WebString& characteristic_instance_id, | 108 const blink::WebString& characteristic_instance_id, |
| 104 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) { | 109 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) { |
| 105 GetDispatcher()->registerCharacteristicObject( | 110 GetDispatcher()->registerCharacteristicObject( |
| 106 frame_routing_id_, characteristic_instance_id, characteristic); | 111 frame_routing_id_, characteristic_instance_id, characteristic); |
| 107 } | 112 } |
| 108 | 113 |
| 114 void WebBluetoothImpl::OnWriteValue( | |
| 115 const blink::WebVector<uint8_t>& value, | |
| 116 scoped_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks, | |
| 117 blink::mojom::WebBluetoothError error) { | |
| 118 if (error == blink::mojom::WebBluetoothError::SUCCESS) { | |
| 119 callbacks->onSuccess(value); | |
| 120 } else { | |
| 121 callbacks->onError(error); | |
| 122 } | |
| 123 } | |
| 124 | |
| 109 BluetoothDispatcher* WebBluetoothImpl::GetDispatcher() { | 125 BluetoothDispatcher* WebBluetoothImpl::GetDispatcher() { |
| 110 return BluetoothDispatcher::GetOrCreateThreadSpecificInstance( | 126 return BluetoothDispatcher::GetOrCreateThreadSpecificInstance( |
| 111 thread_safe_sender_.get()); | 127 thread_safe_sender_.get()); |
| 112 } | 128 } |
| 113 | 129 |
| 130 blink::mojom::WebBluetoothServicePtr& | |
| 131 WebBluetoothImpl::GetWebBluetoothService() { | |
| 132 if (!web_bluetooth_service_) { | |
| 133 service_registry_->ConnectToRemoteService( | |
| 134 mojo::GetProxy(&web_bluetooth_service_)); | |
| 135 } | |
| 136 return web_bluetooth_service_; | |
| 137 } | |
| 138 | |
| 114 } // namespace content | 139 } // namespace content |
| OLD | NEW |