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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 return product_id; | 216 return product_id; |
217 } | 217 } |
218 | 218 |
219 uint16 BluetoothDeviceChromeOS::GetDeviceID() const { | 219 uint16 BluetoothDeviceChromeOS::GetDeviceID() const { |
220 uint16 device_id = 0; | 220 uint16 device_id = 0; |
221 ParseModalias(object_path_, NULL, NULL, NULL, &device_id); | 221 ParseModalias(object_path_, NULL, NULL, NULL, &device_id); |
222 return device_id; | 222 return device_id; |
223 } | 223 } |
224 | 224 |
225 int BluetoothDeviceChromeOS::GetRSSI() const { | 225 int BluetoothDeviceChromeOS::GetRSSI() const { |
226 NOTIMPLEMENTED(); | 226 BluetoothDeviceClient::Properties* properties = |
227 return kUnknownPower; | 227 DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
228 object_path_); | |
229 DCHECK(properties); | |
230 | |
231 return IsConnected() ? properties->connection_rssi.value() | |
232 : properties->inquiry_rssi.value(); | |
keybuk
2014/05/09 00:35:25
Do we really want to conflate these properties int
Tim Song
2014/05/09 02:55:29
It does make sense to have a connection RSSI and a
keybuk
2014/05/09 18:22:07
That separate CL will be much easier if you only s
Tim Song
2014/05/09 19:01:35
Done.
| |
228 } | 233 } |
229 | 234 |
230 int BluetoothDeviceChromeOS::GetCurrentHostTransmitPower() const { | 235 int BluetoothDeviceChromeOS::GetCurrentHostTransmitPower() const { |
231 NOTIMPLEMENTED(); | 236 BluetoothDeviceClient::Properties* properties = |
232 return kUnknownPower; | 237 DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
238 object_path_); | |
239 DCHECK(properties); | |
240 | |
241 return IsConnected() ? properties->tx_power.value() : kUnknownPower; | |
233 } | 242 } |
234 | 243 |
235 int BluetoothDeviceChromeOS::GetMaximumHostTransmitPower() const { | 244 int BluetoothDeviceChromeOS::GetMaximumHostTransmitPower() const { |
236 NOTIMPLEMENTED(); | 245 BluetoothDeviceClient::Properties* properties = |
237 return kUnknownPower; | 246 DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
247 object_path_); | |
248 DCHECK(properties); | |
249 | |
250 return IsConnected() ? properties->tx_power_max.value() : kUnknownPower; | |
238 } | 251 } |
239 | 252 |
240 bool BluetoothDeviceChromeOS::IsPaired() const { | 253 bool BluetoothDeviceChromeOS::IsPaired() const { |
241 BluetoothDeviceClient::Properties* properties = | 254 BluetoothDeviceClient::Properties* properties = |
242 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 255 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> |
243 GetProperties(object_path_); | 256 GetProperties(object_path_); |
244 DCHECK(properties); | 257 DCHECK(properties); |
245 | 258 |
246 // Trusted devices are devices that don't support pairing but that the | 259 // 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 | 260 // user has explicitly connected; it makes no sense for UI purposes to |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 void BluetoothDeviceChromeOS::OnConnect(bool after_pairing, | 554 void BluetoothDeviceChromeOS::OnConnect(bool after_pairing, |
542 const base::Closure& callback) { | 555 const base::Closure& callback) { |
543 if (--num_connecting_calls_ == 0) | 556 if (--num_connecting_calls_ == 0) |
544 adapter_->NotifyDeviceChanged(this); | 557 adapter_->NotifyDeviceChanged(this); |
545 | 558 |
546 DCHECK(num_connecting_calls_ >= 0); | 559 DCHECK(num_connecting_calls_ >= 0); |
547 VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_ | 560 VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_ |
548 << " still in progress"; | 561 << " still in progress"; |
549 | 562 |
550 SetTrusted(); | 563 SetTrusted(); |
564 StartConnectionMonitor(); | |
keybuk
2014/05/09 00:35:25
NAK, doing a connection monitor for every single p
Tim Song
2014/05/09 02:55:29
In that case, should we add an API in chrome.bluet
keybuk
2014/05/09 18:22:07
Yes.
Tim Song
2014/05/09 19:01:35
Okay, I'll add this API function in the other CL.
| |
551 | 565 |
552 if (after_pairing) | 566 if (after_pairing) |
553 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingResult", | 567 UMA_HISTOGRAM_ENUMERATION("Bluetooth.PairingResult", |
554 UMA_PAIRING_RESULT_SUCCESS, | 568 UMA_PAIRING_RESULT_SUCCESS, |
555 UMA_PAIRING_RESULT_COUNT); | 569 UMA_PAIRING_RESULT_COUNT); |
556 | 570 |
557 callback.Run(); | 571 callback.Run(); |
558 } | 572 } |
559 | 573 |
560 void BluetoothDeviceChromeOS::OnConnectError( | 574 void BluetoothDeviceChromeOS::OnConnectError( |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
648 true, | 662 true, |
649 base::Bind(&BluetoothDeviceChromeOS::OnSetTrusted, | 663 base::Bind(&BluetoothDeviceChromeOS::OnSetTrusted, |
650 weak_ptr_factory_.GetWeakPtr())); | 664 weak_ptr_factory_.GetWeakPtr())); |
651 } | 665 } |
652 | 666 |
653 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { | 667 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { |
654 LOG_IF(WARNING, !success) << object_path_.value() | 668 LOG_IF(WARNING, !success) << object_path_.value() |
655 << ": Failed to set device as trusted"; | 669 << ": Failed to set device as trusted"; |
656 } | 670 } |
657 | 671 |
672 void BluetoothDeviceChromeOS::StartConnectionMonitor() { | |
673 DBusThreadManager::Get()->GetBluetoothDeviceClient()->StartConnectionMonitor( | |
674 object_path_, | |
675 base::Bind(&base::DoNothing), | |
676 base::Bind(&BluetoothDeviceChromeOS::OnStartConnectionMonitorError, | |
677 weak_ptr_factory_.GetWeakPtr())); | |
678 } | |
679 | |
680 void BluetoothDeviceChromeOS::OnStartConnectionMonitorError( | |
681 const std::string& error_name, | |
682 const std::string& error_message) { | |
683 LOG(WARNING) << object_path_.value() | |
684 << ": Failed to start connection monitor: " << error_name << ": " | |
685 << error_message; | |
686 } | |
687 | |
658 void BluetoothDeviceChromeOS::OnDisconnect(const base::Closure& callback) { | 688 void BluetoothDeviceChromeOS::OnDisconnect(const base::Closure& callback) { |
659 VLOG(1) << object_path_.value() << ": Disconnected"; | 689 VLOG(1) << object_path_.value() << ": Disconnected"; |
660 callback.Run(); | 690 callback.Run(); |
661 } | 691 } |
662 | 692 |
663 void BluetoothDeviceChromeOS::OnDisconnectError( | 693 void BluetoothDeviceChromeOS::OnDisconnectError( |
664 const ErrorCallback& error_callback, | 694 const ErrorCallback& error_callback, |
665 const std::string& error_name, | 695 const std::string& error_name, |
666 const std::string& error_message) { | 696 const std::string& error_message) { |
667 LOG(WARNING) << object_path_.value() << ": Failed to disconnect device: " | 697 LOG(WARNING) << object_path_.value() << ": Failed to disconnect device: " |
(...skipping 27 matching lines...) Expand all Loading... | |
695 const std::string& error_message) { | 725 const std::string& error_message) { |
696 BluetoothProfileChromeOS* profile_chromeos = | 726 BluetoothProfileChromeOS* profile_chromeos = |
697 static_cast<BluetoothProfileChromeOS*>(profile); | 727 static_cast<BluetoothProfileChromeOS*>(profile); |
698 VLOG(1) << object_path_.value() << ": Profile connection failed: " | 728 VLOG(1) << object_path_.value() << ": Profile connection failed: " |
699 << profile_chromeos->uuid().canonical_value() << ": " | 729 << profile_chromeos->uuid().canonical_value() << ": " |
700 << error_name << ": " << error_message; | 730 << error_name << ": " << error_message; |
701 error_callback.Run(error_message); | 731 error_callback.Run(error_message); |
702 } | 732 } |
703 | 733 |
704 } // namespace chromeos | 734 } // namespace chromeos |
OLD | NEW |