Chromium Code Reviews| Index: content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| diff --git a/content/browser/bluetooth/bluetooth_dispatcher_host.cc b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| index c11c203b13ee8b60fef83d7ab6a95605b04b30db..d462ceb5e00350d8a10b819df2ef4e7f6826f62a 100644 |
| --- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| +++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| @@ -10,10 +10,12 @@ |
| #include "device/bluetooth/bluetooth_adapter_factory.h" |
| #include "device/bluetooth/bluetooth_device.h" |
| #include "device/bluetooth/bluetooth_discovery_session.h" |
| +#include "device/bluetooth/bluetooth_gatt_characteristic.h" |
| #include "device/bluetooth/bluetooth_gatt_service.h" |
| using device::BluetoothAdapter; |
| using device::BluetoothAdapterFactory; |
| +using device::BluetoothGattCharacteristic; |
| using device::BluetoothGattService; |
| namespace content { |
| @@ -54,6 +56,7 @@ bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice) |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_ConnectGATT, OnConnectGATT) |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService) |
| + IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| return handled; |
| @@ -149,6 +152,45 @@ void BluetoothDispatcherHost::OnGetPrimaryService( |
| base::TimeDelta::FromSeconds(current_delay_time_)); |
| } |
| +void BluetoothDispatcherHost::OnGetCharacteristic( |
| + int thread_id, |
| + int request_id, |
| + const std::string& service_instance_id, |
| + const std::string& characteristic_uuid) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + // TODO(ortuno): Check if domain has access to device. |
| + // https://crbug.com/493459 |
| + device::BluetoothDevice* device = |
| + adapter_->GetDevice(service_to_device_[service_instance_id]); |
|
Jeffrey Yasskin
2015/06/02 22:12:28
Generally avoid using operator[] on a map to check
ortuno
2015/06/03 20:27:22
Done.
|
| + if (device == NULL) { |
| + Send(new BluetoothMsg_GetCharacteristicError( |
| + thread_id, request_id, BluetoothError::NETWORK_ERROR)); |
| + return; |
| + } |
| + // TODO(ortuno): Check if domain has access to service |
| + // http://crbug.com/493460 |
| + device::BluetoothGattService* service = |
| + device->GetGattService(service_instance_id); |
| + if (!service) { |
| + Send(new BluetoothMsg_GetCharacteristicError( |
| + thread_id, request_id, BluetoothError::NETWORK_ERROR)); |
| + return; |
| + } |
| + |
| + for (BluetoothGattCharacteristic* characteristic : |
| + service->GetCharacteristics()) { |
| + if (characteristic->GetUUID().canonical_value() == characteristic_uuid) { |
| + // TODO(ortuno): Use generated instance ID instead. |
| + // https://crbug.com/495379 |
| + Send(new BluetoothMsg_GetCharacteristicSuccess( |
| + thread_id, request_id, characteristic->GetIdentifier())); |
| + return; |
| + } |
| + } |
| + Send(new BluetoothMsg_GetCharacteristicError(thread_id, request_id, |
| + BluetoothError::NOT_FOUND)); |
| +} |
| + |
| void BluetoothDispatcherHost::OnDiscoverySessionStarted( |
| int thread_id, |
| int request_id, |
| @@ -231,7 +273,7 @@ void BluetoothDispatcherHost::OnCreateGATTConnectionError( |
| int request_id, |
| const std::string& device_instance_id, |
| device::BluetoothDevice::ConnectErrorCode error_code) { |
| - // There was an error creating the ATT Bearer so we reject with |
| + // There was an error 'creating the ATT Bearer so we reject with |
|
Jeffrey Yasskin
2015/06/02 22:12:29
s/'//
ortuno
2015/06/03 20:27:22
Done.
|
| // NetworkError. |
| // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-connectgatt |
| Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id, |
| @@ -253,8 +295,13 @@ void BluetoothDispatcherHost::OnServicesDiscovered( |
| } |
| for (BluetoothGattService* service : device->GetGattServices()) { |
| if (service->GetUUID().canonical_value() == service_uuid) { |
| + // TODO(ortuno): Use generated instance ID instead. |
| + // https://crbug.com/495379 |
| + const std::string& service_identifier = service->GetIdentifier(); |
| + service_to_device_.insert( |
| + make_pair(service_identifier, device_instance_id)); |
| Send(new BluetoothMsg_GetPrimaryServiceSuccess(thread_id, request_id, |
| - service->GetIdentifier())); |
| + service_identifier)); |
| return; |
| } |
| } |