OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "device/bluetooth/bluetooth_device_chromeos.h" | 5 #include "device/bluetooth/bluetooth_device_chromeos.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "chromeos/dbus/bluetooth_adapter_client.h" | 14 #include "chromeos/dbus/bluetooth_adapter_client.h" |
15 #include "chromeos/dbus/bluetooth_device_client.h" | 15 #include "chromeos/dbus/bluetooth_device_client.h" |
16 #include "chromeos/dbus/bluetooth_gatt_service_client.h" | 16 #include "chromeos/dbus/bluetooth_gatt_service_client.h" |
17 #include "chromeos/dbus/bluetooth_input_client.h" | 17 #include "chromeos/dbus/bluetooth_input_client.h" |
18 #include "chromeos/dbus/dbus_thread_manager.h" | 18 #include "chromeos/dbus/dbus_thread_manager.h" |
19 #include "dbus/bus.h" | 19 #include "dbus/bus.h" |
20 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 20 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
21 #include "device/bluetooth/bluetooth_pairing_chromeos.h" | 21 #include "device/bluetooth/bluetooth_pairing_chromeos.h" |
22 #include "device/bluetooth/bluetooth_profile_chromeos.h" | |
23 #include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h" | 22 #include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h" |
24 #include "device/bluetooth/bluetooth_socket.h" | 23 #include "device/bluetooth/bluetooth_socket.h" |
25 #include "device/bluetooth/bluetooth_socket_chromeos.h" | 24 #include "device/bluetooth/bluetooth_socket_chromeos.h" |
26 #include "device/bluetooth/bluetooth_socket_thread.h" | 25 #include "device/bluetooth/bluetooth_socket_thread.h" |
27 #include "device/bluetooth/bluetooth_uuid.h" | 26 #include "device/bluetooth/bluetooth_uuid.h" |
28 #include "third_party/cros_system_api/dbus/service_constants.h" | 27 #include "third_party/cros_system_api/dbus/service_constants.h" |
29 | 28 |
30 using device::BluetoothDevice; | 29 using device::BluetoothDevice; |
31 using device::BluetoothSocket; | 30 using device::BluetoothSocket; |
32 using device::BluetoothUUID; | 31 using device::BluetoothUUID; |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 callback), | 418 callback), |
420 base::Bind(&BluetoothDeviceChromeOS::OnDisconnectError, | 419 base::Bind(&BluetoothDeviceChromeOS::OnDisconnectError, |
421 weak_ptr_factory_.GetWeakPtr(), | 420 weak_ptr_factory_.GetWeakPtr(), |
422 error_callback)); | 421 error_callback)); |
423 } | 422 } |
424 | 423 |
425 void BluetoothDeviceChromeOS::Forget(const ErrorCallback& error_callback) { | 424 void BluetoothDeviceChromeOS::Forget(const ErrorCallback& error_callback) { |
426 VLOG(1) << object_path_.value() << ": Removing device"; | 425 VLOG(1) << object_path_.value() << ": Removing device"; |
427 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 426 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> |
428 RemoveDevice( | 427 RemoveDevice( |
429 adapter_->object_path_, | 428 adapter_->object_path(), |
430 object_path_, | 429 object_path_, |
431 base::Bind(&base::DoNothing), | 430 base::Bind(&base::DoNothing), |
432 base::Bind(&BluetoothDeviceChromeOS::OnForgetError, | 431 base::Bind(&BluetoothDeviceChromeOS::OnForgetError, |
433 weak_ptr_factory_.GetWeakPtr(), | 432 weak_ptr_factory_.GetWeakPtr(), |
434 error_callback)); | 433 error_callback)); |
435 } | 434 } |
436 | 435 |
437 void BluetoothDeviceChromeOS::ConnectToProfile( | 436 void BluetoothDeviceChromeOS::ConnectToProfile( |
438 device::BluetoothProfile* profile, | 437 device::BluetoothProfile* profile, |
439 const base::Closure& callback, | 438 const base::Closure& callback, |
440 const ConnectToProfileErrorCallback& error_callback) { | 439 const ConnectToProfileErrorCallback& error_callback) { |
441 BluetoothProfileChromeOS* profile_chromeos = | 440 // TODO(keybuK): Remove. |
442 static_cast<BluetoothProfileChromeOS*>(profile); | 441 error_callback.Run("Removed. Use chrome.bluetoothSocket.connect() instead."); |
443 VLOG(1) << object_path_.value() << ": Connecting profile: " | |
444 << profile_chromeos->uuid().canonical_value(); | |
445 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | |
446 ConnectProfile( | |
447 object_path_, | |
448 profile_chromeos->uuid().canonical_value(), | |
449 base::Bind( | |
450 &BluetoothDeviceChromeOS::OnConnectProfile, | |
451 weak_ptr_factory_.GetWeakPtr(), | |
452 profile, | |
453 callback), | |
454 base::Bind( | |
455 &BluetoothDeviceChromeOS::OnConnectProfileError, | |
456 weak_ptr_factory_.GetWeakPtr(), | |
457 profile, | |
458 error_callback)); | |
459 } | 442 } |
460 | 443 |
461 void BluetoothDeviceChromeOS::ConnectToService( | 444 void BluetoothDeviceChromeOS::ConnectToService( |
462 const BluetoothUUID& uuid, | 445 const BluetoothUUID& uuid, |
463 const ConnectToServiceCallback& callback, | 446 const ConnectToServiceCallback& callback, |
464 const ConnectToServiceErrorCallback& error_callback) { | 447 const ConnectToServiceErrorCallback& error_callback) { |
465 // TODO(keybuk): implement | 448 VLOG(1) << object_path_.value() << ": Connecting to service: " |
466 NOTIMPLEMENTED(); | 449 << uuid.canonical_value(); |
| 450 scoped_refptr<BluetoothSocketChromeOS> socket = |
| 451 BluetoothSocketChromeOS::CreateBluetoothSocket( |
| 452 ui_task_runner_, |
| 453 socket_thread_, |
| 454 NULL, |
| 455 net::NetLog::Source()); |
| 456 socket->Connect(this, uuid, |
| 457 base::Bind(callback, socket), |
| 458 error_callback); |
467 } | 459 } |
468 | 460 |
469 void BluetoothDeviceChromeOS::SetOutOfBandPairingData( | 461 void BluetoothDeviceChromeOS::SetOutOfBandPairingData( |
470 const device::BluetoothOutOfBandPairingData& data, | 462 const device::BluetoothOutOfBandPairingData& data, |
471 const base::Closure& callback, | 463 const base::Closure& callback, |
472 const ErrorCallback& error_callback) { | 464 const ErrorCallback& error_callback) { |
473 // TODO(keybuk): implement | 465 // TODO(keybuk): implement |
474 error_callback.Run(); | 466 error_callback.Run(); |
475 } | 467 } |
476 | 468 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 | 714 |
723 void BluetoothDeviceChromeOS::OnForgetError( | 715 void BluetoothDeviceChromeOS::OnForgetError( |
724 const ErrorCallback& error_callback, | 716 const ErrorCallback& error_callback, |
725 const std::string& error_name, | 717 const std::string& error_name, |
726 const std::string& error_message) { | 718 const std::string& error_message) { |
727 LOG(WARNING) << object_path_.value() << ": Failed to remove device: " | 719 LOG(WARNING) << object_path_.value() << ": Failed to remove device: " |
728 << error_name << ": " << error_message; | 720 << error_name << ": " << error_message; |
729 error_callback.Run(); | 721 error_callback.Run(); |
730 } | 722 } |
731 | 723 |
732 void BluetoothDeviceChromeOS::OnConnectProfile( | |
733 device::BluetoothProfile* profile, | |
734 const base::Closure& callback) { | |
735 BluetoothProfileChromeOS* profile_chromeos = | |
736 static_cast<BluetoothProfileChromeOS*>(profile); | |
737 VLOG(1) << object_path_.value() << ": Profile connected: " | |
738 << profile_chromeos->uuid().canonical_value(); | |
739 callback.Run(); | |
740 } | |
741 | |
742 void BluetoothDeviceChromeOS::OnConnectProfileError( | |
743 device::BluetoothProfile* profile, | |
744 const ConnectToProfileErrorCallback& error_callback, | |
745 const std::string& error_name, | |
746 const std::string& error_message) { | |
747 BluetoothProfileChromeOS* profile_chromeos = | |
748 static_cast<BluetoothProfileChromeOS*>(profile); | |
749 VLOG(1) << object_path_.value() << ": Profile connection failed: " | |
750 << profile_chromeos->uuid().canonical_value() << ": " | |
751 << error_name << ": " << error_message; | |
752 error_callback.Run(error_message); | |
753 } | |
754 | |
755 } // namespace chromeos | 724 } // namespace chromeos |
OLD | NEW |