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

Side by Side Diff: device/bluetooth/bluetooth_device_chromeos.cc

Issue 735893002: Add GetConnectionInfo function for BluetoothDevice, replacing the existing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile errors on other platforms Created 5 years, 11 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
« no previous file with comments | « device/bluetooth/bluetooth_device_chromeos.h ('k') | device/bluetooth/bluetooth_device_mac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 ParseModalias(object_path_, NULL, NULL, &product_id, NULL); 205 ParseModalias(object_path_, NULL, NULL, &product_id, NULL);
206 return product_id; 206 return product_id;
207 } 207 }
208 208
209 uint16 BluetoothDeviceChromeOS::GetDeviceID() const { 209 uint16 BluetoothDeviceChromeOS::GetDeviceID() const {
210 uint16 device_id = 0; 210 uint16 device_id = 0;
211 ParseModalias(object_path_, NULL, NULL, NULL, &device_id); 211 ParseModalias(object_path_, NULL, NULL, NULL, &device_id);
212 return device_id; 212 return device_id;
213 } 213 }
214 214
215 int BluetoothDeviceChromeOS::GetRSSI() const {
216 BluetoothDeviceClient::Properties* properties =
217 DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties(
218 object_path_);
219 DCHECK(properties);
220
221 if (!IsConnected()) {
222 NOTIMPLEMENTED();
223 return kUnknownPower;
224 }
225
226 return connection_monitor_started_ ? properties->connection_rssi.value()
227 : kUnknownPower;
228 }
229
230 int BluetoothDeviceChromeOS::GetCurrentHostTransmitPower() const {
231 BluetoothDeviceClient::Properties* properties =
232 DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties(
233 object_path_);
234 DCHECK(properties);
235
236 return IsConnected() && connection_monitor_started_
237 ? properties->connection_tx_power.value()
238 : kUnknownPower;
239 }
240
241 int BluetoothDeviceChromeOS::GetMaximumHostTransmitPower() const {
242 BluetoothDeviceClient::Properties* properties =
243 DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties(
244 object_path_);
245 DCHECK(properties);
246
247 return IsConnected() ? properties->connection_tx_power_max.value()
248 : kUnknownPower;
249 }
250
251 bool BluetoothDeviceChromeOS::IsPaired() const { 215 bool BluetoothDeviceChromeOS::IsPaired() const {
252 BluetoothDeviceClient::Properties* properties = 216 BluetoothDeviceClient::Properties* properties =
253 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> 217 DBusThreadManager::Get()->GetBluetoothDeviceClient()->
254 GetProperties(object_path_); 218 GetProperties(object_path_);
255 DCHECK(properties); 219 DCHECK(properties);
256 220
257 // Trusted devices are devices that don't support pairing but that the 221 // Trusted devices are devices that don't support pairing but that the
258 // user has explicitly connected; it makes no sense for UI purposes to 222 // user has explicitly connected; it makes no sense for UI purposes to
259 // treat them differently from each other. 223 // treat them differently from each other.
260 return properties->paired.value() || properties->trusted.value(); 224 return properties->paired.value() || properties->trusted.value();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } 271 }
308 272
309 bool BluetoothDeviceChromeOS::ExpectingPasskey() const { 273 bool BluetoothDeviceChromeOS::ExpectingPasskey() const {
310 return pairing_.get() && pairing_->ExpectingPasskey(); 274 return pairing_.get() && pairing_->ExpectingPasskey();
311 } 275 }
312 276
313 bool BluetoothDeviceChromeOS::ExpectingConfirmation() const { 277 bool BluetoothDeviceChromeOS::ExpectingConfirmation() const {
314 return pairing_.get() && pairing_->ExpectingConfirmation(); 278 return pairing_.get() && pairing_->ExpectingConfirmation();
315 } 279 }
316 280
281 void BluetoothDeviceChromeOS::GetConnectionInfo(
282 const ConnectionInfoCallback& callback) {
283 // DBus method call should gracefully return an error if the device is not
284 // currently connected.
285 DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetConnInfo(
286 object_path_, base::Bind(&BluetoothDeviceChromeOS::OnGetConnInfo,
287 weak_ptr_factory_.GetWeakPtr(), callback),
288 base::Bind(&BluetoothDeviceChromeOS::OnGetConnInfoError,
289 weak_ptr_factory_.GetWeakPtr(), callback));
290 }
291
317 void BluetoothDeviceChromeOS::Connect( 292 void BluetoothDeviceChromeOS::Connect(
318 BluetoothDevice::PairingDelegate* pairing_delegate, 293 BluetoothDevice::PairingDelegate* pairing_delegate,
319 const base::Closure& callback, 294 const base::Closure& callback,
320 const ConnectErrorCallback& error_callback) { 295 const ConnectErrorCallback& error_callback) {
321 if (num_connecting_calls_++ == 0) 296 if (num_connecting_calls_++ == 0)
322 adapter_->NotifyDeviceChanged(this); 297 adapter_->NotifyDeviceChanged(this);
323 298
324 VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_ 299 VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_
325 << " in progress"; 300 << " in progress";
326 301
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 const ConnectErrorCallback& error_callback) { 429 const ConnectErrorCallback& error_callback) {
455 // TODO(armansito): Until there is a way to create a reference counted GATT 430 // TODO(armansito): Until there is a way to create a reference counted GATT
456 // connection in bluetoothd, simply do a regular connect. 431 // connection in bluetoothd, simply do a regular connect.
457 Connect(NULL, 432 Connect(NULL,
458 base::Bind(&BluetoothDeviceChromeOS::OnCreateGattConnection, 433 base::Bind(&BluetoothDeviceChromeOS::OnCreateGattConnection,
459 weak_ptr_factory_.GetWeakPtr(), 434 weak_ptr_factory_.GetWeakPtr(),
460 callback), 435 callback),
461 error_callback); 436 error_callback);
462 } 437 }
463 438
464 void BluetoothDeviceChromeOS::StartConnectionMonitor(
465 const base::Closure& callback,
466 const ErrorCallback& error_callback) {
467 DBusThreadManager::Get()->GetBluetoothDeviceClient()->StartConnectionMonitor(
468 object_path_,
469 base::Bind(&BluetoothDeviceChromeOS::OnStartConnectionMonitor,
470 weak_ptr_factory_.GetWeakPtr(),
471 callback),
472 base::Bind(&BluetoothDeviceChromeOS::OnStartConnectionMonitorError,
473 weak_ptr_factory_.GetWeakPtr(),
474 error_callback));
475 }
476
477 BluetoothPairingChromeOS* BluetoothDeviceChromeOS::BeginPairing( 439 BluetoothPairingChromeOS* BluetoothDeviceChromeOS::BeginPairing(
478 BluetoothDevice::PairingDelegate* pairing_delegate) { 440 BluetoothDevice::PairingDelegate* pairing_delegate) {
479 pairing_.reset(new BluetoothPairingChromeOS(this, pairing_delegate)); 441 pairing_.reset(new BluetoothPairingChromeOS(this, pairing_delegate));
480 return pairing_.get(); 442 return pairing_.get();
481 } 443 }
482 444
483 void BluetoothDeviceChromeOS::EndPairing() { 445 void BluetoothDeviceChromeOS::EndPairing() {
484 pairing_.reset(); 446 pairing_.reset();
485 } 447 }
486 448
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 static_cast<BluetoothRemoteGattServiceChromeOS*>(iter->second); 493 static_cast<BluetoothRemoteGattServiceChromeOS*>(iter->second);
532 DCHECK(service->object_path() == object_path); 494 DCHECK(service->object_path() == object_path);
533 gatt_services_.erase(iter); 495 gatt_services_.erase(iter);
534 496
535 DCHECK(adapter_); 497 DCHECK(adapter_);
536 adapter_->NotifyGattServiceRemoved(service); 498 adapter_->NotifyGattServiceRemoved(service);
537 499
538 delete service; 500 delete service;
539 } 501 }
540 502
503 void BluetoothDeviceChromeOS::OnGetConnInfo(
504 const ConnectionInfoCallback& callback,
505 int16 rssi,
506 int16 transmit_power,
507 int16 max_transmit_power) {
508 callback.Run(ConnectionInfo(rssi, transmit_power, max_transmit_power));
509 }
510
511 void BluetoothDeviceChromeOS::OnGetConnInfoError(
512 const ConnectionInfoCallback& callback,
513 const std::string& error_name,
514 const std::string& error_message) {
515 LOG(WARNING) << object_path_.value()
516 << ": Failed to get connection info: " << error_name << ": "
517 << error_message;
518 callback.Run(ConnectionInfo());
519 }
520
541 void BluetoothDeviceChromeOS::ConnectInternal( 521 void BluetoothDeviceChromeOS::ConnectInternal(
542 bool after_pairing, 522 bool after_pairing,
543 const base::Closure& callback, 523 const base::Closure& callback,
544 const ConnectErrorCallback& error_callback) { 524 const ConnectErrorCallback& error_callback) {
545 VLOG(1) << object_path_.value() << ": Connecting"; 525 VLOG(1) << object_path_.value() << ": Connecting";
546 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> 526 DBusThreadManager::Get()->GetBluetoothDeviceClient()->
547 Connect( 527 Connect(
548 object_path_, 528 object_path_,
549 base::Bind(&BluetoothDeviceChromeOS::OnConnect, 529 base::Bind(&BluetoothDeviceChromeOS::OnConnect,
550 weak_ptr_factory_.GetWeakPtr(), 530 weak_ptr_factory_.GetWeakPtr(),
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 true, 654 true,
675 base::Bind(&BluetoothDeviceChromeOS::OnSetTrusted, 655 base::Bind(&BluetoothDeviceChromeOS::OnSetTrusted,
676 weak_ptr_factory_.GetWeakPtr())); 656 weak_ptr_factory_.GetWeakPtr()));
677 } 657 }
678 658
679 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { 659 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) {
680 LOG_IF(WARNING, !success) << object_path_.value() 660 LOG_IF(WARNING, !success) << object_path_.value()
681 << ": Failed to set device as trusted"; 661 << ": Failed to set device as trusted";
682 } 662 }
683 663
684 void BluetoothDeviceChromeOS::OnStartConnectionMonitor(
685 const base::Closure& callback) {
686 connection_monitor_started_ = true;
687 callback.Run();
688 }
689
690 void BluetoothDeviceChromeOS::OnStartConnectionMonitorError(
691 const ErrorCallback& error_callback,
692 const std::string& error_name,
693 const std::string& error_message) {
694 LOG(WARNING) << object_path_.value()
695 << ": Failed to start connection monitor: " << error_name << ": "
696 << error_message;
697 error_callback.Run();
698 }
699
700 void BluetoothDeviceChromeOS::OnDisconnect(const base::Closure& callback) { 664 void BluetoothDeviceChromeOS::OnDisconnect(const base::Closure& callback) {
701 VLOG(1) << object_path_.value() << ": Disconnected"; 665 VLOG(1) << object_path_.value() << ": Disconnected";
702 callback.Run(); 666 callback.Run();
703 } 667 }
704 668
705 void BluetoothDeviceChromeOS::OnDisconnectError( 669 void BluetoothDeviceChromeOS::OnDisconnectError(
706 const ErrorCallback& error_callback, 670 const ErrorCallback& error_callback,
707 const std::string& error_name, 671 const std::string& error_name,
708 const std::string& error_message) { 672 const std::string& error_message) {
709 LOG(WARNING) << object_path_.value() << ": Failed to disconnect device: " 673 LOG(WARNING) << object_path_.value() << ": Failed to disconnect device: "
710 << error_name << ": " << error_message; 674 << error_name << ": " << error_message;
711 error_callback.Run(); 675 error_callback.Run();
712 } 676 }
713 677
714 void BluetoothDeviceChromeOS::OnForgetError( 678 void BluetoothDeviceChromeOS::OnForgetError(
715 const ErrorCallback& error_callback, 679 const ErrorCallback& error_callback,
716 const std::string& error_name, 680 const std::string& error_name,
717 const std::string& error_message) { 681 const std::string& error_message) {
718 LOG(WARNING) << object_path_.value() << ": Failed to remove device: " 682 LOG(WARNING) << object_path_.value() << ": Failed to remove device: "
719 << error_name << ": " << error_message; 683 << error_name << ": " << error_message;
720 error_callback.Run(); 684 error_callback.Run();
721 } 685 }
722 686
723 } // namespace chromeos 687 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_device_chromeos.h ('k') | device/bluetooth/bluetooth_device_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698