| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_UNHANDLED(handled = false) | 146 IPC_MESSAGE_UNHANDLED(handled = false) |
| 147 IPC_END_MESSAGE_MAP() | 147 IPC_END_MESSAGE_MAP() |
| 148 DCHECK(handled) << "Unhandled message:" << msg.type(); | 148 DCHECK(handled) << "Unhandled message:" << msg.type(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void BluetoothDispatcher::requestDevice( | 151 void BluetoothDispatcher::requestDevice( |
| 152 int frame_routing_id, |
| 152 const WebRequestDeviceOptions& options, | 153 const WebRequestDeviceOptions& options, |
| 153 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { | 154 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { |
| 154 int request_id = pending_requests_.Add(callbacks); | 155 int request_id = pending_requests_.Add(callbacks); |
| 155 | 156 |
| 156 // Convert |options| to its IPC form. | 157 // Convert |options| to its IPC form. |
| 157 std::vector<content::BluetoothScanFilter> filters(options.filters.size()); | 158 std::vector<content::BluetoothScanFilter> filters(options.filters.size()); |
| 158 for (size_t i = 0; i < options.filters.size(); ++i) { | 159 for (size_t i = 0; i < options.filters.size(); ++i) { |
| 159 const WebBluetoothScanFilter& web_filter = options.filters[i]; | 160 const WebBluetoothScanFilter& web_filter = options.filters[i]; |
| 160 BluetoothScanFilter& filter = filters[i]; | 161 BluetoothScanFilter& filter = filters[i]; |
| 161 filter.services.reserve(web_filter.services.size()); | 162 filter.services.reserve(web_filter.services.size()); |
| 162 for (const WebString& service : web_filter.services) { | 163 for (const WebString& service : web_filter.services) { |
| 163 filter.services.push_back(device::BluetoothUUID(service.utf8())); | 164 filter.services.push_back(device::BluetoothUUID(service.utf8())); |
| 164 } | 165 } |
| 165 } | 166 } |
| 166 std::vector<device::BluetoothUUID> optional_services; | 167 std::vector<device::BluetoothUUID> optional_services; |
| 167 optional_services.reserve(options.optionalServices.size()); | 168 optional_services.reserve(options.optionalServices.size()); |
| 168 for (const WebString& optional_service : options.optionalServices) { | 169 for (const WebString& optional_service : options.optionalServices) { |
| 169 optional_services.push_back(device::BluetoothUUID(optional_service.utf8())); | 170 optional_services.push_back(device::BluetoothUUID(optional_service.utf8())); |
| 170 } | 171 } |
| 171 | 172 |
| 172 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id, | 173 Send(new BluetoothHostMsg_RequestDevice(CurrentWorkerId(), request_id, |
| 173 filters, optional_services)); | 174 frame_routing_id, filters, |
| 175 optional_services)); |
| 174 } | 176 } |
| 175 | 177 |
| 176 void BluetoothDispatcher::connectGATT( | 178 void BluetoothDispatcher::connectGATT( |
| 177 const blink::WebString& device_instance_id, | 179 const blink::WebString& device_instance_id, |
| 178 blink::WebBluetoothConnectGATTCallbacks* callbacks) { | 180 blink::WebBluetoothConnectGATTCallbacks* callbacks) { |
| 179 int request_id = pending_connect_requests_.Add(callbacks); | 181 int request_id = pending_connect_requests_.Add(callbacks); |
| 180 Send(new BluetoothHostMsg_ConnectGATT(CurrentWorkerId(), request_id, | 182 Send(new BluetoothHostMsg_ConnectGATT(CurrentWorkerId(), request_id, |
| 181 device_instance_id.utf8())); | 183 device_instance_id.utf8())); |
| 182 } | 184 } |
| 183 | 185 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 WebBluetoothError error) { | 380 WebBluetoothError error) { |
| 379 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; | 381 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; |
| 380 | 382 |
| 381 pending_write_value_requests_.Lookup(request_id) | 383 pending_write_value_requests_.Lookup(request_id) |
| 382 ->onError(new WebBluetoothError(error)); | 384 ->onError(new WebBluetoothError(error)); |
| 383 | 385 |
| 384 pending_write_value_requests_.Remove(request_id); | 386 pending_write_value_requests_.Remove(request_id); |
| 385 } | 387 } |
| 386 | 388 |
| 387 } // namespace content | 389 } // namespace content |
| OLD | NEW |