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 a2c26ec8f833135eee8edafe1cae370e840a3b33..062088d3b6c48c4f556d25b177ef9067e6d4515d 100644 |
| --- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| +++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| @@ -58,6 +58,7 @@ bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_ConnectGATT, OnConnectGATT) |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService) |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic) |
| + IPC_MESSAGE_HANDLER(BluetoothHostMsg_ReadValue, OnReadValue) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| return handled; |
| @@ -194,10 +195,21 @@ void BluetoothDispatcherHost::OnGetCharacteristic( |
| for (BluetoothGattCharacteristic* characteristic : |
| service->GetCharacteristics()) { |
| if (characteristic->GetUUID().canonical_value() == characteristic_uuid) { |
| + const std::string& characteristic_instance_id = |
| + characteristic->GetIdentifier(); |
| + |
| + auto insert_result = characteristic_to_service_.insert( |
| + make_pair(characteristic_instance_id, service_instance_id)); |
| + |
| + // If the characteristic existed already check that service_instance_id is |
| + // the same. |
| + if (!insert_result.second) |
| + DCHECK(insert_result.first->second == service_instance_id); |
| + |
| // TODO(ortuno): Use generated instance ID instead. |
| // https://crbug.com/495379 |
| Send(new BluetoothMsg_GetCharacteristicSuccess( |
| - thread_id, request_id, characteristic->GetIdentifier())); |
| + thread_id, request_id, characteristic_instance_id)); |
| return; |
| } |
| } |
| @@ -205,6 +217,65 @@ void BluetoothDispatcherHost::OnGetCharacteristic( |
| BluetoothError::NOT_FOUND)); |
| } |
| +void BluetoothDispatcherHost::OnReadValue( |
| + int thread_id, |
| + int request_id, |
| + const std::string& characteristic_instance_id) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + auto characteristic_iter = |
| + characteristic_to_service_.find(characteristic_instance_id); |
| + // A characteristic_instance_id not in the map implies a hostile renderer |
| + // because a renderer obtains the characteristic id from this class and |
| + // it will be added to the map at that time. |
| + if (characteristic_iter == characteristic_to_service_.end()) { |
| + // Kill the renderer |
| + bad_message::ReceivedBadMessage(this, |
| + bad_message::BDH_INVALID_CHARACTERISTIC_ID); |
| + return; |
| + } |
| + const std::string& service_instance_id = characteristic_iter->second; |
| + |
| + auto device_iter = service_to_device_.find(service_instance_id); |
| + // A service_instance_id not in the map implies a hostile renderer |
| + // because a renderer obtains the service id from this class and |
| + // it will be added to the map at that time. |
| + if (device_iter == service_to_device_.end()) { |
| + // Kill the renderer |
| + bad_message::ReceivedBadMessage(this, bad_message::BDH_INVALID_SERVICE_ID); |
| + return; |
| + } |
| + |
| + device::BluetoothDevice* device = |
| + adapter_->GetDevice(device_iter->second /* device_instance_id */); |
| + if (device == nullptr) { |
| + Send(new BluetoothMsg_ReadCharacteristicValueError( |
| + thread_id, request_id, BluetoothError::NETWORK_ERROR)); |
| + return; |
| + } |
| + |
| + BluetoothGattService* service = device->GetGattService(service_instance_id); |
| + if (service == nullptr) { |
| + Send(new BluetoothMsg_ReadCharacteristicValueError( |
| + thread_id, request_id, BluetoothError::NETWORK_ERROR)); |
|
Jeffrey Yasskin
2015/06/10 21:03:45
Hm, I'm not sure this is notionally a network erro
ortuno
2015/06/10 22:03:01
Added a TODO for when the error is implemented.
|
| + return; |
| + } |
| + |
| + BluetoothGattCharacteristic* characteristic = |
| + service->GetCharacteristic(characteristic_instance_id); |
| + if (characteristic == nullptr) { |
| + Send(new BluetoothMsg_ReadCharacteristicValueError( |
| + thread_id, request_id, BluetoothError::NETWORK_ERROR)); |
| + return; |
| + } |
| + |
| + characteristic->ReadRemoteCharacteristic( |
| + base::Bind(&BluetoothDispatcherHost::OnCharacteristicValueRead, |
| + weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), |
| + base::Bind(&BluetoothDispatcherHost::OnCharacteristicReadValueError, |
| + weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); |
| +} |
| + |
| void BluetoothDispatcherHost::OnDiscoverySessionStarted( |
| int thread_id, |
| int request_id, |
| @@ -329,4 +400,20 @@ void BluetoothDispatcherHost::OnServicesDiscovered( |
| BluetoothError::NOT_FOUND)); |
| } |
| +void BluetoothDispatcherHost::OnCharacteristicValueRead( |
| + int thread_id, |
| + int request_id, |
| + const std::vector<uint8>& value) { |
| + Send(new BluetoothMsg_ReadCharacteristicValueSuccess(thread_id, request_id, |
| + value)); |
| +} |
| + |
| +void BluetoothDispatcherHost::OnCharacteristicReadValueError( |
| + int thread_id, |
| + int request_id, |
| + device::BluetoothGattService::GattErrorCode) { |
| + Send(new BluetoothMsg_ReadCharacteristicValueError( |
| + thread_id, request_id, BluetoothError::NETWORK_ERROR)); |
|
Jeffrey Yasskin
2015/06/10 21:03:45
https://webbluetoothcg.github.io/web-bluetooth/#er
ortuno
2015/06/10 22:03:01
I added a TODO here as well. The CL that introduce
Jeffrey Yasskin
2015/06/10 22:55:49
Sure.
|
| +} |
| + |
| } // namespace content |