| 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" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 namespace chromeos { | 121 namespace chromeos { |
| 122 | 122 |
| 123 BluetoothDeviceChromeOS::BluetoothDeviceChromeOS( | 123 BluetoothDeviceChromeOS::BluetoothDeviceChromeOS( |
| 124 BluetoothAdapterChromeOS* adapter, | 124 BluetoothAdapterChromeOS* adapter, |
| 125 const dbus::ObjectPath& object_path, | 125 const dbus::ObjectPath& object_path, |
| 126 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 126 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 127 scoped_refptr<device::BluetoothSocketThread> socket_thread) | 127 scoped_refptr<device::BluetoothSocketThread> socket_thread) |
| 128 : adapter_(adapter), | 128 : adapter_(adapter), |
| 129 object_path_(object_path), | 129 object_path_(object_path), |
| 130 num_connecting_calls_(0), | 130 num_connecting_calls_(0), |
| 131 connection_monitor_started_(false), |
| 131 ui_task_runner_(ui_task_runner), | 132 ui_task_runner_(ui_task_runner), |
| 132 socket_thread_(socket_thread), | 133 socket_thread_(socket_thread), |
| 133 weak_ptr_factory_(this) { | 134 weak_ptr_factory_(this) { |
| 134 DBusThreadManager::Get()->GetBluetoothGattServiceClient()->AddObserver(this); | 135 DBusThreadManager::Get()->GetBluetoothGattServiceClient()->AddObserver(this); |
| 135 | 136 |
| 136 // Add all known GATT services. | 137 // Add all known GATT services. |
| 137 const std::vector<dbus::ObjectPath> gatt_services = | 138 const std::vector<dbus::ObjectPath> gatt_services = |
| 138 DBusThreadManager::Get()->GetBluetoothGattServiceClient()->GetServices(); | 139 DBusThreadManager::Get()->GetBluetoothGattServiceClient()->GetServices(); |
| 139 for (std::vector<dbus::ObjectPath>::const_iterator it = gatt_services.begin(); | 140 for (std::vector<dbus::ObjectPath>::const_iterator it = gatt_services.begin(); |
| 140 it != gatt_services.end(); ++it) { | 141 it != gatt_services.end(); ++it) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 return product_id; | 217 return product_id; |
| 217 } | 218 } |
| 218 | 219 |
| 219 uint16 BluetoothDeviceChromeOS::GetDeviceID() const { | 220 uint16 BluetoothDeviceChromeOS::GetDeviceID() const { |
| 220 uint16 device_id = 0; | 221 uint16 device_id = 0; |
| 221 ParseModalias(object_path_, NULL, NULL, NULL, &device_id); | 222 ParseModalias(object_path_, NULL, NULL, NULL, &device_id); |
| 222 return device_id; | 223 return device_id; |
| 223 } | 224 } |
| 224 | 225 |
| 225 int BluetoothDeviceChromeOS::GetRSSI() const { | 226 int BluetoothDeviceChromeOS::GetRSSI() const { |
| 226 NOTIMPLEMENTED(); | 227 BluetoothDeviceClient::Properties* properties = |
| 227 return kUnknownPower; | 228 DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 229 object_path_); |
| 230 DCHECK(properties); |
| 231 |
| 232 if (!IsConnected()) { |
| 233 NOTIMPLEMENTED(); |
| 234 return kUnknownPower; |
| 235 } |
| 236 |
| 237 return connection_monitor_started_ ? properties->connection_rssi.value() |
| 238 : kUnknownPower; |
| 228 } | 239 } |
| 229 | 240 |
| 230 int BluetoothDeviceChromeOS::GetCurrentHostTransmitPower() const { | 241 int BluetoothDeviceChromeOS::GetCurrentHostTransmitPower() const { |
| 231 NOTIMPLEMENTED(); | 242 BluetoothDeviceClient::Properties* properties = |
| 232 return kUnknownPower; | 243 DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 244 object_path_); |
| 245 DCHECK(properties); |
| 246 |
| 247 return IsConnected() && connection_monitor_started_ |
| 248 ? properties->connection_tx_power.value() |
| 249 : kUnknownPower; |
| 233 } | 250 } |
| 234 | 251 |
| 235 int BluetoothDeviceChromeOS::GetMaximumHostTransmitPower() const { | 252 int BluetoothDeviceChromeOS::GetMaximumHostTransmitPower() const { |
| 236 NOTIMPLEMENTED(); | 253 BluetoothDeviceClient::Properties* properties = |
| 237 return kUnknownPower; | 254 DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 255 object_path_); |
| 256 DCHECK(properties); |
| 257 |
| 258 return IsConnected() ? properties->connection_tx_power_max.value() |
| 259 : kUnknownPower; |
| 238 } | 260 } |
| 239 | 261 |
| 240 bool BluetoothDeviceChromeOS::IsPaired() const { | 262 bool BluetoothDeviceChromeOS::IsPaired() const { |
| 241 BluetoothDeviceClient::Properties* properties = | 263 BluetoothDeviceClient::Properties* properties = |
| 242 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 264 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> |
| 243 GetProperties(object_path_); | 265 GetProperties(object_path_); |
| 244 DCHECK(properties); | 266 DCHECK(properties); |
| 245 | 267 |
| 246 // Trusted devices are devices that don't support pairing but that the | 268 // Trusted devices are devices that don't support pairing but that the |
| 247 // user has explicitly connected; it makes no sense for UI purposes to | 269 // user has explicitly connected; it makes no sense for UI purposes to |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 error_callback.Run(); | 474 error_callback.Run(); |
| 453 } | 475 } |
| 454 | 476 |
| 455 void BluetoothDeviceChromeOS::ClearOutOfBandPairingData( | 477 void BluetoothDeviceChromeOS::ClearOutOfBandPairingData( |
| 456 const base::Closure& callback, | 478 const base::Closure& callback, |
| 457 const ErrorCallback& error_callback) { | 479 const ErrorCallback& error_callback) { |
| 458 // TODO(keybuk): implement | 480 // TODO(keybuk): implement |
| 459 error_callback.Run(); | 481 error_callback.Run(); |
| 460 } | 482 } |
| 461 | 483 |
| 484 void BluetoothDeviceChromeOS::StartConnectionMonitor( |
| 485 const base::Closure& callback, |
| 486 const ErrorCallback& error_callback) { |
| 487 DBusThreadManager::Get()->GetBluetoothDeviceClient()->StartConnectionMonitor( |
| 488 object_path_, |
| 489 base::Bind(&BluetoothDeviceChromeOS::OnStartConnectionMonitor, |
| 490 weak_ptr_factory_.GetWeakPtr(), |
| 491 callback), |
| 492 base::Bind(&BluetoothDeviceChromeOS::OnStartConnectionMonitorError, |
| 493 weak_ptr_factory_.GetWeakPtr(), |
| 494 error_callback)); |
| 495 } |
| 496 |
| 497 void BluetoothDeviceChromeOS::StopConnectionMonitor( |
| 498 const base::Closure& callback, |
| 499 const ErrorCallback& error_callback) { |
| 500 NOTIMPLEMENTED(); |
| 501 } |
| 502 |
| 462 BluetoothPairingChromeOS* BluetoothDeviceChromeOS::BeginPairing( | 503 BluetoothPairingChromeOS* BluetoothDeviceChromeOS::BeginPairing( |
| 463 BluetoothDevice::PairingDelegate* pairing_delegate) { | 504 BluetoothDevice::PairingDelegate* pairing_delegate) { |
| 464 pairing_.reset(new BluetoothPairingChromeOS(this, pairing_delegate)); | 505 pairing_.reset(new BluetoothPairingChromeOS(this, pairing_delegate)); |
| 465 return pairing_.get(); | 506 return pairing_.get(); |
| 466 } | 507 } |
| 467 | 508 |
| 468 void BluetoothDeviceChromeOS::EndPairing() { | 509 void BluetoothDeviceChromeOS::EndPairing() { |
| 469 pairing_.reset(); | 510 pairing_.reset(); |
| 470 } | 511 } |
| 471 | 512 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 true, | 689 true, |
| 649 base::Bind(&BluetoothDeviceChromeOS::OnSetTrusted, | 690 base::Bind(&BluetoothDeviceChromeOS::OnSetTrusted, |
| 650 weak_ptr_factory_.GetWeakPtr())); | 691 weak_ptr_factory_.GetWeakPtr())); |
| 651 } | 692 } |
| 652 | 693 |
| 653 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { | 694 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { |
| 654 LOG_IF(WARNING, !success) << object_path_.value() | 695 LOG_IF(WARNING, !success) << object_path_.value() |
| 655 << ": Failed to set device as trusted"; | 696 << ": Failed to set device as trusted"; |
| 656 } | 697 } |
| 657 | 698 |
| 699 void BluetoothDeviceChromeOS::OnStartConnectionMonitor( |
| 700 const base::Closure& callback) { |
| 701 connection_monitor_started_ = true; |
| 702 callback.Run(); |
| 703 } |
| 704 |
| 705 void BluetoothDeviceChromeOS::OnStartConnectionMonitorError( |
| 706 const ErrorCallback& error_callback, |
| 707 const std::string& error_name, |
| 708 const std::string& error_message) { |
| 709 connection_monitor_started_ = false; |
| 710 LOG(WARNING) << object_path_.value() |
| 711 << ": Failed to start connection monitor: " << error_name << ": " |
| 712 << error_message; |
| 713 error_callback.Run(); |
| 714 } |
| 715 |
| 658 void BluetoothDeviceChromeOS::OnDisconnect(const base::Closure& callback) { | 716 void BluetoothDeviceChromeOS::OnDisconnect(const base::Closure& callback) { |
| 659 VLOG(1) << object_path_.value() << ": Disconnected"; | 717 VLOG(1) << object_path_.value() << ": Disconnected"; |
| 660 callback.Run(); | 718 callback.Run(); |
| 661 } | 719 } |
| 662 | 720 |
| 663 void BluetoothDeviceChromeOS::OnDisconnectError( | 721 void BluetoothDeviceChromeOS::OnDisconnectError( |
| 664 const ErrorCallback& error_callback, | 722 const ErrorCallback& error_callback, |
| 665 const std::string& error_name, | 723 const std::string& error_name, |
| 666 const std::string& error_message) { | 724 const std::string& error_message) { |
| 667 LOG(WARNING) << object_path_.value() << ": Failed to disconnect device: " | 725 LOG(WARNING) << object_path_.value() << ": Failed to disconnect device: " |
| (...skipping 27 matching lines...) Expand all Loading... |
| 695 const std::string& error_message) { | 753 const std::string& error_message) { |
| 696 BluetoothProfileChromeOS* profile_chromeos = | 754 BluetoothProfileChromeOS* profile_chromeos = |
| 697 static_cast<BluetoothProfileChromeOS*>(profile); | 755 static_cast<BluetoothProfileChromeOS*>(profile); |
| 698 VLOG(1) << object_path_.value() << ": Profile connection failed: " | 756 VLOG(1) << object_path_.value() << ": Profile connection failed: " |
| 699 << profile_chromeos->uuid().canonical_value() << ": " | 757 << profile_chromeos->uuid().canonical_value() << ": " |
| 700 << error_name << ": " << error_message; | 758 << error_name << ": " << error_message; |
| 701 error_callback.Run(error_message); | 759 error_callback.Run(error_message); |
| 702 } | 760 } |
| 703 | 761 |
| 704 } // namespace chromeos | 762 } // namespace chromeos |
| OLD | NEW |