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

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: Created 5 years, 8 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 b440cdb5c9e84bf16aafa96a7018164b9da9264b..f0c5eb02bd35f2691c864e6e26ecf79b6e5910d7 100644
--- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc
+++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc
@@ -129,12 +129,55 @@ 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.
+
+ // TODO(ortuno): Right now it's pointless to check if the domain has access to
scheib 2015/05/05 04:00:43 Find or file an issue for this security concept, r
+ // 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.
+ BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
+
+ // TODO(ortuno): Instead of iterating through the devices list we should keep
+ // a set and update it based on events from the adapter.
scheib 2015/05/05 04:00:43 Probably we'll keep a map of origins, each with a
+ for (BluetoothAdapter::DeviceList::iterator iter = devices.begin();
+ iter != devices.end(); iter++) {
+ device::BluetoothDevice* device = *iter;
+ if (device->GetAddress() == device_instance_id) {
+ 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));
+ return;
+ }
+ }
+ // TODO(ortuno): Change to NetworkError once it's implemented.
+ Send(new BluetoothMsg_RequestDeviceError(thread_id, request_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) {
+ // TODO(ortuno): Change to NetworkError once it's implemented.
scheib 2015/05/05 04:00:43 As we start to implement the algorithm details, le
+ Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id,
+ BluetoothError::NOT_FOUND));
+}
+
void BluetoothDispatcherHost::OnSetBluetoothMockDataSetForTesting(
const std::string& name) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
@@ -189,6 +232,7 @@ void BluetoothDispatcherHost::OnDiscoverySessionStopped(int thread_id,
int request_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
+
if (devices.begin() == devices.end()) {
Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id,
BluetoothError::NOT_FOUND));

Powered by Google App Engine
This is Rietveld 408576698