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) |
53 IPC_MESSAGE_UNHANDLED(handled = false) | 55 IPC_MESSAGE_UNHANDLED(handled = false) |
54 IPC_END_MESSAGE_MAP() | 56 IPC_END_MESSAGE_MAP() |
55 return handled; | 57 return handled; |
56 } | 58 } |
57 | 59 |
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 | |
75 BluetoothDispatcherHost::~BluetoothDispatcherHost() { | 60 BluetoothDispatcherHost::~BluetoothDispatcherHost() { |
76 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 61 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
77 // Clear adapter, releasing observer references. | 62 // Clear adapter, releasing observer references. |
78 set_adapter(scoped_refptr<device::BluetoothAdapter>()); | 63 set_adapter(scoped_refptr<device::BluetoothAdapter>()); |
79 } | 64 } |
80 | 65 |
81 void BluetoothDispatcherHost::set_adapter( | 66 void BluetoothDispatcherHost::set_adapter( |
82 scoped_refptr<device::BluetoothAdapter> adapter) { | 67 scoped_refptr<device::BluetoothAdapter> adapter) { |
83 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 68 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
84 if (adapter_.get()) | 69 if (adapter_.get()) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 int thread_id, | 128 int thread_id, |
144 int request_id, | 129 int request_id, |
145 const std::string& device_instance_id) { | 130 const std::string& device_instance_id) { |
146 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 131 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
147 // TODO(ortuno): Add actual implementation of connectGATT. This needs to be | 132 // TODO(ortuno): Add actual implementation of connectGATT. This needs to be |
148 // done after the "allowed devices map" is implemented. | 133 // done after the "allowed devices map" is implemented. |
149 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, | 134 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, |
150 device_instance_id)); | 135 device_instance_id)); |
151 } | 136 } |
152 | 137 |
| 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 |
153 void BluetoothDispatcherHost::OnDiscoverySessionStarted( | 155 void BluetoothDispatcherHost::OnDiscoverySessionStarted( |
154 int thread_id, | 156 int thread_id, |
155 int request_id, | 157 int request_id, |
156 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { | 158 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { |
157 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 159 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
158 BrowserThread::PostDelayedTask( | 160 BrowserThread::PostDelayedTask( |
159 BrowserThread::UI, FROM_HERE, | 161 BrowserThread::UI, FROM_HERE, |
160 base::Bind(&BluetoothDispatcherHost::StopDiscoverySession, | 162 base::Bind(&BluetoothDispatcherHost::StopDiscoverySession, |
161 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, | 163 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, |
162 base::Passed(&discovery_session)), | 164 base::Passed(&discovery_session)), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 212 |
211 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id, | 213 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id, |
212 int request_id) { | 214 int request_id) { |
213 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 215 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
214 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError"; | 216 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError"; |
215 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, | 217 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, |
216 BluetoothError::NOT_FOUND)); | 218 BluetoothError::NOT_FOUND)); |
217 } | 219 } |
218 | 220 |
219 } // namespace content | 221 } // namespace content |
OLD | NEW |