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

Side by Side Diff: chromeos/dbus/fake_bluetooth_device_client.cc

Issue 273953002: Hook up RSSI and host transmit power Bluetooth device properties for ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix clang warnings, test flakiness, and bluetooth.connect should succeed even if monitor fails Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "chromeos/dbus/fake_bluetooth_device_client.h" 5 #include "chromeos/dbus/fake_bluetooth_device_client.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 property->ReplaceValueWithSetValue(); 213 property->ReplaceValueWithSetValue();
214 } else { 214 } else {
215 callback.Run(false); 215 callback.Run(false);
216 } 216 }
217 } 217 }
218 218
219 FakeBluetoothDeviceClient::FakeBluetoothDeviceClient() 219 FakeBluetoothDeviceClient::FakeBluetoothDeviceClient()
220 : simulation_interval_ms_(kSimulationIntervalMs), 220 : simulation_interval_ms_(kSimulationIntervalMs),
221 discovery_simulation_step_(0), 221 discovery_simulation_step_(0),
222 incoming_pairing_simulation_step_(0), 222 incoming_pairing_simulation_step_(0),
223 pairing_cancelled_(false) { 223 pairing_cancelled_(false),
224 connection_monitor_started_(false) {
224 Properties* properties = new Properties(base::Bind( 225 Properties* properties = new Properties(base::Bind(
225 &FakeBluetoothDeviceClient::OnPropertyChanged, 226 &FakeBluetoothDeviceClient::OnPropertyChanged,
226 base::Unretained(this), 227 base::Unretained(this),
227 dbus::ObjectPath(kPairedDevicePath))); 228 dbus::ObjectPath(kPairedDevicePath)));
228 properties->address.ReplaceValue(kPairedDeviceAddress); 229 properties->address.ReplaceValue(kPairedDeviceAddress);
229 properties->bluetooth_class.ReplaceValue(kPairedDeviceClass); 230 properties->bluetooth_class.ReplaceValue(kPairedDeviceClass);
230 properties->name.ReplaceValue("Fake Device (Name)"); 231 properties->name.ReplaceValue("Fake Device (Name)");
231 properties->alias.ReplaceValue(kPairedDeviceName); 232 properties->alias.ReplaceValue(kPairedDeviceName);
232 properties->paired.ReplaceValue(true); 233 properties->paired.ReplaceValue(true);
233 properties->trusted.ReplaceValue(true); 234 properties->trusted.ReplaceValue(true);
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 453
453 void FakeBluetoothDeviceClient::CancelPairing( 454 void FakeBluetoothDeviceClient::CancelPairing(
454 const dbus::ObjectPath& object_path, 455 const dbus::ObjectPath& object_path,
455 const base::Closure& callback, 456 const base::Closure& callback,
456 const ErrorCallback& error_callback) { 457 const ErrorCallback& error_callback) {
457 VLOG(1) << "CancelPairing: " << object_path.value(); 458 VLOG(1) << "CancelPairing: " << object_path.value();
458 pairing_cancelled_ = true; 459 pairing_cancelled_ = true;
459 callback.Run(); 460 callback.Run();
460 } 461 }
461 462
463 void FakeBluetoothDeviceClient::StartConnectionMonitor(
464 const dbus::ObjectPath& object_path,
465 const base::Closure& callback,
466 const ErrorCallback& error_callback) {
467 VLOG(1) << "StartConnectionMonitor: " << object_path.value();
468 connection_monitor_started_ = true;
469 callback.Run();
470 }
471
472 void FakeBluetoothDeviceClient::StopConnectionMonitor(
473 const dbus::ObjectPath& object_path,
474 const base::Closure& callback,
475 const ErrorCallback& error_callback) {
476 connection_monitor_started_ = false;
477 callback.Run();
478 }
462 479
463 void FakeBluetoothDeviceClient::BeginDiscoverySimulation( 480 void FakeBluetoothDeviceClient::BeginDiscoverySimulation(
464 const dbus::ObjectPath& adapter_path) { 481 const dbus::ObjectPath& adapter_path) {
465 VLOG(1) << "starting discovery simulation"; 482 VLOG(1) << "starting discovery simulation";
466 483
467 discovery_simulation_step_ = 1; 484 discovery_simulation_step_ = 1;
468 485
469 base::MessageLoop::current()->PostDelayedTask( 486 base::MessageLoop::current()->PostDelayedTask(
470 FROM_HERE, 487 FROM_HERE,
471 base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer, 488 base::Bind(&FakeBluetoothDeviceClient::DiscoverySimulationTimer,
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 // Timer fires every .75s, the numbers below are arbitrary to give a feel 687 // Timer fires every .75s, the numbers below are arbitrary to give a feel
671 // for a discovery process. 688 // for a discovery process.
672 VLOG(1) << "discovery simulation, step " << discovery_simulation_step_; 689 VLOG(1) << "discovery simulation, step " << discovery_simulation_step_;
673 if (discovery_simulation_step_ == 2) { 690 if (discovery_simulation_step_ == 2) {
674 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), 691 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
675 dbus::ObjectPath(kLegacyAutopairPath)); 692 dbus::ObjectPath(kLegacyAutopairPath));
676 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), 693 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
677 dbus::ObjectPath(kLowEnergyPath)); 694 dbus::ObjectPath(kLowEnergyPath));
678 695
679 } else if (discovery_simulation_step_ == 4) { 696 } else if (discovery_simulation_step_ == 4) {
697 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath),
698 base::RandInt(kMinRSSI, kMaxRSSI));
680 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), 699 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
681 dbus::ObjectPath(kDisplayPinCodePath)); 700 dbus::ObjectPath(kDisplayPinCodePath));
682 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), 701 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
683 dbus::ObjectPath(kVanishingDevicePath)); 702 dbus::ObjectPath(kVanishingDevicePath));
684 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath),
685 base::RandInt(kMinRSSI, kMaxRSSI));
686 703
687 } else if (discovery_simulation_step_ == 7) { 704 } else if (discovery_simulation_step_ == 7) {
688 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), 705 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
689 dbus::ObjectPath(kConnectUnpairablePath)); 706 dbus::ObjectPath(kConnectUnpairablePath));
690 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), 707 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath),
691 base::RandInt(kMinRSSI, kMaxRSSI)); 708 base::RandInt(kMinRSSI, kMaxRSSI));
692 709
693 } else if (discovery_simulation_step_ == 8) { 710 } else if (discovery_simulation_step_ == 8) {
694 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), 711 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
695 dbus::ObjectPath(kDisplayPasskeyPath)); 712 dbus::ObjectPath(kDisplayPasskeyPath));
(...skipping 10 matching lines...) Expand all
706 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), 723 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
707 dbus::ObjectPath(kUnconnectableDevicePath)); 724 dbus::ObjectPath(kUnconnectableDevicePath));
708 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), 725 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
709 dbus::ObjectPath(kUnpairableDevicePath)); 726 dbus::ObjectPath(kUnpairableDevicePath));
710 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), 727 CreateDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
711 dbus::ObjectPath(kJustWorksPath)); 728 dbus::ObjectPath(kJustWorksPath));
712 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), 729 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath),
713 base::RandInt(kMinRSSI, kMaxRSSI)); 730 base::RandInt(kMinRSSI, kMaxRSSI));
714 731
715 } else if (discovery_simulation_step_ == 13) { 732 } else if (discovery_simulation_step_ == 13) {
733 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath),
734 base::RandInt(kMinRSSI, kMaxRSSI));
716 RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath), 735 RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
717 dbus::ObjectPath(kVanishingDevicePath)); 736 dbus::ObjectPath(kVanishingDevicePath));
718 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath),
719 base::RandInt(kMinRSSI, kMaxRSSI));
720 737
721 } else if (discovery_simulation_step_ == 14) { 738 } else if (discovery_simulation_step_ == 14) {
722 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath), 739 UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath),
723 base::RandInt(kMinRSSI, kMaxRSSI)); 740 base::RandInt(kMinRSSI, kMaxRSSI));
724 return; 741 return;
725 742
726 } 743 }
727 744
728 ++discovery_simulation_step_; 745 ++discovery_simulation_step_;
729 base::MessageLoop::current()->PostDelayedTask( 746 base::MessageLoop::current()->PostDelayedTask(
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 // TODO(keybuk): tear down this side of the connection 1190 // TODO(keybuk): tear down this side of the connection
1174 callback.Run(); 1191 callback.Run();
1175 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) { 1192 } else if (status == BluetoothProfileServiceProvider::Delegate::CANCELLED) {
1176 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled"); 1193 error_callback.Run(bluetooth_device::kErrorFailed, "Canceled");
1177 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) { 1194 } else if (status == BluetoothProfileServiceProvider::Delegate::REJECTED) {
1178 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected"); 1195 error_callback.Run(bluetooth_device::kErrorFailed, "Rejected");
1179 } 1196 }
1180 } 1197 }
1181 1198
1182 } // namespace chromeos 1199 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/fake_bluetooth_device_client.h ('k') | device/bluetooth/bluetooth_adapter_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698