| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // See class comment: UI Thread Note. | 43 // See class comment: UI Thread Note. |
| 44 *thread = BrowserThread::UI; | 44 *thread = BrowserThread::UI; |
| 45 } | 45 } |
| 46 | 46 |
| 47 bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { | 47 bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
| 48 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 48 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 49 bool handled = true; | 49 bool handled = true; |
| 50 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message) | 50 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message) |
| 51 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice) | 51 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice) |
| 52 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ConnectGATT, OnConnectGATT) | 52 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ConnectGATT, OnConnectGATT) |
| 53 IPC_MESSAGE_HANDLER(BluetoothHostMsg_SetBluetoothMockDataSetForTesting, | |
| 54 OnSetBluetoothMockDataSetForTesting) | |
| 55 IPC_MESSAGE_UNHANDLED(handled = false) | 53 IPC_MESSAGE_UNHANDLED(handled = false) |
| 56 IPC_END_MESSAGE_MAP() | 54 IPC_END_MESSAGE_MAP() |
| 57 return handled; | 55 return handled; |
| 58 } | 56 } |
| 59 | 57 |
| 58 void BluetoothDispatcherHost::SetBluetoothAdapterForTesting( |
| 59 const std::string& name) { |
| 60 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 61 if (name == "RejectRequestDevice_NotFoundError") { |
| 62 bluetooth_mock_data_set_ = MockData::REJECT; |
| 63 bluetooth_request_device_reject_type_ = BluetoothError::NOT_FOUND; |
| 64 } else if (name == "RejectRequestDevice_SecurityError") { |
| 65 bluetooth_mock_data_set_ = MockData::REJECT; |
| 66 bluetooth_request_device_reject_type_ = BluetoothError::SECURITY; |
| 67 } else if (name == "ResolveRequestDevice_Empty" || // TODO(scheib): Remove. |
| 68 name == "Single Empty Device") { |
| 69 bluetooth_mock_data_set_ = MockData::RESOLVE; |
| 70 } else { |
| 71 bluetooth_mock_data_set_ = MockData::NOT_MOCKING; |
| 72 } |
| 73 } |
| 74 |
| 60 BluetoothDispatcherHost::~BluetoothDispatcherHost() { | 75 BluetoothDispatcherHost::~BluetoothDispatcherHost() { |
| 61 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 76 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 62 // Clear adapter, releasing observer references. | 77 // Clear adapter, releasing observer references. |
| 63 set_adapter(scoped_refptr<device::BluetoothAdapter>()); | 78 set_adapter(scoped_refptr<device::BluetoothAdapter>()); |
| 64 } | 79 } |
| 65 | 80 |
| 66 void BluetoothDispatcherHost::set_adapter( | 81 void BluetoothDispatcherHost::set_adapter( |
| 67 scoped_refptr<device::BluetoothAdapter> adapter) { | 82 scoped_refptr<device::BluetoothAdapter> adapter) { |
| 68 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 83 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 69 if (adapter_.get()) | 84 if (adapter_.get()) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 int thread_id, | 143 int thread_id, |
| 129 int request_id, | 144 int request_id, |
| 130 const std::string& device_instance_id) { | 145 const std::string& device_instance_id) { |
| 131 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 146 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 132 // TODO(ortuno): Add actual implementation of connectGATT. This needs to be | 147 // TODO(ortuno): Add actual implementation of connectGATT. This needs to be |
| 133 // done after the "allowed devices map" is implemented. | 148 // done after the "allowed devices map" is implemented. |
| 134 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, | 149 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, |
| 135 device_instance_id)); | 150 device_instance_id)); |
| 136 } | 151 } |
| 137 | 152 |
| 138 void BluetoothDispatcherHost::OnSetBluetoothMockDataSetForTesting( | |
| 139 const std::string& name) { | |
| 140 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 141 if (name == "RejectRequestDevice_NotFoundError") { | |
| 142 bluetooth_mock_data_set_ = MockData::REJECT; | |
| 143 bluetooth_request_device_reject_type_ = BluetoothError::NOT_FOUND; | |
| 144 } else if (name == "RejectRequestDevice_SecurityError") { | |
| 145 bluetooth_mock_data_set_ = MockData::REJECT; | |
| 146 bluetooth_request_device_reject_type_ = BluetoothError::SECURITY; | |
| 147 } else if (name == "ResolveRequestDevice_Empty" || // TODO(scheib): Remove. | |
| 148 name == "Single Empty Device") { | |
| 149 bluetooth_mock_data_set_ = MockData::RESOLVE; | |
| 150 } else { | |
| 151 bluetooth_mock_data_set_ = MockData::NOT_MOCKING; | |
| 152 } | |
| 153 } | |
| 154 | |
| 155 void BluetoothDispatcherHost::OnDiscoverySessionStarted( | 153 void BluetoothDispatcherHost::OnDiscoverySessionStarted( |
| 156 int thread_id, | 154 int thread_id, |
| 157 int request_id, | 155 int request_id, |
| 158 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { | 156 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { |
| 159 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 157 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 160 BrowserThread::PostDelayedTask( | 158 BrowserThread::PostDelayedTask( |
| 161 BrowserThread::UI, FROM_HERE, | 159 BrowserThread::UI, FROM_HERE, |
| 162 base::Bind(&BluetoothDispatcherHost::StopDiscoverySession, | 160 base::Bind(&BluetoothDispatcherHost::StopDiscoverySession, |
| 163 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, | 161 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, |
| 164 base::Passed(&discovery_session)), | 162 base::Passed(&discovery_session)), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 210 |
| 213 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id, | 211 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id, |
| 214 int request_id) { | 212 int request_id) { |
| 215 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 213 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 216 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError"; | 214 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError"; |
| 217 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, | 215 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, |
| 218 BluetoothError::NOT_FOUND)); | 216 BluetoothError::NOT_FOUND)); |
| 219 } | 217 } |
| 220 | 218 |
| 221 } // namespace content | 219 } // namespace content |
| OLD | NEW |