| 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 |
| 462 BluetoothPairingChromeOS* BluetoothDeviceChromeOS::BeginPairing( | 497 BluetoothPairingChromeOS* BluetoothDeviceChromeOS::BeginPairing( |
| 463 BluetoothDevice::PairingDelegate* pairing_delegate) { | 498 BluetoothDevice::PairingDelegate* pairing_delegate) { |
| 464 pairing_.reset(new BluetoothPairingChromeOS(this, pairing_delegate)); | 499 pairing_.reset(new BluetoothPairingChromeOS(this, pairing_delegate)); |
| 465 return pairing_.get(); | 500 return pairing_.get(); |
| 466 } | 501 } |
| 467 | 502 |
| 468 void BluetoothDeviceChromeOS::EndPairing() { | 503 void BluetoothDeviceChromeOS::EndPairing() { |
| 469 pairing_.reset(); | 504 pairing_.reset(); |
| 470 } | 505 } |
| 471 | 506 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 true, | 683 true, |
| 649 base::Bind(&BluetoothDeviceChromeOS::OnSetTrusted, | 684 base::Bind(&BluetoothDeviceChromeOS::OnSetTrusted, |
| 650 weak_ptr_factory_.GetWeakPtr())); | 685 weak_ptr_factory_.GetWeakPtr())); |
| 651 } | 686 } |
| 652 | 687 |
| 653 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { | 688 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { |
| 654 LOG_IF(WARNING, !success) << object_path_.value() | 689 LOG_IF(WARNING, !success) << object_path_.value() |
| 655 << ": Failed to set device as trusted"; | 690 << ": Failed to set device as trusted"; |
| 656 } | 691 } |
| 657 | 692 |
| 693 void BluetoothDeviceChromeOS::OnStartConnectionMonitor( |
| 694 const base::Closure& callback) { |
| 695 connection_monitor_started_ = true; |
| 696 callback.Run(); |
| 697 } |
| 698 |
| 699 void BluetoothDeviceChromeOS::OnStartConnectionMonitorError( |
| 700 const ErrorCallback& error_callback, |
| 701 const std::string& error_name, |
| 702 const std::string& error_message) { |
| 703 LOG(WARNING) << object_path_.value() |
| 704 << ": Failed to start connection monitor: " << error_name << ": " |
| 705 << error_message; |
| 706 error_callback.Run(); |
| 707 } |
| 708 |
| 658 void BluetoothDeviceChromeOS::OnDisconnect(const base::Closure& callback) { | 709 void BluetoothDeviceChromeOS::OnDisconnect(const base::Closure& callback) { |
| 659 VLOG(1) << object_path_.value() << ": Disconnected"; | 710 VLOG(1) << object_path_.value() << ": Disconnected"; |
| 660 callback.Run(); | 711 callback.Run(); |
| 661 } | 712 } |
| 662 | 713 |
| 663 void BluetoothDeviceChromeOS::OnDisconnectError( | 714 void BluetoothDeviceChromeOS::OnDisconnectError( |
| 664 const ErrorCallback& error_callback, | 715 const ErrorCallback& error_callback, |
| 665 const std::string& error_name, | 716 const std::string& error_name, |
| 666 const std::string& error_message) { | 717 const std::string& error_message) { |
| 667 LOG(WARNING) << object_path_.value() << ": Failed to disconnect device: " | 718 LOG(WARNING) << object_path_.value() << ": Failed to disconnect device: " |
| (...skipping 27 matching lines...) Expand all Loading... |
| 695 const std::string& error_message) { | 746 const std::string& error_message) { |
| 696 BluetoothProfileChromeOS* profile_chromeos = | 747 BluetoothProfileChromeOS* profile_chromeos = |
| 697 static_cast<BluetoothProfileChromeOS*>(profile); | 748 static_cast<BluetoothProfileChromeOS*>(profile); |
| 698 VLOG(1) << object_path_.value() << ": Profile connection failed: " | 749 VLOG(1) << object_path_.value() << ": Profile connection failed: " |
| 699 << profile_chromeos->uuid().canonical_value() << ": " | 750 << profile_chromeos->uuid().canonical_value() << ": " |
| 700 << error_name << ": " << error_message; | 751 << error_name << ": " << error_message; |
| 701 error_callback.Run(error_message); | 752 error_callback.Run(error_message); |
| 702 } | 753 } |
| 703 | 754 |
| 704 } // namespace chromeos | 755 } // namespace chromeos |
| OLD | NEW |