Chromium Code Reviews| Index: content/browser/bluetooth/web_bluetooth_service_impl.cc |
| diff --git a/content/browser/bluetooth/web_bluetooth_service_impl.cc b/content/browser/bluetooth/web_bluetooth_service_impl.cc |
| index bb410e7e9f60ade0a48b30e3beb7af996a02bd76..450045e744ffc3f899770176daafa430cb590f9c 100644 |
| --- a/content/browser/bluetooth/web_bluetooth_service_impl.cc |
| +++ b/content/browser/bluetooth/web_bluetooth_service_impl.cc |
| @@ -233,9 +233,6 @@ void WebBluetoothServiceImpl::DeviceChanged(device::BluetoothAdapter* adapter, |
| base::Optional<WebBluetoothDeviceId> device_id = |
| connected_devices_->CloseConnectionToDeviceWithAddress( |
| device->GetAddress()); |
| - if (device_id && client_) { |
| - client_->GattServerDisconnected(device_id.value()); |
| - } |
| } |
| } |
| @@ -292,18 +289,13 @@ void WebBluetoothServiceImpl::GattCharacteristicValueChanged( |
| void WebBluetoothServiceImpl::NotifyCharacteristicValueChanged( |
| const std::string& characteristic_instance_id, |
| const std::vector<uint8_t>& value) { |
| - if (client_) { |
| - client_->RemoteCharacteristicValueChanged(characteristic_instance_id, |
| - value); |
| + auto iter = |
| + characteristic_id_to_notify_session_.find(characteristic_instance_id); |
| + if (iter != characteristic_id_to_notify_session_.end()) { |
| + iter->second.second->RemoteCharacteristicValueChanged(value); |
| } |
| } |
| -void WebBluetoothServiceImpl::SetClient( |
| - blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) { |
| - DCHECK(!client_.get()); |
| - client_.Bind(std::move(client)); |
| -} |
| - |
| void WebBluetoothServiceImpl::RequestDevice( |
| blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, |
| const RequestDeviceCallback& callback) { |
| @@ -338,13 +330,17 @@ void WebBluetoothServiceImpl::RemoteServerConnect( |
| if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| RecordConnectGATTOutcome(query_result.outcome); |
| - callback.Run(query_result.GetWebResult()); |
| + callback.Run( |
| + query_result.GetWebResult(), |
| + nullptr /* blink::mojom::WebBluetoothServerClientAssociatedRequest */); |
|
ortuno
2017/03/01 04:52:05
optional: you can just use client_request.
juncai
2017/03/02 03:23:42
Done.
|
| return; |
| } |
| if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { |
| DVLOG(1) << "Already connected."; |
| - callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
| + callback.Run( |
| + blink::mojom::WebBluetoothResult::SUCCESS, |
| + nullptr /* blink::mojom::WebBluetoothServerClientAssociatedRequest */); |
| return; |
| } |
| @@ -689,10 +685,12 @@ void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications( |
| auto iter = |
| characteristic_id_to_notify_session_.find(characteristic_instance_id); |
| if (iter != characteristic_id_to_notify_session_.end() && |
| - iter->second->IsActive()) { |
| + iter->second.first->IsActive()) { |
| // If the frame has already started notifications and the notifications |
| // are active we return SUCCESS. |
| - callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
| + callback.Run( |
| + blink::mojom::WebBluetoothResult::SUCCESS, nullptr |
| + /* blink::mojom::WebBluetoothCharacteristicClientAssociatedRequest */); |
| return; |
| } |
| @@ -705,7 +703,9 @@ void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications( |
| if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| RecordStartNotificationsOutcome(query_result.outcome); |
| - callback.Run(query_result.GetWebResult()); |
| + callback.Run( |
| + query_result.GetWebResult(), nullptr |
| + /* blink::mojom::WebBluetoothCharacteristicClientAssociatedRequest */); |
| return; |
| } |
| @@ -714,7 +714,9 @@ void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications( |
| (device::BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY | |
| device::BluetoothRemoteGattCharacteristic::PROPERTY_INDICATE); |
| if (!notify_or_indicate) { |
| - callback.Run(blink::mojom::WebBluetoothResult::GATT_NOT_SUPPORTED); |
| + callback.Run( |
| + blink::mojom::WebBluetoothResult::GATT_NOT_SUPPORTED, nullptr |
| + /* blink::mojom::WebBluetoothCharacteristicClientAssociatedRequest */); |
| return; |
| } |
| @@ -747,7 +749,7 @@ void WebBluetoothServiceImpl::RemoteCharacteristicStopNotifications( |
| callback.Run(); |
| return; |
| } |
| - notify_session_iter->second->Stop(base::Bind( |
| + notify_session_iter->second.first->Stop(base::Bind( |
| &WebBluetoothServiceImpl::OnStopNotifySessionComplete, |
| weak_ptr_factory_.GetWeakPtr(), characteristic_instance_id, callback)); |
| } |
| @@ -957,8 +959,11 @@ void WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess( |
| RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time); |
| RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); |
| - connected_devices_->Insert(device_id, std::move(connection)); |
| - callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
| + blink::mojom::WebBluetoothServerClientAssociatedPtr client; |
|
ortuno
2017/03/01 04:52:05
Seems a bit wasteful to be sending request when th
juncai
2017/03/02 03:23:40
Done.
|
| + callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, |
| + mojo::MakeRequest(&client)); |
| + connected_devices_->Insert(device_id, std::move(connection), |
| + std::move(client)); |
| } |
| void WebBluetoothServiceImpl::OnCreateGATTConnectionFailed( |
| @@ -967,7 +972,9 @@ void WebBluetoothServiceImpl::OnCreateGATTConnectionFailed( |
| device::BluetoothDevice::ConnectErrorCode error_code) { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); |
| - callback.Run(TranslateConnectErrorAndRecord(error_code)); |
| + callback.Run( |
| + TranslateConnectErrorAndRecord(error_code), |
| + nullptr /* blink::mojom::WebBluetoothServerClientAssociatedRequest */); |
| } |
| void WebBluetoothServiceImpl::OnCharacteristicReadValueSuccess( |
| @@ -1010,18 +1017,24 @@ void WebBluetoothServiceImpl::OnStartNotifySessionSuccess( |
| // compilers may evaluate arguments in any order. |
| std::string characteristic_instance_id = |
| notify_session->GetCharacteristicIdentifier(); |
| + |
| + blink::mojom::WebBluetoothCharacteristicClientAssociatedPtr client; |
|
ortuno
2017/03/01 04:52:05
Seems a bit wasteful to be sending request when th
juncai
2017/03/02 03:23:41
Done.
|
| + callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, |
| + mojo::MakeRequest(&client)); |
| // Saving the BluetoothGattNotifySession keeps notifications active. |
| characteristic_id_to_notify_session_[characteristic_instance_id] = |
| - std::move(notify_session); |
| - callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
| + std::make_pair(std::move(notify_session), std::move(client)); |
| } |
| void WebBluetoothServiceImpl::OnStartNotifySessionFailed( |
| const RemoteCharacteristicStartNotificationsCallback& callback, |
| device::BluetoothRemoteGattService::GattErrorCode error_code) { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| - callback.Run(TranslateGATTErrorAndRecord( |
| - error_code, UMAGATTOperation::START_NOTIFICATIONS)); |
| + callback.Run( |
| + TranslateGATTErrorAndRecord(error_code, |
| + UMAGATTOperation::START_NOTIFICATIONS), |
| + nullptr |
| + /* blink::mojom::WebBluetoothCharacteristicClientAssociatedRequest */); |
| } |
| void WebBluetoothServiceImpl::OnStopNotifySessionComplete( |