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/child/bluetooth/bluetooth_dispatcher.h" | 5 #include "content/child/bluetooth/bluetooth_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "content/child/thread_safe_sender.h" | 11 #include "content/child/thread_safe_sender.h" |
| 12 #include "content/common/bluetooth/bluetooth_messages.h" | 12 #include "content/common/bluetooth/bluetooth_messages.h" |
| 13 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h" | 13 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h" |
| 14 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError .h" | 14 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError .h" |
| 15 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTC haracteristic.h" | 15 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTC haracteristic.h" |
| 16 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTR emoteServer.h" | 16 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTR emoteServer.h" |
| 17 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTS ervice.h" | 17 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTS ervice.h" |
| 18 | 18 |
| 19 using blink::WebBluetoothConnectGATTCallbacks; | 19 using blink::WebBluetoothConnectGATTCallbacks; |
| 20 using blink::WebBluetoothDevice; | 20 using blink::WebBluetoothDevice; |
| 21 using blink::WebBluetoothError; | 21 using blink::WebBluetoothError; |
| 22 using blink::WebBluetoothGATTCharacteristic; | 22 using blink::WebBluetoothGATTCharacteristic; |
| 23 using blink::WebBluetoothGATTRemoteServer; | 23 using blink::WebBluetoothGATTRemoteServer; |
| 24 using blink::WebBluetoothGATTService; | 24 using blink::WebBluetoothGATTService; |
| 25 using blink::WebBluetoothReadValueCallbacks; | |
| 25 using blink::WebBluetoothRequestDeviceCallbacks; | 26 using blink::WebBluetoothRequestDeviceCallbacks; |
| 26 using blink::WebString; | 27 using blink::WebString; |
| 27 using blink::WebVector; | 28 using blink::WebVector; |
| 28 | 29 |
| 29 struct BluetoothPrimaryServiceRequest { | 30 struct BluetoothPrimaryServiceRequest { |
| 30 BluetoothPrimaryServiceRequest( | 31 BluetoothPrimaryServiceRequest( |
| 31 blink::WebString device_instance_id, | 32 blink::WebString device_instance_id, |
| 32 blink::WebString service_uuid, | 33 blink::WebString service_uuid, |
| 33 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) | 34 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) |
| 34 : device_instance_id(device_instance_id), | 35 : device_instance_id(device_instance_id), |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTSuccess, OnConnectGATTSuccess); | 138 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTSuccess, OnConnectGATTSuccess); |
| 138 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTError, OnConnectGATTError); | 139 IPC_MESSAGE_HANDLER(BluetoothMsg_ConnectGATTError, OnConnectGATTError); |
| 139 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceSuccess, | 140 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceSuccess, |
| 140 OnGetPrimaryServiceSuccess); | 141 OnGetPrimaryServiceSuccess); |
| 141 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceError, | 142 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceError, |
| 142 OnGetPrimaryServiceError); | 143 OnGetPrimaryServiceError); |
| 143 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicSuccess, | 144 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicSuccess, |
| 144 OnGetCharacteristicSuccess); | 145 OnGetCharacteristicSuccess); |
| 145 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError, | 146 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError, |
| 146 OnGetCharacteristicError); | 147 OnGetCharacteristicError); |
| 148 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess, | |
| 149 OnReadValueSuccess); | |
| 150 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError, | |
| 151 OnReadValueError); | |
| 147 IPC_MESSAGE_UNHANDLED(handled = false) | 152 IPC_MESSAGE_UNHANDLED(handled = false) |
| 148 IPC_END_MESSAGE_MAP() | 153 IPC_END_MESSAGE_MAP() |
| 149 DCHECK(handled) << "Unhandled message:" << msg.type(); | 154 DCHECK(handled) << "Unhandled message:" << msg.type(); |
| 150 } | 155 } |
| 151 | 156 |
| 152 void BluetoothDispatcher::requestDevice( | 157 void BluetoothDispatcher::requestDevice( |
| 153 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { | 158 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { |
| 154 int request_id = pending_requests_.Add(callbacks); | 159 int request_id = pending_requests_.Add(callbacks); |
| 155 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id)); | 160 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id)); |
| 156 } | 161 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 180 const blink::WebString& characteristic_uuid, | 185 const blink::WebString& characteristic_uuid, |
| 181 blink::WebBluetoothGetCharacteristicCallbacks* callbacks) { | 186 blink::WebBluetoothGetCharacteristicCallbacks* callbacks) { |
| 182 int request_id = | 187 int request_id = |
| 183 pending_characteristic_requests_.Add(new BluetoothCharacteristicRequest( | 188 pending_characteristic_requests_.Add(new BluetoothCharacteristicRequest( |
| 184 service_instance_id, characteristic_uuid, callbacks)); | 189 service_instance_id, characteristic_uuid, callbacks)); |
| 185 Send(new BluetoothHostMsg_GetCharacteristic(CurrentWorkerId(), request_id, | 190 Send(new BluetoothHostMsg_GetCharacteristic(CurrentWorkerId(), request_id, |
| 186 service_instance_id.utf8(), | 191 service_instance_id.utf8(), |
| 187 characteristic_uuid.utf8())); | 192 characteristic_uuid.utf8())); |
| 188 } | 193 } |
| 189 | 194 |
| 195 void BluetoothDispatcher::readValue( | |
| 196 const blink::WebString& characteristic_instance_id, | |
| 197 blink::WebBluetoothReadValueCallbacks* callbacks) { | |
| 198 int request_id = pending_read_value_requests_.Add(callbacks); | |
| 199 Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id, | |
| 200 characteristic_instance_id.utf8())); | |
| 201 } | |
| 202 | |
| 190 void BluetoothDispatcher::OnWorkerRunLoopStopped() { | 203 void BluetoothDispatcher::OnWorkerRunLoopStopped() { |
| 191 delete this; | 204 delete this; |
| 192 } | 205 } |
| 193 | 206 |
| 194 void BluetoothDispatcher::OnRequestDeviceSuccess( | 207 void BluetoothDispatcher::OnRequestDeviceSuccess( |
| 195 int thread_id, | 208 int thread_id, |
| 196 int request_id, | 209 int request_id, |
| 197 const BluetoothDevice& device) { | 210 const BluetoothDevice& device) { |
| 198 DCHECK(pending_requests_.Lookup(request_id)) << request_id; | 211 DCHECK(pending_requests_.Lookup(request_id)) << request_id; |
| 199 | 212 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 // http://crbug.com/490419 | 292 // http://crbug.com/490419 |
| 280 WebBluetoothErrorFromBluetoothError(error_type), "")); | 293 WebBluetoothErrorFromBluetoothError(error_type), "")); |
| 281 pending_primary_service_requests_.Remove(request_id); | 294 pending_primary_service_requests_.Remove(request_id); |
| 282 } | 295 } |
| 283 | 296 |
| 284 void BluetoothDispatcher::OnGetCharacteristicSuccess( | 297 void BluetoothDispatcher::OnGetCharacteristicSuccess( |
| 285 int thread_id, | 298 int thread_id, |
| 286 int request_id, | 299 int request_id, |
| 287 const std::string& characteristic_instance_id) { | 300 const std::string& characteristic_instance_id) { |
| 288 DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id; | 301 DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id; |
| 289 | |
| 290 BluetoothCharacteristicRequest* request = | 302 BluetoothCharacteristicRequest* request = |
| 291 pending_characteristic_requests_.Lookup(request_id); | 303 pending_characteristic_requests_.Lookup(request_id); |
| 292 request->callbacks->onSuccess(new WebBluetoothGATTCharacteristic( | 304 request->callbacks->onSuccess(new WebBluetoothGATTCharacteristic( |
| 293 WebString::fromUTF8(characteristic_instance_id), | 305 WebString::fromUTF8(characteristic_instance_id), |
| 294 request->service_instance_id, request->characteristic_uuid)); | 306 request->service_instance_id, request->characteristic_uuid)); |
| 295 | 307 |
| 296 pending_characteristic_requests_.Remove(request_id); | 308 pending_characteristic_requests_.Remove(request_id); |
| 297 } | 309 } |
| 298 | 310 |
| 299 void BluetoothDispatcher::OnGetCharacteristicError(int thread_id, | 311 void BluetoothDispatcher::OnGetCharacteristicError(int thread_id, |
| 300 int request_id, | 312 int request_id, |
| 301 BluetoothError error_type) { | 313 BluetoothError error_type) { |
| 302 DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id; | 314 DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id; |
| 303 | |
|
Jeffrey Yasskin
2015/06/10 21:03:45
I kinda liked these blank lines.
ortuno
2015/06/10 22:03:01
Done.
| |
| 304 // Since we couldn't find the characteristic return null. See Step 3 of | 315 // Since we couldn't find the characteristic return null. See Step 3 of |
| 305 // getCharacteristic algorithm: | 316 // getCharacteristic algorithm: |
| 306 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothgattservice-ge tcharacteristic | 317 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothgattservice-ge tcharacteristic |
| 307 if (error_type == BluetoothError::NOT_FOUND) { | 318 if (error_type == BluetoothError::NOT_FOUND) { |
| 308 pending_characteristic_requests_.Lookup(request_id) | 319 pending_characteristic_requests_.Lookup(request_id) |
| 309 ->callbacks->onSuccess(nullptr); | 320 ->callbacks->onSuccess(nullptr); |
| 310 } else { | 321 } else { |
| 311 pending_characteristic_requests_.Lookup(request_id) | 322 pending_characteristic_requests_.Lookup(request_id) |
| 312 ->callbacks->onError(new WebBluetoothError( | 323 ->callbacks->onError(new WebBluetoothError( |
| 313 // TODO(ortuno): Return more descriptive error messages. | 324 // TODO(ortuno): Return more descriptive error messages. |
| 314 // http://crbug.com/490419 | 325 // http://crbug.com/490419 |
| 315 WebBluetoothErrorFromBluetoothError(error_type), "")); | 326 WebBluetoothErrorFromBluetoothError(error_type), "")); |
| 316 } | 327 } |
| 317 pending_characteristic_requests_.Remove(request_id); | 328 pending_characteristic_requests_.Remove(request_id); |
| 318 } | 329 } |
| 319 | 330 |
| 331 void BluetoothDispatcher::OnReadValueSuccess( | |
| 332 int thread_id, | |
| 333 int request_id, | |
| 334 const std::vector<uint8_t>& value) { | |
| 335 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id; | |
| 336 | |
| 337 // WebArrayBuffer is not accessible from Source/modules so we pass a | |
| 338 // WebVector instead. | |
| 339 pending_read_value_requests_.Lookup(request_id) | |
| 340 ->onSuccess(new WebVector<uint8_t>(value)); | |
| 341 | |
| 342 pending_read_value_requests_.Remove(request_id); | |
| 343 } | |
| 344 | |
| 345 void BluetoothDispatcher::OnReadValueError(int thread_id, | |
| 346 int request_id, | |
| 347 BluetoothError error_type) { | |
| 348 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id; | |
| 349 | |
| 350 pending_read_value_requests_.Lookup(request_id) | |
| 351 ->onError(new WebBluetoothError( | |
| 352 // TODO(ortuno): Return more descriptive error messages. | |
| 353 // http://crbug.com/490419 | |
| 354 WebBluetoothErrorFromBluetoothError(error_type), "")); | |
| 355 | |
| 356 pending_read_value_requests_.Remove(request_id); | |
| 357 } | |
| 358 | |
| 320 } // namespace content | 359 } // namespace content |
| OLD | NEW |