Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h" | 5 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/common/bluetooth/bluetooth_messages.h" | 8 #include "content/common/bluetooth/bluetooth_messages.h" |
| 9 #include "device/bluetooth/bluetooth_adapter.h" | 9 #include "device/bluetooth/bluetooth_adapter.h" |
| 10 #include "device/bluetooth/bluetooth_adapter_factory.h" | 10 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 BluetoothError::NOT_FOUND)); | 93 BluetoothError::NOT_FOUND)); |
| 94 } | 94 } |
| 95 return; | 95 return; |
| 96 } | 96 } |
| 97 | 97 |
| 98 void BluetoothDispatcherHost::OnConnectGATT( | 98 void BluetoothDispatcherHost::OnConnectGATT( |
| 99 int thread_id, | 99 int thread_id, |
| 100 int request_id, | 100 int request_id, |
| 101 const std::string& device_instance_id) { | 101 const std::string& device_instance_id) { |
| 102 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 102 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 103 // TODO(ortuno): Add actual implementation of connectGATT. This needs to be | 103 // TODO(ortuno): Right now it's pointless to check if the domain has access to |
| 104 // done after the "allowed devices map" is implemented. | 104 // the device, because any domain can connect to any device. But once |
| 105 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, | 105 // permissions are implemented we should check that the domain has access to |
| 106 device_instance_id)); | 106 // the device. https://crbug.com/484745 |
| 107 device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id); | |
| 108 if (device == NULL) { | |
| 109 // Since we can't create a ATT Bearer without a device we reject with | |
| 110 // NetworkError. | |
|
Jeffrey Yasskin
2015/05/20 22:19:48
Is a device_instance_id that doesn't map to a devi
ortuno
2015/05/20 23:35:19
Yes, the renderer could send a device_instance_id
Jeffrey Yasskin
2015/05/21 00:12:00
And walking out of range is exactly when we'd want
| |
| 111 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-conne ctgatt | |
| 112 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id, | |
| 113 BluetoothError::NETWORK_ERROR)); | |
| 114 return; | |
| 115 } | |
| 116 device->CreateGattConnection( | |
| 117 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated, | |
| 118 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, | |
| 119 device_instance_id), | |
| 120 base::Bind(&BluetoothDispatcherHost::OnCreateGATTConnectionError, | |
| 121 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, | |
| 122 device_instance_id)); | |
| 107 } | 123 } |
| 108 | 124 |
| 109 void BluetoothDispatcherHost::OnDiscoverySessionStarted( | 125 void BluetoothDispatcherHost::OnDiscoverySessionStarted( |
| 110 int thread_id, | 126 int thread_id, |
| 111 int request_id, | 127 int request_id, |
| 112 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { | 128 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { |
| 113 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 129 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 114 BrowserThread::PostDelayedTask( | 130 BrowserThread::PostDelayedTask( |
| 115 BrowserThread::UI, FROM_HERE, | 131 BrowserThread::UI, FROM_HERE, |
| 116 base::Bind(&BluetoothDispatcherHost::StopDiscoverySession, | 132 base::Bind(&BluetoothDispatcherHost::StopDiscoverySession, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 } | 181 } |
| 166 | 182 |
| 167 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id, | 183 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id, |
| 168 int request_id) { | 184 int request_id) { |
| 169 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 185 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 170 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError"; | 186 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError"; |
| 171 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, | 187 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, |
| 172 BluetoothError::NOT_FOUND)); | 188 BluetoothError::NOT_FOUND)); |
| 173 } | 189 } |
| 174 | 190 |
| 191 void BluetoothDispatcherHost::OnGATTConnectionCreated( | |
| 192 int thread_id, | |
| 193 int request_id, | |
| 194 const std::string& device_instance_id, | |
| 195 scoped_ptr<device::BluetoothGattConnection> connection) { | |
| 196 // TODO(ortuno): Save the BluetoothGattConnection so we can disconnect | |
| 197 // from it. | |
| 198 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, | |
| 199 device_instance_id)); | |
| 200 } | |
| 201 | |
| 202 void BluetoothDispatcherHost::OnCreateGATTConnectionError( | |
| 203 int thread_id, | |
| 204 int request_id, | |
| 205 const std::string& device_instance_id, | |
| 206 device::BluetoothDevice::ConnectErrorCode error_code) { | |
| 207 // There was an error creating the ATT Bearer so we reject with | |
| 208 // NetworkError. | |
|
Jeffrey Yasskin
2015/05/20 22:19:48
Please give the eventual Javascript error a descri
ortuno
2015/05/20 23:35:19
Added a todo and opened an issue: http://crbug.com
| |
| 209 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-connect gatt | |
| 210 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id, | |
| 211 BluetoothError::NETWORK_ERROR)); | |
| 212 } | |
| 213 | |
| 175 } // namespace content | 214 } // namespace content |
| OLD | NEW |