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

Side by Side Diff: chromeos/dbus/fake_bluetooth_device_client.cc

Issue 910433002: Fix crash on second failed connect to a paired device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chromeos/dbus/fake_bluetooth_device_client.h" 5 #include "chromeos/dbus/fake_bluetooth_device_client.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 178
179 const char FakeBluetoothDeviceClient::kLowEnergyPath[] = 179 const char FakeBluetoothDeviceClient::kLowEnergyPath[] =
180 "/fake/hci0/devC"; 180 "/fake/hci0/devC";
181 const char FakeBluetoothDeviceClient::kLowEnergyAddress[] = 181 const char FakeBluetoothDeviceClient::kLowEnergyAddress[] =
182 "00:1A:11:00:15:30"; 182 "00:1A:11:00:15:30";
183 const char FakeBluetoothDeviceClient::kLowEnergyName[] = 183 const char FakeBluetoothDeviceClient::kLowEnergyName[] =
184 "Bluetooth 4.0 Heart Rate Monitor"; 184 "Bluetooth 4.0 Heart Rate Monitor";
185 const uint32 FakeBluetoothDeviceClient::kLowEnergyClass = 185 const uint32 FakeBluetoothDeviceClient::kLowEnergyClass =
186 0x000918; // Major class "Health", Minor class "Heart/Pulse Rate Monitor." 186 0x000918; // Major class "Health", Minor class "Heart/Pulse Rate Monitor."
187 187
188 const char FakeBluetoothDeviceClient::kPairedUnconnectableDevicePath[] =
189 "/fake/hci0/devD";
190 const char FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress[] =
191 "20:7D:74:00:00:04";
192 const char FakeBluetoothDeviceClient::kPairedUnconnectableDeviceName[] =
193 "Paired Unconnectable Device";
194 const uint32 FakeBluetoothDeviceClient::kPairedUnconnectableDeviceClass =
195 0x000104;
196
188 FakeBluetoothDeviceClient::Properties::Properties( 197 FakeBluetoothDeviceClient::Properties::Properties(
189 const PropertyChangedCallback& callback) 198 const PropertyChangedCallback& callback)
190 : BluetoothDeviceClient::Properties( 199 : BluetoothDeviceClient::Properties(
191 NULL, 200 NULL,
192 bluetooth_device::kBluetoothDeviceInterface, 201 bluetooth_device::kBluetoothDeviceInterface,
193 callback) { 202 callback) {
194 } 203 }
195 204
196 FakeBluetoothDeviceClient::Properties::~Properties() { 205 FakeBluetoothDeviceClient::Properties::~Properties() {
197 } 206 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 251
243 std::vector<std::string> uuids; 252 std::vector<std::string> uuids;
244 uuids.push_back("00001800-0000-1000-8000-00805f9b34fb"); 253 uuids.push_back("00001800-0000-1000-8000-00805f9b34fb");
245 uuids.push_back("00001801-0000-1000-8000-00805f9b34fb"); 254 uuids.push_back("00001801-0000-1000-8000-00805f9b34fb");
246 properties->uuids.ReplaceValue(uuids); 255 properties->uuids.ReplaceValue(uuids);
247 256
248 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306"); 257 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306");
249 258
250 properties_map_[dbus::ObjectPath(kPairedDevicePath)] = properties; 259 properties_map_[dbus::ObjectPath(kPairedDevicePath)] = properties;
251 device_list_.push_back(dbus::ObjectPath(kPairedDevicePath)); 260 device_list_.push_back(dbus::ObjectPath(kPairedDevicePath));
261
262 properties = new Properties(base::Bind(
263 &FakeBluetoothDeviceClient::OnPropertyChanged, base::Unretained(this),
armansito 2015/02/07 00:29:55 nit: Formatting. Put second argument in its own li
Marie Janssen 2015/02/09 18:58:41 git cl format chromeos disagrees, and chromeos/ re
armansito 2015/02/09 20:35:22 I disagree with git cl format here, it doesn't alw
264 dbus::ObjectPath(kPairedUnconnectableDevicePath)));
265 properties->address.ReplaceValue(kPairedUnconnectableDeviceAddress);
266 properties->bluetooth_class.ReplaceValue(kPairedUnconnectableDeviceClass);
267 properties->name.ReplaceValue("Fake Device 2 (Unconnectable)");
268 properties->alias.ReplaceValue(kPairedUnconnectableDeviceName);
269 properties->paired.ReplaceValue(true);
270 properties->trusted.ReplaceValue(true);
271 properties->adapter.ReplaceValue(
272 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath));
273
274 properties->uuids.ReplaceValue(uuids);
275
276 properties->modalias.ReplaceValue("usb:v05ACp030Dd0306");
277
278 properties_map_[dbus::ObjectPath(kPairedUnconnectableDevicePath)] =
279 properties;
280 device_list_.push_back(dbus::ObjectPath(kPairedUnconnectableDevicePath));
252 } 281 }
253 282
254 FakeBluetoothDeviceClient::~FakeBluetoothDeviceClient() { 283 FakeBluetoothDeviceClient::~FakeBluetoothDeviceClient() {
255 // Clean up Properties structures 284 // Clean up Properties structures
256 STLDeleteValues(&properties_map_); 285 STLDeleteValues(&properties_map_);
257 } 286 }
258 287
259 void FakeBluetoothDeviceClient::Init(dbus::Bus* bus) { 288 void FakeBluetoothDeviceClient::Init(dbus::Bus* bus) {
260 } 289 }
261 290
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 return; 326 return;
298 } 327 }
299 328
300 if (properties->paired.value() != true && 329 if (properties->paired.value() != true &&
301 object_path != dbus::ObjectPath(kConnectUnpairablePath) && 330 object_path != dbus::ObjectPath(kConnectUnpairablePath) &&
302 object_path != dbus::ObjectPath(kLowEnergyPath)) { 331 object_path != dbus::ObjectPath(kLowEnergyPath)) {
303 // Must be paired. 332 // Must be paired.
304 error_callback.Run(bluetooth_device::kErrorFailed, "Not paired"); 333 error_callback.Run(bluetooth_device::kErrorFailed, "Not paired");
305 return; 334 return;
306 } else if (properties->paired.value() == true && 335 } else if (properties->paired.value() == true &&
307 object_path == dbus::ObjectPath(kUnconnectableDevicePath)) { 336 (object_path == dbus::ObjectPath(kUnconnectableDevicePath) ||
337 object_path ==
338 dbus::ObjectPath(kPairedUnconnectableDevicePath))) {
308 // Must not be paired 339 // Must not be paired
309 error_callback.Run(bluetooth_device::kErrorFailed, 340 error_callback.Run(bluetooth_device::kErrorFailed,
310 "Connection fails while paired"); 341 "Connection fails while paired");
311 return; 342 return;
312 } 343 }
313 344
314 // The device can be connected. 345 // The device can be connected.
315 properties->connected.ReplaceValue(true); 346 properties->connected.ReplaceValue(true);
316 callback.Run(); 347 callback.Run();
317 348
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client = 392 FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client =
362 static_cast<FakeBluetoothProfileManagerClient*>( 393 static_cast<FakeBluetoothProfileManagerClient*>(
363 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()); 394 DBusThreadManager::Get()->GetBluetoothProfileManagerClient());
364 FakeBluetoothProfileServiceProvider* profile_service_provider = 395 FakeBluetoothProfileServiceProvider* profile_service_provider =
365 fake_bluetooth_profile_manager_client->GetProfileServiceProvider(uuid); 396 fake_bluetooth_profile_manager_client->GetProfileServiceProvider(uuid);
366 if (profile_service_provider == NULL) { 397 if (profile_service_provider == NULL) {
367 error_callback.Run(kNoResponseError, "Missing profile"); 398 error_callback.Run(kNoResponseError, "Missing profile");
368 return; 399 return;
369 } 400 }
370 401
402 if (object_path == dbus::ObjectPath(kPairedUnconnectableDevicePath)) {
403 error_callback.Run(kNoResponseError, "unconnectable");
armansito 2015/02/07 00:29:55 I think we use kNoResponseError for cases that are
Marie Janssen 2015/02/09 18:58:41 Done. Using kErrorFailed instead.
404 return;
405 }
406
371 // Make a socket pair of a compatible type with the type used by Bluetooth; 407 // Make a socket pair of a compatible type with the type used by Bluetooth;
372 // spin up a thread to simulate the server side and wrap the client side in 408 // spin up a thread to simulate the server side and wrap the client side in
373 // a D-Bus file descriptor object. 409 // a D-Bus file descriptor object.
374 int socket_type = SOCK_STREAM; 410 int socket_type = SOCK_STREAM;
375 if (uuid == FakeBluetoothProfileManagerClient::kL2capUuid) 411 if (uuid == FakeBluetoothProfileManagerClient::kL2capUuid)
376 socket_type = SOCK_SEQPACKET; 412 socket_type = SOCK_SEQPACKET;
377 413
378 int fds[2]; 414 int fds[2];
379 if (socketpair(AF_UNIX, socket_type, 0, fds) < 0) { 415 if (socketpair(AF_UNIX, socket_type, 0, fds) < 0) {
380 error_callback.Run(kNoResponseError, "socketpair call failed"); 416 error_callback.Run(kNoResponseError, "socketpair call failed");
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 // TODO(keybuk): tear down this side of the connection 1237 // TODO(keybuk): tear down this side of the connection
1202 callback.Run(); 1238 callback.Run();
1203 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { 1239 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) {
1204 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); 1240 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled");
1205 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { 1241 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) {
1206 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); 1242 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected");
1207 } 1243 }
1208 } 1244 }
1209 1245
1210 } // namespace chromeos 1246 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/fake_bluetooth_device_client.h ('k') | device/bluetooth/bluetooth_adapter_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698