Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Unified Diff: content/browser/bluetooth/bluetooth_dispatcher_host.cc

Issue 1120373004: bluetooth: Browser-side implementation of connectGATT. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-request-device-implementation
Patch Set: Address jyasskin's comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 f6042833937de7839ffda678c25e17d266716c0a..fe067a12ca1103e3e113291942bc1737f8b5f9ad 100644
--- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc
+++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc
@@ -100,10 +100,27 @@ void BluetoothDispatcherHost::OnConnectGATT(
int request_id,
const std::string& device_instance_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- // TODO(ortuno): Add actual implementation of connectGATT. This needs to be
- // done after the "allowed devices map" is implemented.
- Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id,
- device_instance_id));
+ // TODO(ortuno): Right now it's pointless to check if the domain has access to
+ // the device, because any domain can connect to any device. But once
+ // permissions are implemented we should check that the domain has access to
+ // the device. https://crbug.com/484745
+ device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id);
+ if (device == NULL) {
+ // Device could have gone out of range so it's no longer in
+ // BluetoothAdapter. Since we can't create a ATT Bearer without a device we
+ // reject with NetworkError.
+ // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-connectgatt
+ Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id,
+ BluetoothError::NETWORK_ERROR));
+ return;
+ }
+ device->CreateGattConnection(
+ base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated,
+ weak_ptr_factory_.GetWeakPtr(), thread_id, request_id,
+ device_instance_id),
+ base::Bind(&BluetoothDispatcherHost::OnCreateGATTConnectionError,
+ weak_ptr_factory_.GetWeakPtr(), thread_id, request_id,
+ device_instance_id));
}
void BluetoothDispatcherHost::OnDiscoverySessionStarted(
@@ -172,4 +189,27 @@ void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id,
BluetoothError::NOT_FOUND));
}
+void BluetoothDispatcherHost::OnGATTConnectionCreated(
+ int thread_id,
+ int request_id,
+ const std::string& device_instance_id,
+ scoped_ptr<device::BluetoothGattConnection> connection) {
+ // TODO(ortuno): Save the BluetoothGattConnection so we can disconnect
+ // from it.
+ Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id,
+ device_instance_id));
+}
+
+void BluetoothDispatcherHost::OnCreateGATTConnectionError(
+ int thread_id,
+ 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
+ // NetworkError.
+ // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-connectgatt
+ Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id,
+ BluetoothError::NETWORK_ERROR));
+}
+
} // namespace content
« no previous file with comments | « content/browser/bluetooth/bluetooth_dispatcher_host.h ('k') | content/child/bluetooth/bluetooth_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698