| 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 "content/common/bluetooth/bluetooth_messages.h" | 8 #include "content/common/bluetooth/bluetooth_messages.h" |
| 8 #include "device/bluetooth/bluetooth_adapter.h" | 9 #include "device/bluetooth/bluetooth_adapter.h" |
| 9 #include "device/bluetooth/bluetooth_adapter_factory.h" | 10 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 10 #include "device/bluetooth/bluetooth_device.h" | 11 #include "device/bluetooth/bluetooth_device.h" |
| 11 | 12 |
| 12 using device::BluetoothAdapter; | 13 using device::BluetoothAdapter; |
| 13 using device::BluetoothAdapterFactory; | 14 using device::BluetoothAdapterFactory; |
| 14 using device::BluetoothDevice; | |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 const uint32 kUnspecifiedDeviceClass = |
| 19 0x1F00; // bluetooth.org/en-us/specification/assigned-numbers/baseband |
| 20 |
| 18 scoped_refptr<BluetoothDispatcherHost> BluetoothDispatcherHost::Create() { | 21 scoped_refptr<BluetoothDispatcherHost> BluetoothDispatcherHost::Create() { |
| 19 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 22 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 20 | 23 |
| 21 // Hold a reference to the BluetoothDispatcherHost because the callback below | 24 // Hold a reference to the BluetoothDispatcherHost because the callback below |
| 22 // may run and would otherwise release the BluetoothDispatcherHost | 25 // may run and would otherwise release the BluetoothDispatcherHost |
| 23 // prematurely. | 26 // prematurely. |
| 24 scoped_refptr<BluetoothDispatcherHost> host(new BluetoothDispatcherHost()); | 27 scoped_refptr<BluetoothDispatcherHost> host(new BluetoothDispatcherHost()); |
| 25 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) | 28 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) |
| 26 BluetoothAdapterFactory::GetAdapter( | 29 BluetoothAdapterFactory::GetAdapter( |
| 27 base::Bind(&BluetoothDispatcherHost::set_adapter, host)); | 30 base::Bind(&BluetoothDispatcherHost::set_adapter, host)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 switch (bluetooth_mock_data_set_) { | 71 switch (bluetooth_mock_data_set_) { |
| 69 case MockData::NOT_MOCKING: { | 72 case MockData::NOT_MOCKING: { |
| 70 // TODO(scheib): Filter devices by services: crbug.com/440594 | 73 // TODO(scheib): Filter devices by services: crbug.com/440594 |
| 71 // TODO(scheib): Device selection UI: crbug.com/436280 | 74 // TODO(scheib): Device selection UI: crbug.com/436280 |
| 72 // TODO(scheib): Utilize BluetoothAdapter::Observer::DeviceAdded/Removed. | 75 // TODO(scheib): Utilize BluetoothAdapter::Observer::DeviceAdded/Removed. |
| 73 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); | 76 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 74 if (devices.begin() == devices.end()) { | 77 if (devices.begin() == devices.end()) { |
| 75 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, | 78 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, |
| 76 BluetoothError::NOT_FOUND)); | 79 BluetoothError::NOT_FOUND)); |
| 77 } else { | 80 } else { |
| 78 BluetoothDevice* device = *devices.begin(); | 81 device::BluetoothDevice* device = *devices.begin(); |
| 82 content::BluetoothDevice device_ipc( |
| 83 device->GetAddress(), // instance_id |
| 84 device->GetName(), // name |
| 85 device->GetBluetoothClass(), // device_class |
| 86 device->GetVendorIDSource(), // vendor_id_source |
| 87 device->GetVendorID(), // vendor_id |
| 88 device->GetProductID(), // product_id |
| 89 device->GetDeviceID(), // product_version |
| 90 device->IsPaired(), // paired |
| 91 device->IsConnected(), // connected |
| 92 content::BluetoothDevice::UUIDsFromBluetoothUUIDs( |
| 93 device->GetUUIDs())); // uuids |
| 79 Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id, | 94 Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id, |
| 80 device->GetAddress())); | 95 device_ipc)); |
| 81 } | 96 } |
| 82 return; | 97 return; |
| 83 } | 98 } |
| 84 case MockData::REJECT: { | 99 case MockData::REJECT: { |
| 85 Send(new BluetoothMsg_RequestDeviceError( | 100 Send(new BluetoothMsg_RequestDeviceError( |
| 86 thread_id, request_id, bluetooth_request_device_reject_type_)); | 101 thread_id, request_id, bluetooth_request_device_reject_type_)); |
| 87 return; | 102 return; |
| 88 } | 103 } |
| 89 case MockData::RESOLVE: { | 104 case MockData::RESOLVE: { |
| 105 content::BluetoothDevice device_ipc( |
| 106 "Empty Mock Device instanceID", // instance_id |
| 107 base::UTF8ToUTF16("Empty Mock Device name"), // name |
| 108 kUnspecifiedDeviceClass, // device_class |
| 109 device::BluetoothDevice::VENDOR_ID_BLUETOOTH, // vendor_id_source |
| 110 0xFFFF, // vendor_id |
| 111 1, // product_id |
| 112 2, // product_version |
| 113 true, // paired |
| 114 false, // connected |
| 115 {"00001800-0000-1000-8000-00805f9b34fb", |
| 116 "00001801-0000-1000-8000-00805f9b34fb"}); // uuids |
| 90 Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id, | 117 Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id, |
| 91 "Empty Mock deviceId")); | 118 device_ipc)); |
| 92 return; | 119 return; |
| 93 } | 120 } |
| 94 } | 121 } |
| 95 NOTREACHED(); | 122 NOTREACHED(); |
| 96 } | 123 } |
| 97 | 124 |
| 98 void BluetoothDispatcherHost::OnSetBluetoothMockDataSetForTesting( | 125 void BluetoothDispatcherHost::OnSetBluetoothMockDataSetForTesting( |
| 99 const std::string& name) { | 126 const std::string& name) { |
| 100 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 127 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 101 if (name == "RejectRequestDevice_NotFoundError") { | 128 if (name == "RejectRequestDevice_NotFoundError") { |
| 102 bluetooth_mock_data_set_ = MockData::REJECT; | 129 bluetooth_mock_data_set_ = MockData::REJECT; |
| 103 bluetooth_request_device_reject_type_ = BluetoothError::NOT_FOUND; | 130 bluetooth_request_device_reject_type_ = BluetoothError::NOT_FOUND; |
| 104 } else if (name == "RejectRequestDevice_SecurityError") { | 131 } else if (name == "RejectRequestDevice_SecurityError") { |
| 105 bluetooth_mock_data_set_ = MockData::REJECT; | 132 bluetooth_mock_data_set_ = MockData::REJECT; |
| 106 bluetooth_request_device_reject_type_ = BluetoothError::SECURITY; | 133 bluetooth_request_device_reject_type_ = BluetoothError::SECURITY; |
| 107 } else if (name == "ResolveRequestDevice_Empty" || // TODO(scheib): Remove. | 134 } else if (name == "ResolveRequestDevice_Empty" || // TODO(scheib): Remove. |
| 108 name == "Single Empty Device") { | 135 name == "Single Empty Device") { |
| 109 bluetooth_mock_data_set_ = MockData::RESOLVE; | 136 bluetooth_mock_data_set_ = MockData::RESOLVE; |
| 110 } else { | 137 } else { |
| 111 bluetooth_mock_data_set_ = MockData::NOT_MOCKING; | 138 bluetooth_mock_data_set_ = MockData::NOT_MOCKING; |
| 112 } | 139 } |
| 113 } | 140 } |
| 114 | 141 |
| 115 } // namespace content | 142 } // namespace content |
| OLD | NEW |