| 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" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceError, | 156 IPC_MESSAGE_HANDLER(BluetoothMsg_GetPrimaryServiceError, |
| 157 OnGetPrimaryServiceError); | 157 OnGetPrimaryServiceError); |
| 158 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicSuccess, | 158 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicSuccess, |
| 159 OnGetCharacteristicSuccess); | 159 OnGetCharacteristicSuccess); |
| 160 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError, | 160 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError, |
| 161 OnGetCharacteristicError); | 161 OnGetCharacteristicError); |
| 162 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess, | 162 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess, |
| 163 OnReadValueSuccess); | 163 OnReadValueSuccess); |
| 164 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError, | 164 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError, |
| 165 OnReadValueError); | 165 OnReadValueError); |
| 166 IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueSuccess, |
| 167 OnWriteValueSuccess); |
| 168 IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueError, |
| 169 OnWriteValueError); |
| 166 IPC_MESSAGE_UNHANDLED(handled = false) | 170 IPC_MESSAGE_UNHANDLED(handled = false) |
| 167 IPC_END_MESSAGE_MAP() | 171 IPC_END_MESSAGE_MAP() |
| 168 DCHECK(handled) << "Unhandled message:" << msg.type(); | 172 DCHECK(handled) << "Unhandled message:" << msg.type(); |
| 169 } | 173 } |
| 170 | 174 |
| 171 void BluetoothDispatcher::requestDevice( | 175 void BluetoothDispatcher::requestDevice( |
| 172 const WebRequestDeviceOptions& options, | 176 const WebRequestDeviceOptions& options, |
| 173 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { | 177 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { |
| 174 int request_id = pending_requests_.Add(callbacks); | 178 int request_id = pending_requests_.Add(callbacks); |
| 175 | 179 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 230 } |
| 227 | 231 |
| 228 void BluetoothDispatcher::readValue( | 232 void BluetoothDispatcher::readValue( |
| 229 const blink::WebString& characteristic_instance_id, | 233 const blink::WebString& characteristic_instance_id, |
| 230 blink::WebBluetoothReadValueCallbacks* callbacks) { | 234 blink::WebBluetoothReadValueCallbacks* callbacks) { |
| 231 int request_id = pending_read_value_requests_.Add(callbacks); | 235 int request_id = pending_read_value_requests_.Add(callbacks); |
| 232 Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id, | 236 Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id, |
| 233 characteristic_instance_id.utf8())); | 237 characteristic_instance_id.utf8())); |
| 234 } | 238 } |
| 235 | 239 |
| 240 void BluetoothDispatcher::writeValue( |
| 241 const blink::WebString& characteristic_instance_id, |
| 242 const std::vector<uint8_t>& value, |
| 243 blink::WebBluetoothWriteValueCallbacks* callbacks) { |
| 244 int request_id = pending_write_value_requests_.Add(callbacks); |
| 245 |
| 246 Send(new BluetoothHostMsg_WriteValue( |
| 247 CurrentWorkerId(), request_id, characteristic_instance_id.utf8(), value)); |
| 248 } |
| 249 |
| 236 void BluetoothDispatcher::OnWorkerRunLoopStopped() { | 250 void BluetoothDispatcher::OnWorkerRunLoopStopped() { |
| 237 delete this; | 251 delete this; |
| 238 } | 252 } |
| 239 | 253 |
| 240 void BluetoothDispatcher::OnRequestDeviceSuccess( | 254 void BluetoothDispatcher::OnRequestDeviceSuccess( |
| 241 int thread_id, | 255 int thread_id, |
| 242 int request_id, | 256 int request_id, |
| 243 const BluetoothDevice& device) { | 257 const BluetoothDevice& device) { |
| 244 DCHECK(pending_requests_.Lookup(request_id)) << request_id; | 258 DCHECK(pending_requests_.Lookup(request_id)) << request_id; |
| 245 | 259 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 pending_read_value_requests_.Lookup(request_id) | 411 pending_read_value_requests_.Lookup(request_id) |
| 398 ->onError(new WebBluetoothError( | 412 ->onError(new WebBluetoothError( |
| 399 // TODO(ortuno): Return more descriptive error messages. | 413 // TODO(ortuno): Return more descriptive error messages. |
| 400 // http://crbug.com/490419 | 414 // http://crbug.com/490419 |
| 401 WebBluetoothErrorFromBluetoothError(error_type), | 415 WebBluetoothErrorFromBluetoothError(error_type), |
| 402 WebString::fromUTF8(error_message))); | 416 WebString::fromUTF8(error_message))); |
| 403 | 417 |
| 404 pending_read_value_requests_.Remove(request_id); | 418 pending_read_value_requests_.Remove(request_id); |
| 405 } | 419 } |
| 406 | 420 |
| 421 void BluetoothDispatcher::OnWriteValueSuccess(int thread_id, int request_id) { |
| 422 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; |
| 423 |
| 424 pending_write_value_requests_.Lookup(request_id)->onSuccess(); |
| 425 |
| 426 pending_write_value_requests_.Remove(request_id); |
| 427 } |
| 428 |
| 429 void BluetoothDispatcher::OnWriteValueError(int thread_id, |
| 430 int request_id, |
| 431 BluetoothError error_type, |
| 432 const std::string& error_message) { |
| 433 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; |
| 434 |
| 435 pending_write_value_requests_.Lookup(request_id) |
| 436 ->onError( |
| 437 new WebBluetoothError(WebBluetoothErrorFromBluetoothError(error_type), |
| 438 WebString::fromUTF8(error_message))); |
| 439 |
| 440 pending_write_value_requests_.Remove(request_id); |
| 441 } |
| 442 |
| 407 } // namespace content | 443 } // namespace content |
| OLD | NEW |