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 unsigned char* bytes, | |
243 unsigned byteLength, | |
244 blink::WebBluetoothWriteValueCallbacks* callbacks) { | |
245 int request_id = pending_write_value_requests_.Add(callbacks); | |
246 std::vector<uint8_t> value(byteLength); | |
Jeffrey Yasskin
2015/07/07 00:31:42
You can initialize this with "std::vector<uint8_t>
| |
247 for (unsigned i = 0; i < byteLength; i++) | |
248 value[i] = bytes[i]; | |
249 | |
250 Send(new BluetoothHostMsg_WriteValue( | |
251 CurrentWorkerId(), request_id, characteristic_instance_id.utf8(), value)); | |
252 } | |
253 | |
236 void BluetoothDispatcher::OnWorkerRunLoopStopped() { | 254 void BluetoothDispatcher::OnWorkerRunLoopStopped() { |
237 delete this; | 255 delete this; |
238 } | 256 } |
239 | 257 |
240 void BluetoothDispatcher::OnRequestDeviceSuccess( | 258 void BluetoothDispatcher::OnRequestDeviceSuccess( |
241 int thread_id, | 259 int thread_id, |
242 int request_id, | 260 int request_id, |
243 const BluetoothDevice& device) { | 261 const BluetoothDevice& device) { |
244 DCHECK(pending_requests_.Lookup(request_id)) << request_id; | 262 DCHECK(pending_requests_.Lookup(request_id)) << request_id; |
245 | 263 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 pending_read_value_requests_.Lookup(request_id) | 415 pending_read_value_requests_.Lookup(request_id) |
398 ->onError(new WebBluetoothError( | 416 ->onError(new WebBluetoothError( |
399 // TODO(ortuno): Return more descriptive error messages. | 417 // TODO(ortuno): Return more descriptive error messages. |
400 // http://crbug.com/490419 | 418 // http://crbug.com/490419 |
401 WebBluetoothErrorFromBluetoothError(error_type), | 419 WebBluetoothErrorFromBluetoothError(error_type), |
402 WebString::fromUTF8(error_message))); | 420 WebString::fromUTF8(error_message))); |
403 | 421 |
404 pending_read_value_requests_.Remove(request_id); | 422 pending_read_value_requests_.Remove(request_id); |
405 } | 423 } |
406 | 424 |
425 void BluetoothDispatcher::OnWriteValueSuccess(int thread_id, int request_id) { | |
426 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; | |
427 | |
428 pending_write_value_requests_.Lookup(request_id)->onSuccess(); | |
429 | |
430 pending_write_value_requests_.Remove(request_id); | |
431 } | |
432 | |
433 void BluetoothDispatcher::OnWriteValueError(int thread_id, | |
434 int request_id, | |
435 BluetoothError error_type, | |
436 const std::string& error_message) { | |
437 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; | |
438 | |
439 pending_write_value_requests_.Lookup(request_id) | |
440 ->onError( | |
441 new WebBluetoothError(WebBluetoothErrorFromBluetoothError(error_type), | |
442 WebString::fromUTF8(error_message))); | |
443 | |
444 pending_write_value_requests_.Remove(request_id); | |
445 } | |
446 | |
407 } // namespace content | 447 } // namespace content |
OLD | NEW |