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