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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "content/child/mojo/type_converters.h" | 10 #include "content/child/mojo/type_converters.h" |
| 11 #include "content/child/thread_safe_sender.h" | 11 #include "content/child/thread_safe_sender.h" |
| 12 #include "content/public/common/service_registry.h" | 12 #include "content/public/common/service_registry.h" |
| 13 #include "content/renderer/bluetooth/bluetooth_dispatcher.h" | 13 #include "content/renderer/bluetooth/bluetooth_dispatcher.h" |
| 14 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
| 15 #include "mojo/public/cpp/bindings/array.h" | 15 #include "mojo/public/cpp/bindings/array.h" |
| 16 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristic.h" | 16 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristic.h" |
| 17 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot eGATTCharacteristicInit.h" | |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| 20 WebBluetoothImpl::WebBluetoothImpl(ServiceRegistry* service_registry, | 21 WebBluetoothImpl::WebBluetoothImpl(ServiceRegistry* service_registry, |
| 21 ThreadSafeSender* thread_safe_sender, | 22 ThreadSafeSender* thread_safe_sender, |
| 22 int frame_routing_id) | 23 int frame_routing_id) |
| 23 : service_registry_(service_registry), | 24 : service_registry_(service_registry), |
| 24 binding_(this), | 25 binding_(this), |
| 25 thread_safe_sender_(thread_safe_sender), | 26 thread_safe_sender_(thread_safe_sender), |
| 26 frame_routing_id_(frame_routing_id) {} | 27 frame_routing_id_(frame_routing_id) {} |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 45 } | 46 } |
| 46 | 47 |
| 47 void WebBluetoothImpl::getPrimaryService( | 48 void WebBluetoothImpl::getPrimaryService( |
| 48 const blink::WebString& device_id, | 49 const blink::WebString& device_id, |
| 49 const blink::WebString& service_uuid, | 50 const blink::WebString& service_uuid, |
| 50 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { | 51 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { |
| 51 GetDispatcher()->getPrimaryService(frame_routing_id_, device_id, service_uuid, | 52 GetDispatcher()->getPrimaryService(frame_routing_id_, device_id, service_uuid, |
| 52 callbacks); | 53 callbacks); |
| 53 } | 54 } |
| 54 | 55 |
| 55 void WebBluetoothImpl::getCharacteristic( | |
| 56 const blink::WebString& service_instance_id, | |
| 57 const blink::WebString& characteristics_uuid, | |
| 58 blink::WebBluetoothGetCharacteristicCallbacks* callbacks) { | |
| 59 GetDispatcher()->getCharacteristic(frame_routing_id_, service_instance_id, | |
| 60 characteristics_uuid, callbacks); | |
| 61 } | |
| 62 | |
| 63 void WebBluetoothImpl::getCharacteristics( | 56 void WebBluetoothImpl::getCharacteristics( |
| 64 const blink::WebString& service_instance_id, | 57 const blink::WebString& service_instance_id, |
| 65 const blink::WebString& characteristic_uuid, | 58 bool single_characteristic, |
| 59 const blink::WebString& characteristics_uuid, | |
| 66 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) { | 60 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) { |
| 67 GetDispatcher()->getCharacteristics(frame_routing_id_, service_instance_id, | 61 GetWebBluetoothService().RemoteServiceGetCharacteristics( |
| 68 characteristic_uuid, callbacks); | 62 mojo::String::From(service_instance_id), single_characteristic, |
| 63 characteristics_uuid.isEmpty() ? nullptr | |
| 64 : mojo::String::From(characteristics_uuid), | |
| 65 base::Bind(&WebBluetoothImpl::OnGetCharacteristicsComplete, | |
| 66 base::Unretained(this), service_instance_id, | |
| 67 characteristics_uuid, | |
| 68 base::Passed(base::WrapUnique(callbacks)))); | |
| 69 } | 69 } |
| 70 | 70 |
| 71 void WebBluetoothImpl::readValue( | 71 void WebBluetoothImpl::readValue( |
| 72 const blink::WebString& characteristic_instance_id, | 72 const blink::WebString& characteristic_instance_id, |
| 73 blink::WebBluetoothReadValueCallbacks* callbacks) { | 73 blink::WebBluetoothReadValueCallbacks* callbacks) { |
| 74 GetWebBluetoothService().RemoteCharacteristicReadValue( | 74 GetWebBluetoothService().RemoteCharacteristicReadValue( |
| 75 mojo::String::From(characteristic_instance_id), | 75 mojo::String::From(characteristic_instance_id), |
| 76 base::Bind(&WebBluetoothImpl::OnReadValueComplete, base::Unretained(this), | 76 base::Bind(&WebBluetoothImpl::OnReadValueComplete, base::Unretained(this), |
| 77 base::Passed(base::WrapUnique(callbacks)))); | 77 base::Passed(base::WrapUnique(callbacks)))); |
| 78 } | 78 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 mojo::Array<uint8_t> value) { | 130 mojo::Array<uint8_t> value) { |
| 131 // We post a task so that the event is fired after any pending promises have | 131 // We post a task so that the event is fired after any pending promises have |
| 132 // resolved. | 132 // resolved. |
| 133 base::ThreadTaskRunnerHandle::Get()->PostTask( | 133 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 134 FROM_HERE, | 134 FROM_HERE, |
| 135 base::Bind(&WebBluetoothImpl::DispatchCharacteristicValueChanged, | 135 base::Bind(&WebBluetoothImpl::DispatchCharacteristicValueChanged, |
| 136 base::Unretained(this), characteristic_instance_id, | 136 base::Unretained(this), characteristic_instance_id, |
| 137 value.PassStorage())); | 137 value.PassStorage())); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void WebBluetoothImpl::OnGetCharacteristicsComplete( | |
| 141 const blink::WebString& service_instance_id, | |
| 142 const blink::WebString& characteristics_uuid, | |
| 143 std::unique_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks, | |
| 144 blink::mojom::WebBluetoothError error, | |
| 145 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> | |
| 146 characteristics) { | |
| 147 if (error == blink::mojom::WebBluetoothError::SUCCESS) { | |
| 148 blink::WebVector<blink::WebBluetoothRemoteGATTCharacteristicInit*> | |
|
Jeffrey Yasskin
2016/04/22 01:16:38
Keep dcheng's TODO here, to make this work with sm
ortuno
2016/04/25 15:29:45
Done.
| |
| 149 promise_characteristics(characteristics.size()); | |
| 150 | |
| 151 for (size_t i = 0; i < characteristics.size(); i++) { | |
| 152 promise_characteristics[i] = | |
| 153 new blink::WebBluetoothRemoteGATTCharacteristicInit( | |
| 154 service_instance_id, | |
| 155 blink::WebString::fromUTF8(characteristics[i]->instance_id), | |
| 156 characteristics_uuid.isEmpty() | |
| 157 ? blink::WebString::fromUTF8(characteristics[i]->uuid) | |
| 158 : characteristics_uuid, | |
| 159 characteristics[i]->properties); | |
| 160 } | |
| 161 callbacks->onSuccess(promise_characteristics); | |
|
Jeffrey Yasskin
2016/04/22 01:16:38
std::move the vector?
ortuno
2016/04/25 15:29:45
This is passed by reference. Is that wrong?
Jeffrey Yasskin
2016/04/25 17:26:10
Eventually, we should make as much as possible mov
ortuno
2016/04/25 20:37:41
Acknowledge.
| |
| 162 } else { | |
| 163 callbacks->onError(error); | |
| 164 } | |
| 165 } | |
| 166 | |
| 140 void WebBluetoothImpl::OnReadValueComplete( | 167 void WebBluetoothImpl::OnReadValueComplete( |
| 141 std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks, | 168 std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks, |
| 142 blink::mojom::WebBluetoothError error, | 169 blink::mojom::WebBluetoothError error, |
| 143 mojo::Array<uint8_t> value) { | 170 mojo::Array<uint8_t> value) { |
| 144 if (error == blink::mojom::WebBluetoothError::SUCCESS) { | 171 if (error == blink::mojom::WebBluetoothError::SUCCESS) { |
| 145 callbacks->onSuccess(value.PassStorage()); | 172 callbacks->onSuccess(value.PassStorage()); |
| 146 } else { | 173 } else { |
| 147 callbacks->onError(error); | 174 callbacks->onError(error); |
| 148 } | 175 } |
| 149 } | 176 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 // Create an associated interface ptr and pass it to the WebBluetoothService | 222 // Create an associated interface ptr and pass it to the WebBluetoothService |
| 196 // so that it can send us events without us prompting. | 223 // so that it can send us events without us prompting. |
| 197 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; | 224 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; |
| 198 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); | 225 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); |
| 199 web_bluetooth_service_->SetClient(std::move(ptr_info)); | 226 web_bluetooth_service_->SetClient(std::move(ptr_info)); |
| 200 } | 227 } |
| 201 return *web_bluetooth_service_; | 228 return *web_bluetooth_service_; |
| 202 } | 229 } |
| 203 | 230 |
| 204 } // namespace content | 231 } // namespace content |
| OLD | NEW |