Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: content/browser/bluetooth/bluetooth_dispatcher_host.cc

Issue 1132943002: bluetooth: Move mock creation out of BluetoothDispatcherHost to LayoutTestBluetoothAdapterProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-testing-layout-tests
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/public/browser/browser_context.h" 9 #include "content/public/browser/browser_context.h"
10 #include "device/bluetooth/bluetooth_adapter.h" 10 #include "device/bluetooth/bluetooth_adapter.h"
11 #include "device/bluetooth/bluetooth_adapter_factory.h" 11 #include "device/bluetooth/bluetooth_adapter_factory.h"
12 #include "device/bluetooth/bluetooth_device.h" 12 #include "device/bluetooth/bluetooth_device.h"
13 #include "device/bluetooth/bluetooth_discovery_session.h" 13 #include "device/bluetooth/bluetooth_discovery_session.h"
14 14
15 using device::BluetoothAdapter; 15 using device::BluetoothAdapter;
16 using device::BluetoothAdapterFactory; 16 using device::BluetoothAdapterFactory;
17 17
18 namespace content { 18 namespace content {
19 19
20 const uint32 kUnspecifiedDeviceClass = 20 const uint32 kUnspecifiedDeviceClass =
scheib 2015/05/11 20:19:26 Delete constant here, it is now unused.
21 0x1F00; // bluetooth.org/en-us/specification/assigned-numbers/baseband 21 0x1F00; // bluetooth.org/en-us/specification/assigned-numbers/baseband
22 const int kScanTime = 5; // 5 seconds of scan time 22 const int kScanTime = 5; // 5 seconds of scan time
23 23
24 BluetoothDispatcherHost::BluetoothDispatcherHost( 24 BluetoothDispatcherHost::BluetoothDispatcherHost(
25 BrowserContext* browser_context) 25 BrowserContext* browser_context)
26 : BrowserMessageFilter(BluetoothMsgStart), 26 : BrowserMessageFilter(BluetoothMsgStart),
27 browser_context_(browser_context), 27 browser_context_(browser_context),
28 bluetooth_mock_data_set_(MockData::NOT_MOCKING),
29 bluetooth_request_device_reject_type_(BluetoothError::NOT_FOUND),
30 weak_ptr_factory_(this) { 28 weak_ptr_factory_(this) {
31 DCHECK_CURRENTLY_ON(BrowserThread::UI); 29 DCHECK_CURRENTLY_ON(BrowserThread::UI);
32 browser_context_->GetBluetoothAdapter(base::Bind( 30 browser_context_->GetBluetoothAdapter(base::Bind(
33 &BluetoothDispatcherHost::set_adapter, weak_ptr_factory_.GetWeakPtr())); 31 &BluetoothDispatcherHost::set_adapter, weak_ptr_factory_.GetWeakPtr()));
34 } 32 }
35 33
36 void BluetoothDispatcherHost::OnDestruct() const { 34 void BluetoothDispatcherHost::OnDestruct() const {
37 // See class comment: UI Thread Note. 35 // See class comment: UI Thread Note.
38 BrowserThread::DeleteOnUIThread::Destruct(this); 36 BrowserThread::DeleteOnUIThread::Destruct(this);
39 } 37 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 adapter_->RemoveObserver(this); 69 adapter_->RemoveObserver(this);
72 adapter_ = adapter; 70 adapter_ = adapter;
73 if (adapter_.get()) 71 if (adapter_.get())
74 adapter_->AddObserver(this); 72 adapter_->AddObserver(this);
75 } 73 }
76 74
77 void BluetoothDispatcherHost::OnRequestDevice(int thread_id, int request_id) { 75 void BluetoothDispatcherHost::OnRequestDevice(int thread_id, int request_id) {
78 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 76 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
79 // TODO(scheib) Extend this very simple mock implementation by using 77 // TODO(scheib) Extend this very simple mock implementation by using
80 // device/bluetooth/test mock adapter and related classes. 78 // device/bluetooth/test mock adapter and related classes.
81 switch (bluetooth_mock_data_set_) { 79 // TODO(scheib): Filter devices by services: crbug.com/440594
82 case MockData::NOT_MOCKING: { 80 // TODO(scheib): Device selection UI: crbug.com/436280
83 // TODO(scheib): Filter devices by services: crbug.com/440594 81 // TODO(scheib): Utilize BluetoothAdapter::Observer::DeviceAdded/Removed.
84 // TODO(scheib): Device selection UI: crbug.com/436280 82 BluetoothAdapter::DeviceList devices;
85 // TODO(scheib): Utilize BluetoothAdapter::Observer::DeviceAdded/Removed.
86 BluetoothAdapter::DeviceList devices;
87 83
88 if (adapter_.get()) { 84 if (adapter_.get()) {
89 adapter_->StartDiscoverySession( 85 adapter_->StartDiscoverySession(
90 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted, 86 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted,
91 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), 87 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id),
92 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError, 88 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError,
93 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); 89 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id));
94 } else { 90 } else {
95 DLOG(WARNING) << "No BluetoothAdapter. Can't serve requestDevice."; 91 DLOG(WARNING) << "No BluetoothAdapter. Can't serve requestDevice.";
96 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, 92 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id,
97 BluetoothError::NOT_FOUND)); 93 BluetoothError::NOT_FOUND));
98 }
99 return;
100 }
101 case MockData::REJECT: {
102 Send(new BluetoothMsg_RequestDeviceError(
103 thread_id, request_id, bluetooth_request_device_reject_type_));
104 return;
105 }
106 case MockData::RESOLVE: {
107 std::vector<std::string> uuids;
108 uuids.push_back("00001800-0000-1000-8000-00805f9b34fb");
109 uuids.push_back("00001801-0000-1000-8000-00805f9b34fb");
110 content::BluetoothDevice device_ipc(
111 "Empty Mock Device instanceID", // instance_id
112 base::UTF8ToUTF16("Empty Mock Device name"), // name
113 kUnspecifiedDeviceClass, // device_class
114 device::BluetoothDevice::VENDOR_ID_BLUETOOTH, // vendor_id_source
115 0xFFFF, // vendor_id
116 1, // product_id
117 2, // product_version
118 true, // paired
119 uuids); // uuids
120 Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id,
121 device_ipc));
122 return;
123 }
124 } 94 }
125 NOTREACHED(); 95 return;
126 } 96 }
127 97
128 void BluetoothDispatcherHost::OnConnectGATT( 98 void BluetoothDispatcherHost::OnConnectGATT(
129 int thread_id, 99 int thread_id,
130 int request_id, 100 int request_id,
131 const std::string& device_instance_id) { 101 const std::string& device_instance_id) {
132 DCHECK_CURRENTLY_ON(BrowserThread::UI); 102 DCHECK_CURRENTLY_ON(BrowserThread::UI);
133 // TODO(ortuno): Add actual implementation of connectGATT. This needs to be 103 // TODO(ortuno): Add actual implementation of connectGATT. This needs to be
134 // done after the "allowed devices map" is implemented. 104 // done after the "allowed devices map" is implemented.
135 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, 105 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id,
136 device_instance_id)); 106 device_instance_id));
137 } 107 }
138 108
139 void BluetoothDispatcherHost::OnSetBluetoothMockDataSetForTesting( 109 void BluetoothDispatcherHost::OnSetBluetoothMockDataSetForTesting(
140 const std::string& name) { 110 const std::string& name) {
141 DCHECK_CURRENTLY_ON(BrowserThread::UI); 111 DCHECK_CURRENTLY_ON(BrowserThread::UI);
142 if (name == "RejectRequestDevice_NotFoundError") { 112 browser_context_->GetBluetoothAdapterForTesting(
scheib 2015/05/11 20:19:26 Whitespace typo, run git cl format.
ortuno 2015/05/12 19:33:19 Done.
143 bluetooth_mock_data_set_ = MockData::REJECT; 113 base::Bind(&BluetoothDispatcherHost::set_adapter,
144 bluetooth_request_device_reject_type_ = BluetoothError::NOT_FOUND; 114 weak_ptr_factory_.GetWeakPtr()),
145 } else if (name == "RejectRequestDevice_SecurityError") { 115 name);
146 bluetooth_mock_data_set_ = MockData::REJECT;
147 bluetooth_request_device_reject_type_ = BluetoothError::SECURITY;
148 } else if (name == "ResolveRequestDevice_Empty" || // TODO(scheib): Remove.
149 name == "Single Empty Device") {
150 bluetooth_mock_data_set_ = MockData::RESOLVE;
151 } else {
152 bluetooth_mock_data_set_ = MockData::NOT_MOCKING;
153 }
154 } 116 }
155 117
156 void BluetoothDispatcherHost::OnDiscoverySessionStarted( 118 void BluetoothDispatcherHost::OnDiscoverySessionStarted(
157 int thread_id, 119 int thread_id,
158 int request_id, 120 int request_id,
159 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { 121 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) {
160 DCHECK_CURRENTLY_ON(BrowserThread::UI); 122 DCHECK_CURRENTLY_ON(BrowserThread::UI);
161 BrowserThread::PostDelayedTask( 123 BrowserThread::PostDelayedTask(
162 BrowserThread::UI, FROM_HERE, 124 BrowserThread::UI, FROM_HERE,
163 base::Bind(&BluetoothDispatcherHost::StopDiscoverySession, 125 base::Bind(&BluetoothDispatcherHost::StopDiscoverySession,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 175
214 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id, 176 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id,
215 int request_id) { 177 int request_id) {
216 DCHECK_CURRENTLY_ON(BrowserThread::UI); 178 DCHECK_CURRENTLY_ON(BrowserThread::UI);
217 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError"; 179 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError";
218 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, 180 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id,
219 BluetoothError::NOT_FOUND)); 181 BluetoothError::NOT_FOUND));
220 } 182 }
221 183
222 } // namespace content 184 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698