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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 NOTREACHED(); | 124 NOTREACHED(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void BluetoothDispatcherHost::OnConnectGATT( | 127 void BluetoothDispatcherHost::OnConnectGATT( |
| 128 int thread_id, | 128 int thread_id, |
| 129 int request_id, | 129 int request_id, |
| 130 const std::string& device_instance_id) { | 130 const std::string& device_instance_id) { |
| 131 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 131 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 132 // TODO(ortuno): Add actual implementation of connectGATT. This needs to be | 132 |
| 133 // done after the "allowed devices map" is implemented. | 133 // 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
| |
| 134 // the device, because any domain can connect to any device. But once | |
| 135 // permissions are implemented we should check that the domain has access to | |
| 136 // the device. | |
| 137 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | |
| 138 | |
| 139 // TODO(ortuno): Instead of iterating through the devices list we should keep | |
| 140 // 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
| |
| 141 for (BluetoothAdapter::DeviceList::iterator iter = devices.begin(); | |
| 142 iter != devices.end(); iter++) { | |
| 143 device::BluetoothDevice* device = *iter; | |
| 144 if (device->GetAddress() == device_instance_id) { | |
| 145 device->CreateGattConnection( | |
| 146 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated, | |
| 147 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, | |
| 148 device_instance_id), | |
| 149 base::Bind(&BluetoothDispatcherHost::OnCreateGATTConnectionError, | |
| 150 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, | |
| 151 device_instance_id)); | |
| 152 return; | |
| 153 } | |
| 154 } | |
| 155 // TODO(ortuno): Change to NetworkError once it's implemented. | |
| 156 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, | |
| 157 BluetoothError::NOT_FOUND)); | |
| 158 } | |
| 159 | |
| 160 void BluetoothDispatcherHost::OnGATTConnectionCreated( | |
| 161 int thread_id, | |
| 162 int request_id, | |
| 163 const std::string& device_instance_id, | |
| 164 scoped_ptr<device::BluetoothGattConnection> connection) { | |
| 165 // TODO(ortuno): Save the BluetoothGattConnection so we can disconnect | |
| 166 // from it. | |
| 134 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, | 167 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, |
| 135 device_instance_id)); | 168 device_instance_id)); |
| 136 } | 169 } |
| 137 | 170 |
| 171 void BluetoothDispatcherHost::OnCreateGATTConnectionError( | |
| 172 int thread_id, | |
| 173 int request_id, | |
| 174 const std::string& device_instance_id, | |
| 175 device::BluetoothDevice::ConnectErrorCode error_code) { | |
| 176 // 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
| |
| 177 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, | |
| 178 BluetoothError::NOT_FOUND)); | |
| 179 } | |
| 180 | |
| 138 void BluetoothDispatcherHost::OnSetBluetoothMockDataSetForTesting( | 181 void BluetoothDispatcherHost::OnSetBluetoothMockDataSetForTesting( |
| 139 const std::string& name) { | 182 const std::string& name) { |
| 140 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 183 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 141 if (name == "RejectRequestDevice_NotFoundError") { | 184 if (name == "RejectRequestDevice_NotFoundError") { |
| 142 bluetooth_mock_data_set_ = MockData::REJECT; | 185 bluetooth_mock_data_set_ = MockData::REJECT; |
| 143 bluetooth_request_device_reject_type_ = BluetoothError::NOT_FOUND; | 186 bluetooth_request_device_reject_type_ = BluetoothError::NOT_FOUND; |
| 144 } else if (name == "RejectRequestDevice_SecurityError") { | 187 } else if (name == "RejectRequestDevice_SecurityError") { |
| 145 bluetooth_mock_data_set_ = MockData::REJECT; | 188 bluetooth_mock_data_set_ = MockData::REJECT; |
| 146 bluetooth_request_device_reject_type_ = BluetoothError::SECURITY; | 189 bluetooth_request_device_reject_type_ = BluetoothError::SECURITY; |
| 147 } else if (name == "ResolveRequestDevice_Empty" || // TODO(scheib): Remove. | 190 } else if (name == "ResolveRequestDevice_Empty" || // TODO(scheib): Remove. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStopped, | 225 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStopped, |
| 183 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), | 226 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), |
| 184 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStoppedError, | 227 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStoppedError, |
| 185 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); | 228 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); |
| 186 } | 229 } |
| 187 | 230 |
| 188 void BluetoothDispatcherHost::OnDiscoverySessionStopped(int thread_id, | 231 void BluetoothDispatcherHost::OnDiscoverySessionStopped(int thread_id, |
| 189 int request_id) { | 232 int request_id) { |
| 190 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 233 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 191 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 234 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 235 | |
| 192 if (devices.begin() == devices.end()) { | 236 if (devices.begin() == devices.end()) { |
| 193 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, | 237 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, |
| 194 BluetoothError::NOT_FOUND)); | 238 BluetoothError::NOT_FOUND)); |
| 195 } else { | 239 } else { |
| 196 device::BluetoothDevice* device = *devices.begin(); | 240 device::BluetoothDevice* device = *devices.begin(); |
| 197 content::BluetoothDevice device_ipc( | 241 content::BluetoothDevice device_ipc( |
| 198 device->GetAddress(), // instance_id | 242 device->GetAddress(), // instance_id |
| 199 device->GetName(), // name | 243 device->GetName(), // name |
| 200 device->GetBluetoothClass(), // device_class | 244 device->GetBluetoothClass(), // device_class |
| 201 device->GetVendorIDSource(), // vendor_id_source | 245 device->GetVendorIDSource(), // vendor_id_source |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 212 | 256 |
| 213 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id, | 257 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id, |
| 214 int request_id) { | 258 int request_id) { |
| 215 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 259 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 216 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError"; | 260 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError"; |
| 217 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, | 261 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, |
| 218 BluetoothError::NOT_FOUND)); | 262 BluetoothError::NOT_FOUND)); |
| 219 } | 263 } |
| 220 | 264 |
| 221 } // namespace content | 265 } // namespace content |
| OLD | NEW |