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 75556c0b319d3f4b7bc0656813429e7fd04545a1..8a2f29229fcca69599da0ffb0e8e0ba49745bced 100644 |
| --- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| +++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| @@ -199,6 +199,8 @@ bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic) |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_ReadValue, OnReadValue) |
| IPC_MESSAGE_HANDLER(BluetoothHostMsg_WriteValue, OnWriteValue) |
| + IPC_MESSAGE_HANDLER(BluetoothHostMsg_StartNotifications, OnStartNotifications) |
| + IPC_MESSAGE_HANDLER(BluetoothHostMsg_StopNotifications, OnStopNotifications) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| return handled; |
| @@ -347,6 +349,15 @@ void BluetoothDispatcherHost::DeviceRemoved(device::BluetoothAdapter* adapter, |
| } |
| } |
| +void BluetoothDispatcherHost::GattCharacteristicValueChanged( |
| + device::BluetoothAdapter* adapter, |
| + device::BluetoothGattCharacteristic* characteristic, |
| + const std::vector<uint8>& value) { |
| + // TODO(ortuno): Notify renderer the characteristic changed. |
| + // http://crbug.com/529560 |
| + VLOG(1) << "Characteristic updated."; |
| +} |
| + |
| void BluetoothDispatcherHost::OnRequestDevice( |
| int thread_id, |
| int request_id, |
| @@ -694,6 +705,91 @@ void BluetoothDispatcherHost::OnWriteValue( |
| weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); |
| } |
| +void BluetoothDispatcherHost::OnStartNotifications( |
| + int thread_id, |
| + int request_id, |
| + const std::string& characteristic_instance_id) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + RecordWebBluetoothFunctionCall( |
| + UMAWebBluetoothFunction::CHARACTERISTIC_START_NOTIFICATIONS); |
| + |
| + // BluetoothDispatcher will never send a request for a characteristic |
| + // already subscribed to notifications. |
| + DCHECK( |
|
scheib
2015/10/01 22:05:22
It's a compromised renderer then, right? So this s
ortuno
2015/10/03 04:03:03
Done.
|
| + characteristic_id_to_notify_session_.find(characteristic_instance_id) == |
| + characteristic_id_to_notify_session_.end()); |
| + |
| + // TODO(ortuno): Check if notify/indicate bit is set. |
|
scheib
2015/10/01 22:05:22
Have an issue so we track to follow up on this.
ortuno
2015/10/03 04:03:03
Done.
|
| + |
| + auto characteristic_iter = |
| + characteristic_to_service_.find(characteristic_instance_id); |
| + // A characteristic_instance_id not in the map implies a hostile renderer |
|
scheib
2015/10/01 22:05:22
3rd time we're copying this block, so let's move e
ortuno
2015/10/03 04:03:03
Done.
|
| + // 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); |
| + CHECK(device_iter != service_to_device_.end()); |
| + |
| + device::BluetoothDevice* device = |
|
scheib
2015/10/01 22:05:22
In a later clean up patch we should refactor out t
ortuno
2015/10/03 04:03:03
I already have a patch :P
https://codereview.chro
|
| + adapter_->GetDevice(device_iter->second /* device_instance_id */); |
| + if (device == nullptr) { // See "NETWORK_ERROR Note" above. |
| + RecordStartNotificationsOutcome(UMAGATTOperationOutcome::NO_DEVICE); |
| + Send(new BluetoothMsg_StartNotificationsError( |
| + thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); |
| + return; |
| + } |
| + |
| + BluetoothGattService* service = device->GetGattService(service_instance_id); |
| + if (service == nullptr) { |
| + RecordStartNotificationsOutcome(UMAGATTOperationOutcome::NO_SERVICE); |
| + Send(new BluetoothMsg_StartNotificationsError( |
| + thread_id, request_id, WebBluetoothError::ServiceNoLongerExists)); |
| + return; |
| + } |
| + |
| + BluetoothGattCharacteristic* characteristic = |
| + service->GetCharacteristic(characteristic_instance_id); |
| + if (characteristic == nullptr) { |
| + RecordStartNotificationsOutcome(UMAGATTOperationOutcome::NO_CHARACTERISTIC); |
| + Send(new BluetoothMsg_StartNotificationsError( |
| + thread_id, request_id, |
| + WebBluetoothError::CharacteristicNoLongerExists)); |
| + return; |
| + } |
| + |
| + characteristic->StartNotifySession( |
| + base::Bind(&BluetoothDispatcherHost::OnStartNotifySessionSuccess, |
| + weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), |
| + base::Bind(&BluetoothDispatcherHost::OnStartNotifySessionFailed, |
| + weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); |
| +} |
| +void BluetoothDispatcherHost::OnStopNotifications( |
| + int thread_id, |
| + int request_id, |
| + const std::string& characteristic_instance_id) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + RecordWebBluetoothFunctionCall( |
| + UMAWebBluetoothFunction::CHARACTERISTIC_STOP_NOTIFICATIONS); |
| + |
| + auto notify_session_iter = |
| + characteristic_id_to_notify_session_.find(characteristic_instance_id); |
| + if (notify_session_iter == characteristic_id_to_notify_session_.end()) { |
| + Send(new BluetoothMsg_StopNotificationsSuccess(thread_id, request_id)); |
| + return; |
| + } |
| + notify_session_iter->second->Stop( |
| + base::Bind(&BluetoothDispatcherHost::OnStopNotifySession, |
| + weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, |
| + characteristic_instance_id)); |
| +} |
| + |
| void BluetoothDispatcherHost::OnDiscoverySessionStarted( |
| int chooser_id, |
| scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { |
| @@ -923,6 +1019,35 @@ void BluetoothDispatcherHost::OnWriteValueFailed( |
| TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_WRITE))); |
| } |
| +void BluetoothDispatcherHost::OnStartNotifySessionSuccess( |
| + int thread_id, |
| + int request_id, |
| + scoped_ptr<device::BluetoothGattNotifySession> notify_session) { |
| + RecordStartNotificationsOutcome(UMAGATTOperationOutcome::SUCCESS); |
| + |
| + characteristic_id_to_notify_session_.insert( |
| + notify_session->GetCharacteristicIdentifier(), notify_session.Pass()); |
| + Send(new BluetoothMsg_StartNotificationsSuccess(thread_id, request_id)); |
| +} |
| + |
| +void BluetoothDispatcherHost::OnStartNotifySessionFailed( |
| + int thread_id, |
| + int request_id, |
| + device::BluetoothGattService::GattErrorCode error_code) { |
| + // TranslateGATTError calls RecordGATTOperationOutcome. |
|
scheib
2015/10/01 22:05:22
In a clean up CL we should remove comments and ren
ortuno
2015/10/03 04:03:03
http://crbug.com/538876
|
| + Send(new BluetoothMsg_StartNotificationsError( |
| + thread_id, request_id, |
| + TranslateGATTError(error_code, UMAGATTOperation::START_NOTIFICATIONS))); |
| +} |
| + |
| +void BluetoothDispatcherHost::OnStopNotifySession( |
| + int thread_id, |
| + int request_id, |
| + const std::string& characteristic_instance_id) { |
| + characteristic_id_to_notify_session_.erase(characteristic_instance_id); |
| + Send(new BluetoothMsg_StopNotificationsSuccess(thread_id, request_id)); |
| +} |
| + |
| void BluetoothDispatcherHost::ShowBluetoothOverviewLink() { |
| NOTIMPLEMENTED(); |
| } |