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

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

Issue 14443003: D-Bus: notify properties changed from fakes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
« no previous file with comments | « chromeos/dbus/fake_bluetooth_adapter_client.cc ('k') | dbus/property.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 (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 <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 VLOG(1) << "GetAll"; 126 VLOG(1) << "GetAll";
127 } 127 }
128 128
129 void FakeBluetoothDeviceClient::Properties::Set( 129 void FakeBluetoothDeviceClient::Properties::Set(
130 dbus::PropertyBase *property, 130 dbus::PropertyBase *property,
131 dbus::PropertySet::SetCallback callback) { 131 dbus::PropertySet::SetCallback callback) {
132 VLOG(1) << "Set " << property->name(); 132 VLOG(1) << "Set " << property->name();
133 if (property->name() == trusted.name()) { 133 if (property->name() == trusted.name()) {
134 callback.Run(true); 134 callback.Run(true);
135 property->ReplaceValueWithSetValue(); 135 property->ReplaceValueWithSetValue();
136 NotifyPropertyChanged(property->name());
137 } else { 136 } else {
138 callback.Run(false); 137 callback.Run(false);
139 } 138 }
140 } 139 }
141 140
142 141
143 FakeBluetoothDeviceClient::FakeBluetoothDeviceClient() 142 FakeBluetoothDeviceClient::FakeBluetoothDeviceClient()
144 : simulation_interval_ms_(kSimulationIntervalMs), 143 : simulation_interval_ms_(kSimulationIntervalMs),
145 discovery_simulation_step_(0), 144 discovery_simulation_step_(0),
146 pairing_cancelled_(false) { 145 pairing_cancelled_(false) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } else if (properties->paired.value() == true && 216 } else if (properties->paired.value() == true &&
218 object_path == dbus::ObjectPath(kMicrosoftMousePath)) { 217 object_path == dbus::ObjectPath(kMicrosoftMousePath)) {
219 // Must not be paired 218 // Must not be paired
220 error_callback.Run(bluetooth_adapter::kErrorFailed, 219 error_callback.Run(bluetooth_adapter::kErrorFailed,
221 "Connection fails while paired"); 220 "Connection fails while paired");
222 return; 221 return;
223 } 222 }
224 223
225 // The device can be connected. 224 // The device can be connected.
226 properties->connected.ReplaceValue(true); 225 properties->connected.ReplaceValue(true);
226 callback.Run();
227 227
228 AddInputDeviceIfNeeded(object_path, properties); 228 AddInputDeviceIfNeeded(object_path, properties);
229
230 callback.Run();
231 properties->NotifyPropertyChanged(properties->connected.name());
232 } 229 }
233 230
234 void FakeBluetoothDeviceClient::Disconnect( 231 void FakeBluetoothDeviceClient::Disconnect(
235 const dbus::ObjectPath& object_path, 232 const dbus::ObjectPath& object_path,
236 const base::Closure& callback, 233 const base::Closure& callback,
237 const ErrorCallback& error_callback) { 234 const ErrorCallback& error_callback) {
238 VLOG(1) << "Disconnect: " << object_path.value(); 235 VLOG(1) << "Disconnect: " << object_path.value();
239 Properties* properties = GetProperties(object_path); 236 Properties* properties = GetProperties(object_path);
240 237
241 if (properties->connected.value() == true) { 238 if (properties->connected.value() == true) {
239 callback.Run();
242 properties->connected.ReplaceValue(false); 240 properties->connected.ReplaceValue(false);
243
244 callback.Run();
245 properties->NotifyPropertyChanged(properties->connected.name());
246 } else { 241 } else {
247 error_callback.Run("org.bluez.Error.NotConnected", "Not Connected"); 242 error_callback.Run("org.bluez.Error.NotConnected", "Not Connected");
248 } 243 }
249 } 244 }
250 245
251 void FakeBluetoothDeviceClient::ConnectProfile( 246 void FakeBluetoothDeviceClient::ConnectProfile(
252 const dbus::ObjectPath& object_path, 247 const dbus::ObjectPath& object_path,
253 const std::string& uuid, 248 const std::string& uuid,
254 const base::Closure& callback, 249 const base::Closure& callback,
255 const ErrorCallback& error_callback) { 250 const ErrorCallback& error_callback) {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 &FakeBluetoothDeviceClient::OnPropertyChanged, 448 &FakeBluetoothDeviceClient::OnPropertyChanged,
454 base::Unretained(this), 449 base::Unretained(this),
455 dbus::ObjectPath(kAppleMousePath))); 450 dbus::ObjectPath(kAppleMousePath)));
456 properties->address.ReplaceValue(kAppleMouseAddress); 451 properties->address.ReplaceValue(kAppleMouseAddress);
457 properties->bluetooth_class.ReplaceValue(kAppleMouseClass); 452 properties->bluetooth_class.ReplaceValue(kAppleMouseClass);
458 properties->name.ReplaceValue("Fake Apple Magic Mouse"); 453 properties->name.ReplaceValue("Fake Apple Magic Mouse");
459 properties->alias.ReplaceValue(kAppleMouseName); 454 properties->alias.ReplaceValue(kAppleMouseName);
460 properties->adapter.ReplaceValue( 455 properties->adapter.ReplaceValue(
461 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); 456 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath));
462 457
458 std::vector<std::string> uuids;
459 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb");
460 properties->uuids.ReplaceValue(uuids);
461
463 properties_map_[dbus::ObjectPath(kAppleMousePath)] = properties; 462 properties_map_[dbus::ObjectPath(kAppleMousePath)] = properties;
464 device_list_.push_back(dbus::ObjectPath(kAppleMousePath)); 463 device_list_.push_back(dbus::ObjectPath(kAppleMousePath));
465 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, 464 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_,
466 DeviceAdded(dbus::ObjectPath(kAppleMousePath))); 465 DeviceAdded(dbus::ObjectPath(kAppleMousePath)));
467 } 466 }
468 467
469 } else if (discovery_simulation_step_ == 4) { 468 } else if (discovery_simulation_step_ == 4) {
470 if (std::find(device_list_.begin(), device_list_.end(), 469 if (std::find(device_list_.begin(), device_list_.end(),
471 dbus::ObjectPath(kAppleKeyboardPath)) == device_list_.end()) { 470 dbus::ObjectPath(kAppleKeyboardPath)) == device_list_.end()) {
472 Properties *properties = new Properties(base::Bind( 471 Properties *properties = new Properties(base::Bind(
473 &FakeBluetoothDeviceClient::OnPropertyChanged, 472 &FakeBluetoothDeviceClient::OnPropertyChanged,
474 base::Unretained(this), 473 base::Unretained(this),
475 dbus::ObjectPath(kAppleKeyboardPath))); 474 dbus::ObjectPath(kAppleKeyboardPath)));
476 properties->address.ReplaceValue(kAppleKeyboardAddress); 475 properties->address.ReplaceValue(kAppleKeyboardAddress);
477 properties->bluetooth_class.ReplaceValue(kAppleKeyboardClass); 476 properties->bluetooth_class.ReplaceValue(kAppleKeyboardClass);
478 properties->name.ReplaceValue("Fake Apple Wireless Keyboard"); 477 properties->name.ReplaceValue("Fake Apple Wireless Keyboard");
479 properties->alias.ReplaceValue(kAppleKeyboardName); 478 properties->alias.ReplaceValue(kAppleKeyboardName);
480 properties->adapter.ReplaceValue( 479 properties->adapter.ReplaceValue(
481 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); 480 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath));
482 481
482 std::vector<std::string> uuids;
483 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb");
484 properties->uuids.ReplaceValue(uuids);
485
483 properties_map_[dbus::ObjectPath(kAppleKeyboardPath)] = properties; 486 properties_map_[dbus::ObjectPath(kAppleKeyboardPath)] = properties;
484 device_list_.push_back(dbus::ObjectPath(kAppleKeyboardPath)); 487 device_list_.push_back(dbus::ObjectPath(kAppleKeyboardPath));
485 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, 488 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_,
486 DeviceAdded(dbus::ObjectPath(kAppleKeyboardPath))); 489 DeviceAdded(dbus::ObjectPath(kAppleKeyboardPath)));
487 } 490 }
488 491
489 if (std::find(device_list_.begin(), device_list_.end(), 492 if (std::find(device_list_.begin(), device_list_.end(),
490 dbus::ObjectPath(kVanishingDevicePath)) == 493 dbus::ObjectPath(kVanishingDevicePath)) ==
491 device_list_.end()) { 494 device_list_.end()) {
492 Properties* properties = new Properties(base::Bind( 495 Properties* properties = new Properties(base::Bind(
(...skipping 21 matching lines...) Expand all
514 &FakeBluetoothDeviceClient::OnPropertyChanged, 517 &FakeBluetoothDeviceClient::OnPropertyChanged,
515 base::Unretained(this), 518 base::Unretained(this),
516 dbus::ObjectPath(kMicrosoftMousePath))); 519 dbus::ObjectPath(kMicrosoftMousePath)));
517 properties->address.ReplaceValue(kMicrosoftMouseAddress); 520 properties->address.ReplaceValue(kMicrosoftMouseAddress);
518 properties->bluetooth_class.ReplaceValue(kMicrosoftMouseClass); 521 properties->bluetooth_class.ReplaceValue(kMicrosoftMouseClass);
519 properties->name.ReplaceValue("Fake Microsoft Mouse"); 522 properties->name.ReplaceValue("Fake Microsoft Mouse");
520 properties->alias.ReplaceValue(kMicrosoftMouseName); 523 properties->alias.ReplaceValue(kMicrosoftMouseName);
521 properties->adapter.ReplaceValue( 524 properties->adapter.ReplaceValue(
522 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); 525 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath));
523 526
527 std::vector<std::string> uuids;
528 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb");
529 properties->uuids.ReplaceValue(uuids);
530
524 properties_map_[dbus::ObjectPath(kMicrosoftMousePath)] = properties; 531 properties_map_[dbus::ObjectPath(kMicrosoftMousePath)] = properties;
525 device_list_.push_back(dbus::ObjectPath(kMicrosoftMousePath)); 532 device_list_.push_back(dbus::ObjectPath(kMicrosoftMousePath));
526 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, 533 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_,
527 DeviceAdded(dbus::ObjectPath(kMicrosoftMousePath))); 534 DeviceAdded(dbus::ObjectPath(kMicrosoftMousePath)));
528 } 535 }
529 536
530 } else if (discovery_simulation_step_ == 8) { 537 } else if (discovery_simulation_step_ == 8) {
531 if (std::find(device_list_.begin(), device_list_.end(), 538 if (std::find(device_list_.begin(), device_list_.end(),
532 dbus::ObjectPath(kMotorolaKeyboardPath)) == 539 dbus::ObjectPath(kMotorolaKeyboardPath)) ==
533 device_list_.end()) { 540 device_list_.end()) {
534 Properties* properties = new Properties(base::Bind( 541 Properties* properties = new Properties(base::Bind(
535 &FakeBluetoothDeviceClient::OnPropertyChanged, 542 &FakeBluetoothDeviceClient::OnPropertyChanged,
536 base::Unretained(this), 543 base::Unretained(this),
537 dbus::ObjectPath(kMotorolaKeyboardPath))); 544 dbus::ObjectPath(kMotorolaKeyboardPath)));
538 properties->address.ReplaceValue(kMotorolaKeyboardAddress); 545 properties->address.ReplaceValue(kMotorolaKeyboardAddress);
539 properties->bluetooth_class.ReplaceValue(kMotorolaKeyboardClass); 546 properties->bluetooth_class.ReplaceValue(kMotorolaKeyboardClass);
540 properties->name.ReplaceValue("Fake Motorola Keyboard"); 547 properties->name.ReplaceValue("Fake Motorola Keyboard");
541 properties->alias.ReplaceValue(kMotorolaKeyboardName); 548 properties->alias.ReplaceValue(kMotorolaKeyboardName);
542 properties->adapter.ReplaceValue( 549 properties->adapter.ReplaceValue(
543 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath)); 550 dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath));
544 551
552 std::vector<std::string> uuids;
553 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb");
554 properties->uuids.ReplaceValue(uuids);
555
545 properties_map_[dbus::ObjectPath(kMotorolaKeyboardPath)] = properties; 556 properties_map_[dbus::ObjectPath(kMotorolaKeyboardPath)] = properties;
546 device_list_.push_back(dbus::ObjectPath(kMotorolaKeyboardPath)); 557 device_list_.push_back(dbus::ObjectPath(kMotorolaKeyboardPath));
547 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_, 558 FOR_EACH_OBSERVER(ExperimentalBluetoothDeviceClient::Observer, observers_,
548 DeviceAdded(dbus::ObjectPath(kMotorolaKeyboardPath))); 559 DeviceAdded(dbus::ObjectPath(kMotorolaKeyboardPath)));
549 } 560 }
550 561
551 if (std::find(device_list_.begin(), device_list_.end(), 562 if (std::find(device_list_.begin(), device_list_.end(),
552 dbus::ObjectPath(kSonyHeadphonesPath)) == 563 dbus::ObjectPath(kSonyHeadphonesPath)) ==
553 device_list_.end()) { 564 device_list_.end()) {
554 Properties* properties = new Properties(base::Bind( 565 Properties* properties = new Properties(base::Bind(
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 VLOG(1) << "CompleteSimulatedPairing: " << object_path.value(); 643 VLOG(1) << "CompleteSimulatedPairing: " << object_path.value();
633 if (pairing_cancelled_) { 644 if (pairing_cancelled_) {
634 pairing_cancelled_ = false; 645 pairing_cancelled_ = false;
635 646
636 error_callback.Run(bluetooth_adapter::kErrorAuthenticationCanceled, 647 error_callback.Run(bluetooth_adapter::kErrorAuthenticationCanceled,
637 "Cancaled"); 648 "Cancaled");
638 } else { 649 } else {
639 Properties* properties = GetProperties(object_path); 650 Properties* properties = GetProperties(object_path);
640 651
641 properties->paired.ReplaceValue(true); 652 properties->paired.ReplaceValue(true);
653 callback.Run();
642 654
643 AddInputDeviceIfNeeded(object_path, properties); 655 AddInputDeviceIfNeeded(object_path, properties);
644
645 callback.Run();
646 properties->NotifyPropertyChanged(properties->paired.name());
647 } 656 }
648 } 657 }
649 658
650 void FakeBluetoothDeviceClient::TimeoutSimulatedPairing( 659 void FakeBluetoothDeviceClient::TimeoutSimulatedPairing(
651 const dbus::ObjectPath& object_path, 660 const dbus::ObjectPath& object_path,
652 const ErrorCallback& error_callback) { 661 const ErrorCallback& error_callback) {
653 VLOG(1) << "TimeoutSimulatedPairing: " << object_path.value(); 662 VLOG(1) << "TimeoutSimulatedPairing: " << object_path.value();
654 663
655 error_callback.Run(bluetooth_adapter::kErrorAuthenticationTimeout, 664 error_callback.Run(bluetooth_adapter::kErrorAuthenticationTimeout,
656 "Timed out"); 665 "Timed out");
(...skipping 19 matching lines...) Expand all
676 685
677 void FakeBluetoothDeviceClient::AddInputDeviceIfNeeded( 686 void FakeBluetoothDeviceClient::AddInputDeviceIfNeeded(
678 const dbus::ObjectPath& object_path, 687 const dbus::ObjectPath& object_path,
679 Properties* properties) { 688 Properties* properties) {
680 // If the paired device is a HID device based on it's bluetooth class, 689 // If the paired device is a HID device based on it's bluetooth class,
681 // simulate the Input interface. 690 // simulate the Input interface.
682 FakeBluetoothInputClient* fake_bluetooth_input_client = 691 FakeBluetoothInputClient* fake_bluetooth_input_client =
683 static_cast<FakeBluetoothInputClient*>( 692 static_cast<FakeBluetoothInputClient*>(
684 DBusThreadManager::Get()->GetExperimentalBluetoothInputClient()); 693 DBusThreadManager::Get()->GetExperimentalBluetoothInputClient());
685 694
686 if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500) { 695 if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500)
687 std::vector<std::string> uuids = properties->uuids.value(); 696 fake_bluetooth_input_client->AddInputDevice(object_path);
688 if (std::find(uuids.begin(), uuids.end(),
689 "00001124-0000-1000-8000-00805f9b34fb") == uuids.end()) {
690 uuids.push_back("00001124-0000-1000-8000-00805f9b34fb");
691 properties->uuids.ReplaceValue(uuids);
692 fake_bluetooth_input_client->AddInputDevice(object_path);
693 }
694 }
695 } 697 }
696 698
697 void FakeBluetoothDeviceClient::PinCodeCallback( 699 void FakeBluetoothDeviceClient::PinCodeCallback(
698 const dbus::ObjectPath& object_path, 700 const dbus::ObjectPath& object_path,
699 const base::Closure& callback, 701 const base::Closure& callback,
700 const ErrorCallback& error_callback, 702 const ErrorCallback& error_callback,
701 ExperimentalBluetoothAgentServiceProvider::Delegate::Status status, 703 ExperimentalBluetoothAgentServiceProvider::Delegate::Status status,
702 const std::string& pincode) { 704 const std::string& pincode) {
703 VLOG(1) << "PinCodeCallback: " << object_path.value(); 705 VLOG(1) << "PinCodeCallback: " << object_path.value();
704 706
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 FROM_HERE, 834 FROM_HERE,
833 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing, 835 base::Bind(&FakeBluetoothDeviceClient::CompleteSimulatedPairing,
834 base::Unretained(this), 836 base::Unretained(this),
835 object_path, callback, error_callback), 837 object_path, callback, error_callback),
836 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); 838 base::TimeDelta::FromMilliseconds(simulation_interval_ms_));
837 839
838 } 840 }
839 } 841 }
840 842
841 } // namespace chromeos 843 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/fake_bluetooth_adapter_client.cc ('k') | dbus/property.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698