| 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 c1a2395c4f2bb918ab826e0a4242535217dbd999..bc6674b44d6b7601534893311c29cc49ab5376c3 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;
|
| @@ -315,6 +317,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.";
|
| +}
|
| +
|
| static scoped_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter(
|
| const std::vector<BluetoothScanFilter>& filters) {
|
| std::set<BluetoothUUID> services;
|
| @@ -685,6 +696,97 @@ 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);
|
| +
|
| + // Check if already subscribed to 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_StartNotificationsSuccess(thread_id, request_id));
|
| + return;
|
| + }
|
| +
|
| + // TODO(ortuno): Check if notify/indicate bit is set.
|
| +
|
| + 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);
|
| +
|
| + CHECK(device_iter != service_to_device_.end());
|
| +
|
| + device::BluetoothDevice* device =
|
| + 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) {
|
| @@ -914,6 +1016,33 @@ void BluetoothDispatcherHost::OnWriteValueFailed(
|
| TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_WRITE)));
|
| }
|
|
|
| +void BluetoothDispatcherHost::OnStartNotifySessionSuccess(
|
| + int thread_id,
|
| + int request_id,
|
| + scoped_ptr<device::BluetoothGattNotifySession> notify_session) {
|
| + 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.
|
| + 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();
|
| }
|
|
|