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/bluetooth_dispatcher.h" | 5 #include "content/renderer/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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError, | 136 IPC_MESSAGE_HANDLER(BluetoothMsg_GetCharacteristicError, |
137 OnGetCharacteristicError); | 137 OnGetCharacteristicError); |
138 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess, | 138 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueSuccess, |
139 OnReadValueSuccess); | 139 OnReadValueSuccess); |
140 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError, | 140 IPC_MESSAGE_HANDLER(BluetoothMsg_ReadCharacteristicValueError, |
141 OnReadValueError); | 141 OnReadValueError); |
142 IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueSuccess, | 142 IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueSuccess, |
143 OnWriteValueSuccess); | 143 OnWriteValueSuccess); |
144 IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueError, | 144 IPC_MESSAGE_HANDLER(BluetoothMsg_WriteCharacteristicValueError, |
145 OnWriteValueError); | 145 OnWriteValueError); |
| 146 IPC_MESSAGE_HANDLER(BluetoothMsg_StartNotificationsSuccess, |
| 147 OnStartNotificationsSuccess) |
| 148 IPC_MESSAGE_HANDLER(BluetoothMsg_StartNotificationsError, |
| 149 OnStartNotificationsError) |
| 150 IPC_MESSAGE_HANDLER(BluetoothMsg_StopNotificationsSuccess, |
| 151 OnStopNotificationsSuccess) |
146 IPC_MESSAGE_UNHANDLED(handled = false) | 152 IPC_MESSAGE_UNHANDLED(handled = false) |
147 IPC_END_MESSAGE_MAP() | 153 IPC_END_MESSAGE_MAP() |
148 DCHECK(handled) << "Unhandled message:" << msg.type(); | 154 DCHECK(handled) << "Unhandled message:" << msg.type(); |
149 } | 155 } |
150 | 156 |
151 void BluetoothDispatcher::requestDevice( | 157 void BluetoothDispatcher::requestDevice( |
152 int frame_routing_id, | 158 int frame_routing_id, |
153 const WebRequestDeviceOptions& options, | 159 const WebRequestDeviceOptions& options, |
154 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { | 160 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { |
155 int request_id = pending_requests_.Add(callbacks); | 161 int request_id = pending_requests_.Add(callbacks); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 void BluetoothDispatcher::writeValue( | 224 void BluetoothDispatcher::writeValue( |
219 const blink::WebString& characteristic_instance_id, | 225 const blink::WebString& characteristic_instance_id, |
220 const std::vector<uint8_t>& value, | 226 const std::vector<uint8_t>& value, |
221 blink::WebBluetoothWriteValueCallbacks* callbacks) { | 227 blink::WebBluetoothWriteValueCallbacks* callbacks) { |
222 int request_id = pending_write_value_requests_.Add(callbacks); | 228 int request_id = pending_write_value_requests_.Add(callbacks); |
223 | 229 |
224 Send(new BluetoothHostMsg_WriteValue( | 230 Send(new BluetoothHostMsg_WriteValue( |
225 CurrentWorkerId(), request_id, characteristic_instance_id.utf8(), value)); | 231 CurrentWorkerId(), request_id, characteristic_instance_id.utf8(), value)); |
226 } | 232 } |
227 | 233 |
| 234 void BluetoothDispatcher::startNotifications( |
| 235 const blink::WebString& characteristic_instance_id, |
| 236 blink::WebBluetoothStartNotificationsCallbacks* callbacks) { |
| 237 int request_id = pending_start_notifications_requests_.Add(callbacks); |
| 238 |
| 239 Send(new BluetoothHostMsg_StartNotifications( |
| 240 CurrentWorkerId(), request_id, characteristic_instance_id.utf8())); |
| 241 } |
| 242 |
| 243 void BluetoothDispatcher::stopNotifications( |
| 244 const blink::WebString& characteristic_instance_id, |
| 245 blink::WebBluetoothStopNotificationsCallbacks* callbacks) { |
| 246 int request_id = pending_stop_notifications_requests_.Add(callbacks); |
| 247 |
| 248 Send(new BluetoothHostMsg_StopNotifications( |
| 249 CurrentWorkerId(), request_id, characteristic_instance_id.utf8())); |
| 250 } |
| 251 |
228 void BluetoothDispatcher::WillStopCurrentWorkerThread() { | 252 void BluetoothDispatcher::WillStopCurrentWorkerThread() { |
229 delete this; | 253 delete this; |
230 } | 254 } |
231 | 255 |
232 void BluetoothDispatcher::OnRequestDeviceSuccess( | 256 void BluetoothDispatcher::OnRequestDeviceSuccess( |
233 int thread_id, | 257 int thread_id, |
234 int request_id, | 258 int request_id, |
235 const BluetoothDevice& device) { | 259 const BluetoothDevice& device) { |
236 DCHECK(pending_requests_.Lookup(request_id)) << request_id; | 260 DCHECK(pending_requests_.Lookup(request_id)) << request_id; |
237 | 261 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 int request_id, | 403 int request_id, |
380 WebBluetoothError error) { | 404 WebBluetoothError error) { |
381 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; | 405 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; |
382 | 406 |
383 pending_write_value_requests_.Lookup(request_id) | 407 pending_write_value_requests_.Lookup(request_id) |
384 ->onError(WebBluetoothError(error)); | 408 ->onError(WebBluetoothError(error)); |
385 | 409 |
386 pending_write_value_requests_.Remove(request_id); | 410 pending_write_value_requests_.Remove(request_id); |
387 } | 411 } |
388 | 412 |
| 413 void BluetoothDispatcher::OnStartNotificationsSuccess(int thread_id, |
| 414 int request_id) { |
| 415 DCHECK(pending_start_notifications_requests_.Lookup(request_id)) |
| 416 << request_id; |
| 417 |
| 418 pending_start_notifications_requests_.Lookup(request_id)->onSuccess(); |
| 419 |
| 420 pending_start_notifications_requests_.Remove(request_id); |
| 421 } |
| 422 |
| 423 void BluetoothDispatcher::OnStartNotificationsError(int thread_id, |
| 424 int request_id, |
| 425 WebBluetoothError error) { |
| 426 DCHECK(pending_start_notifications_requests_.Lookup(request_id)) |
| 427 << request_id; |
| 428 |
| 429 pending_start_notifications_requests_.Lookup(request_id)->onError(error); |
| 430 |
| 431 pending_start_notifications_requests_.Remove(request_id); |
| 432 } |
| 433 |
| 434 void BluetoothDispatcher::OnStopNotificationsSuccess(int thread_id, |
| 435 int request_id) { |
| 436 DCHECK(pending_stop_notifications_requests_.Lookup(request_id)) << request_id; |
| 437 |
| 438 pending_stop_notifications_requests_.Lookup(request_id)->onSuccess(); |
| 439 |
| 440 pending_stop_notifications_requests_.Remove(request_id); |
| 441 } |
| 442 |
389 } // namespace content | 443 } // namespace content |
OLD | NEW |