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 std::vector<std::string> uuids; |
| 106 uuids.push_back("00001800-0000-1000-8000-00805f9b34fb"); |
| 107 uuids.push_back("00001801-0000-1000-8000-00805f9b34fb"); |
| 108 content::BluetoothDevice device_ipc( |
| 109 "Empty Mock Device instanceID", // instance_id |
| 110 base::UTF8ToUTF16("Empty Mock Device name"), // name |
| 111 kUnspecifiedDeviceClass, // device_class |
| 112 device::BluetoothDevice::VENDOR_ID_BLUETOOTH, // vendor_id_source |
| 113 0xFFFF, // vendor_id |
| 114 1, // product_id |
| 115 2, // product_version |
| 116 true, // paired |
| 117 false, // connected |
| 118 uuids); // uuids |
90 Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id, | 119 Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id, |
91 "Empty Mock deviceId")); | 120 device_ipc)); |
92 return; | 121 return; |
93 } | 122 } |
94 } | 123 } |
95 NOTREACHED(); | 124 NOTREACHED(); |
96 } | 125 } |
97 | 126 |
98 void BluetoothDispatcherHost::OnSetBluetoothMockDataSetForTesting( | 127 void BluetoothDispatcherHost::OnSetBluetoothMockDataSetForTesting( |
99 const std::string& name) { | 128 const std::string& name) { |
100 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 129 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
101 if (name == "RejectRequestDevice_NotFoundError") { | 130 if (name == "RejectRequestDevice_NotFoundError") { |
102 bluetooth_mock_data_set_ = MockData::REJECT; | 131 bluetooth_mock_data_set_ = MockData::REJECT; |
103 bluetooth_request_device_reject_type_ = BluetoothError::NOT_FOUND; | 132 bluetooth_request_device_reject_type_ = BluetoothError::NOT_FOUND; |
104 } else if (name == "RejectRequestDevice_SecurityError") { | 133 } else if (name == "RejectRequestDevice_SecurityError") { |
105 bluetooth_mock_data_set_ = MockData::REJECT; | 134 bluetooth_mock_data_set_ = MockData::REJECT; |
106 bluetooth_request_device_reject_type_ = BluetoothError::SECURITY; | 135 bluetooth_request_device_reject_type_ = BluetoothError::SECURITY; |
107 } else if (name == "ResolveRequestDevice_Empty" || // TODO(scheib): Remove. | 136 } else if (name == "ResolveRequestDevice_Empty" || // TODO(scheib): Remove. |
108 name == "Single Empty Device") { | 137 name == "Single Empty Device") { |
109 bluetooth_mock_data_set_ = MockData::RESOLVE; | 138 bluetooth_mock_data_set_ = MockData::RESOLVE; |
110 } else { | 139 } else { |
111 bluetooth_mock_data_set_ = MockData::NOT_MOCKING; | 140 bluetooth_mock_data_set_ = MockData::NOT_MOCKING; |
112 } | 141 } |
113 } | 142 } |
114 | 143 |
115 } // namespace content | 144 } // namespace content |
OLD | NEW |