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_adapter_chromeos.h" | 5 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 } // namespace | 60 } // namespace |
61 | 61 |
62 namespace device { | 62 namespace device { |
63 | 63 |
64 // static | 64 // static |
65 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( | 65 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( |
66 const InitCallback& init_callback) { | 66 const InitCallback& init_callback) { |
67 return chromeos::BluetoothAdapterChromeOS::CreateAdapter(); | 67 return chromeos::BluetoothAdapterChromeOS::CreateAdapter(); |
68 } | 68 } |
69 | 69 |
70 } | 70 } // namespace device |
71 | 71 |
72 namespace chromeos { | 72 namespace chromeos { |
73 | 73 |
74 // static | 74 // static |
75 base::WeakPtr<BluetoothAdapter> BluetoothAdapterChromeOS::CreateAdapter() { | 75 base::WeakPtr<BluetoothAdapter> BluetoothAdapterChromeOS::CreateAdapter() { |
76 BluetoothAdapterChromeOS* adapter = new BluetoothAdapterChromeOS(); | 76 BluetoothAdapterChromeOS* adapter = new BluetoothAdapterChromeOS(); |
77 return adapter->weak_ptr_factory_.GetWeakPtr(); | 77 return adapter->weak_ptr_factory_.GetWeakPtr(); |
78 } | 78 } |
79 | 79 |
80 void BluetoothAdapterChromeOS::Shutdown() { | 80 void BluetoothAdapterChromeOS::Shutdown() { |
81 if (dbus_is_shutdown_) | 81 if (dbus_is_shutdown_) |
82 return; | 82 return; |
83 DCHECK(DBusThreadManager::IsInitialized()) | 83 DCHECK(DBusThreadManager::IsInitialized()) |
84 << "Call BluetoothAdapterFactory::Shutdown() before " | 84 << "Call BluetoothAdapterFactory::Shutdown() before " |
85 "DBusThreadManager::Shutdown()."; | 85 "DBusThreadManager::Shutdown()."; |
86 | 86 |
87 if (IsPresent()) | 87 if (IsPresent()) |
88 RemoveAdapter(); // Also deletes devices_. | 88 RemoveAdapter(); // Also deletes devices_. |
89 DCHECK(devices_.empty()); | 89 DCHECK(devices_.empty()); |
90 // profiles_ should be empty because all BluetoothSockets have been signaled | 90 // profiles_ is empty because all BluetoothSockets have been notified |
91 // that this adapter is disappearing. | 91 // that this adapter is disappearing. |
92 DCHECK(profiles_.empty()); | 92 DCHECK(profiles_.empty()); |
93 | 93 |
94 for (auto& it : profile_queues_) | 94 for (auto& it : profile_queues_) |
95 delete it.second; | 95 delete it.second; |
96 profile_queues_.clear(); | 96 profile_queues_.clear(); |
97 | 97 |
98 DBusThreadManager::Get()->GetBluetoothAdapterClient()->RemoveObserver(this); | 98 DBusThreadManager::Get()->GetBluetoothAdapterClient()->RemoveObserver(this); |
99 DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this); | 99 DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this); |
100 DBusThreadManager::Get()->GetBluetoothInputClient()->RemoveObserver(this); | 100 DBusThreadManager::Get()->GetBluetoothInputClient()->RemoveObserver(this); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 scoped_ptr<device::BluetoothAdvertisement::Data> advertisement_data, | 317 scoped_ptr<device::BluetoothAdvertisement::Data> advertisement_data, |
318 const CreateAdvertisementCallback& callback, | 318 const CreateAdvertisementCallback& callback, |
319 const CreateAdvertisementErrorCallback& error_callback) { | 319 const CreateAdvertisementErrorCallback& error_callback) { |
320 scoped_refptr<BluetoothAdvertisementChromeOS> advertisement( | 320 scoped_refptr<BluetoothAdvertisementChromeOS> advertisement( |
321 new BluetoothAdvertisementChromeOS(advertisement_data.Pass(), this)); | 321 new BluetoothAdvertisementChromeOS(advertisement_data.Pass(), this)); |
322 advertisement->Register(base::Bind(callback, advertisement), error_callback); | 322 advertisement->Register(base::Bind(callback, advertisement), error_callback); |
323 } | 323 } |
324 | 324 |
325 void BluetoothAdapterChromeOS::RemovePairingDelegateInternal( | 325 void BluetoothAdapterChromeOS::RemovePairingDelegateInternal( |
326 BluetoothDevice::PairingDelegate* pairing_delegate) { | 326 BluetoothDevice::PairingDelegate* pairing_delegate) { |
327 // Before removing a pairing delegate make sure that there aren't any devices | 327 // Check if any device is using the pairing delegate. |
328 // currently using it; if there are, clear the pairing context which will | 328 // If so, clear the pairing context which will make any responses no-ops. |
329 // make any responses no-ops. | |
330 for (DevicesMap::iterator iter = devices_.begin(); | 329 for (DevicesMap::iterator iter = devices_.begin(); |
331 iter != devices_.end(); ++iter) { | 330 iter != devices_.end(); ++iter) { |
332 BluetoothDeviceChromeOS* device_chromeos = | 331 BluetoothDeviceChromeOS* device_chromeos = |
333 static_cast<BluetoothDeviceChromeOS*>(iter->second); | 332 static_cast<BluetoothDeviceChromeOS*>(iter->second); |
334 | 333 |
335 BluetoothPairingChromeOS* pairing = device_chromeos->GetPairing(); | 334 BluetoothPairingChromeOS* pairing = device_chromeos->GetPairing(); |
336 if (pairing && pairing->GetPairingDelegate() == pairing_delegate) | 335 if (pairing && pairing->GetPairingDelegate() == pairing_delegate) |
337 device_chromeos->EndPairing(); | 336 device_chromeos->EndPairing(); |
338 } | 337 } |
339 } | 338 } |
(...skipping 15 matching lines...) Expand all Loading... |
355 const dbus::ObjectPath& object_path, | 354 const dbus::ObjectPath& object_path, |
356 const std::string& property_name) { | 355 const std::string& property_name) { |
357 if (object_path != object_path_) | 356 if (object_path != object_path_) |
358 return; | 357 return; |
359 DCHECK(IsPresent()); | 358 DCHECK(IsPresent()); |
360 | 359 |
361 BluetoothAdapterClient::Properties* properties = | 360 BluetoothAdapterClient::Properties* properties = |
362 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 361 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> |
363 GetProperties(object_path_); | 362 GetProperties(object_path_); |
364 | 363 |
365 if (property_name == properties->powered.name()) | 364 if (property_name == properties->powered.name()) { |
366 PoweredChanged(properties->powered.value()); | 365 PoweredChanged(properties->powered.value()); |
367 else if (property_name == properties->discoverable.name()) | 366 } else if (property_name == properties->discoverable.name()) { |
368 DiscoverableChanged(properties->discoverable.value()); | 367 DiscoverableChanged(properties->discoverable.value()); |
369 else if (property_name == properties->discovering.name()) | 368 } else if (property_name == properties->discovering.name()) { |
370 DiscoveringChanged(properties->discovering.value()); | 369 DiscoveringChanged(properties->discovering.value()); |
| 370 } |
371 } | 371 } |
372 | 372 |
373 void BluetoothAdapterChromeOS::DeviceAdded( | 373 void BluetoothAdapterChromeOS::DeviceAdded( |
374 const dbus::ObjectPath& object_path) { | 374 const dbus::ObjectPath& object_path) { |
375 DCHECK(DBusThreadManager::Get()); | 375 DCHECK(DBusThreadManager::Get()); |
376 BluetoothDeviceClient::Properties* properties = | 376 BluetoothDeviceClient::Properties* properties = |
377 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 377 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> |
378 GetProperties(object_path); | 378 GetProperties(object_path); |
379 if (!properties || properties->adapter.value() != object_path_) | 379 if (!properties || properties->adapter.value() != object_path_) |
380 return; | 380 return; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 421 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> |
422 GetProperties(object_path); | 422 GetProperties(object_path); |
423 | 423 |
424 if (property_name == properties->bluetooth_class.name() || | 424 if (property_name == properties->bluetooth_class.name() || |
425 property_name == properties->address.name() || | 425 property_name == properties->address.name() || |
426 property_name == properties->alias.name() || | 426 property_name == properties->alias.name() || |
427 property_name == properties->paired.name() || | 427 property_name == properties->paired.name() || |
428 property_name == properties->trusted.name() || | 428 property_name == properties->trusted.name() || |
429 property_name == properties->connected.name() || | 429 property_name == properties->connected.name() || |
430 property_name == properties->uuids.name() || | 430 property_name == properties->uuids.name() || |
431 property_name == properties->rssi.name()) | 431 property_name == properties->rssi.name()) { |
432 NotifyDeviceChanged(device_chromeos); | 432 NotifyDeviceChanged(device_chromeos); |
| 433 } |
433 | 434 |
434 // When a device becomes paired, mark it as trusted so that the user does | 435 // When a device becomes paired, mark it as trusted so that the user does |
435 // not need to approve every incoming connection | 436 // not need to approve every incoming connection |
436 if (property_name == properties->paired.name() && | 437 if (property_name == properties->paired.name() && |
437 properties->paired.value() && !properties->trusted.value()) | 438 properties->paired.value() && !properties->trusted.value()) { |
438 device_chromeos->SetTrusted(); | 439 device_chromeos->SetTrusted(); |
| 440 } |
439 | 441 |
440 // UMA connection counting | 442 // UMA connection counting |
441 if (property_name == properties->connected.name()) { | 443 if (property_name == properties->connected.name()) { |
442 // PlayStation joystick tries to reconnect after disconnection from USB. | 444 // PlayStation joystick tries to reconnect after disconnection from USB. |
443 // If it is still not trusted, set it, so it becomes available on the | 445 // If it is still not trusted, set it, so it becomes available on the |
444 // list of known devices. | 446 // list of known devices. |
445 if (properties->connected.value() && device_chromeos->IsTrustable() && | 447 if (properties->connected.value() && device_chromeos->IsTrustable() && |
446 !properties->trusted.value()) | 448 !properties->trusted.value()) |
447 device_chromeos->SetTrusted(); | 449 device_chromeos->SetTrusted(); |
448 | 450 |
(...skipping 16 matching lines...) Expand all Loading... |
465 if (!device_chromeos) | 467 if (!device_chromeos) |
466 return; | 468 return; |
467 | 469 |
468 BluetoothInputClient::Properties* properties = | 470 BluetoothInputClient::Properties* properties = |
469 DBusThreadManager::Get()->GetBluetoothInputClient()-> | 471 DBusThreadManager::Get()->GetBluetoothInputClient()-> |
470 GetProperties(object_path); | 472 GetProperties(object_path); |
471 | 473 |
472 // Properties structure can be removed, which triggers a change in the | 474 // Properties structure can be removed, which triggers a change in the |
473 // BluetoothDevice::IsConnectable() property, as does a change in the | 475 // BluetoothDevice::IsConnectable() property, as does a change in the |
474 // actual reconnect_mode property. | 476 // actual reconnect_mode property. |
475 if (!properties || | 477 if (!properties || property_name == properties->reconnect_mode.name()) { |
476 property_name == properties->reconnect_mode.name()) | |
477 NotifyDeviceChanged(device_chromeos); | 478 NotifyDeviceChanged(device_chromeos); |
| 479 } |
478 } | 480 } |
479 | 481 |
480 void BluetoothAdapterChromeOS::Released() { | 482 void BluetoothAdapterChromeOS::Released() { |
481 VLOG(1) << "Release"; | 483 VLOG(1) << "Release"; |
482 if (!IsPresent()) | 484 if (!IsPresent()) |
483 return; | 485 return; |
484 DCHECK(agent_.get()); | 486 DCHECK(agent_.get()); |
485 | 487 |
486 // Called after we unregister the pairing agent, e.g. when changing I/O | 488 // Called after we unregister the pairing agent, e.g. when changing I/O |
487 // capabilities. Nothing much to be done right now. | 489 // capabilities. Nothing much to be done right now. |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 return; | 667 return; |
666 } | 668 } |
667 DCHECK(audio_sink.get()); | 669 DCHECK(audio_sink.get()); |
668 callback.Run(audio_sink); | 670 callback.Run(audio_sink); |
669 } | 671 } |
670 | 672 |
671 BluetoothDeviceChromeOS* | 673 BluetoothDeviceChromeOS* |
672 BluetoothAdapterChromeOS::GetDeviceWithPath( | 674 BluetoothAdapterChromeOS::GetDeviceWithPath( |
673 const dbus::ObjectPath& object_path) { | 675 const dbus::ObjectPath& object_path) { |
674 if (!IsPresent()) | 676 if (!IsPresent()) |
675 return NULL; | 677 return nullptr; |
676 | 678 |
677 for (DevicesMap::iterator iter = devices_.begin(); iter != devices_.end(); | 679 for (DevicesMap::iterator iter = devices_.begin(); iter != devices_.end(); |
678 ++iter) { | 680 ++iter) { |
679 BluetoothDeviceChromeOS* device_chromeos = | 681 BluetoothDeviceChromeOS* device_chromeos = |
680 static_cast<BluetoothDeviceChromeOS*>(iter->second); | 682 static_cast<BluetoothDeviceChromeOS*>(iter->second); |
681 if (device_chromeos->object_path() == object_path) | 683 if (device_chromeos->object_path() == object_path) |
682 return device_chromeos; | 684 return device_chromeos; |
683 } | 685 } |
684 | 686 |
685 return NULL; | 687 return nullptr; |
686 } | 688 } |
687 | 689 |
688 BluetoothPairingChromeOS* BluetoothAdapterChromeOS::GetPairing( | 690 BluetoothPairingChromeOS* BluetoothAdapterChromeOS::GetPairing( |
689 const dbus::ObjectPath& object_path) { | 691 const dbus::ObjectPath& object_path) { |
690 DCHECK(IsPresent()); | 692 DCHECK(IsPresent()); |
691 BluetoothDeviceChromeOS* device_chromeos = GetDeviceWithPath(object_path); | 693 BluetoothDeviceChromeOS* device_chromeos = GetDeviceWithPath(object_path); |
692 if (!device_chromeos) { | 694 if (!device_chromeos) { |
693 LOG(WARNING) << "Pairing Agent request for unknown device: " | 695 LOG(WARNING) << "Pairing Agent request for unknown device: " |
694 << object_path.value(); | 696 << object_path.value(); |
695 return NULL; | 697 return nullptr; |
696 } | 698 } |
697 | 699 |
698 BluetoothPairingChromeOS* pairing = device_chromeos->GetPairing(); | 700 BluetoothPairingChromeOS* pairing = device_chromeos->GetPairing(); |
699 if (pairing) | 701 if (pairing) |
700 return pairing; | 702 return pairing; |
701 | 703 |
702 // The device doesn't have its own pairing context, so this is an incoming | 704 // The device doesn't have its own pairing context, so this is an incoming |
703 // pairing request that should use our best default delegate (if we have one). | 705 // pairing request that should use our best default delegate (if we have one). |
704 BluetoothDevice::PairingDelegate* pairing_delegate = DefaultPairingDelegate(); | 706 BluetoothDevice::PairingDelegate* pairing_delegate = DefaultPairingDelegate(); |
705 if (!pairing_delegate) | 707 if (!pairing_delegate) |
706 return NULL; | 708 return nullptr; |
707 | 709 |
708 return device_chromeos->BeginPairing(pairing_delegate); | 710 return device_chromeos->BeginPairing(pairing_delegate); |
709 } | 711 } |
710 | 712 |
711 void BluetoothAdapterChromeOS::SetAdapter(const dbus::ObjectPath& object_path) { | 713 void BluetoothAdapterChromeOS::SetAdapter(const dbus::ObjectPath& object_path) { |
712 DCHECK(!IsPresent()); | 714 DCHECK(!IsPresent()); |
713 DCHECK(!dbus_is_shutdown_); | 715 DCHECK(!dbus_is_shutdown_); |
714 object_path_ = object_path; | 716 object_path_ = object_path; |
715 | 717 |
716 VLOG(1) << object_path_.value() << ": using adapter."; | 718 VLOG(1) << object_path_.value() << ": using adapter."; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 void BluetoothAdapterChromeOS::DiscoverableChanged(bool discoverable) { | 807 void BluetoothAdapterChromeOS::DiscoverableChanged(bool discoverable) { |
806 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 808 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
807 AdapterDiscoverableChanged(this, discoverable)); | 809 AdapterDiscoverableChanged(this, discoverable)); |
808 } | 810 } |
809 | 811 |
810 void BluetoothAdapterChromeOS::DiscoveringChanged( | 812 void BluetoothAdapterChromeOS::DiscoveringChanged( |
811 bool discovering) { | 813 bool discovering) { |
812 // If the adapter stopped discovery due to a reason other than a request by | 814 // If the adapter stopped discovery due to a reason other than a request by |
813 // us, reset the count to 0. | 815 // us, reset the count to 0. |
814 VLOG(1) << "Discovering changed: " << discovering; | 816 VLOG(1) << "Discovering changed: " << discovering; |
815 if (!discovering && !discovery_request_pending_ | 817 if (!discovering && !discovery_request_pending_ && |
816 && num_discovery_sessions_ > 0) { | 818 num_discovery_sessions_ > 0) { |
817 VLOG(1) << "Marking sessions as inactive."; | 819 VLOG(1) << "Marking sessions as inactive."; |
818 num_discovery_sessions_ = 0; | 820 num_discovery_sessions_ = 0; |
819 MarkDiscoverySessionsAsInactive(); | 821 MarkDiscoverySessionsAsInactive(); |
820 } | 822 } |
821 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 823 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
822 AdapterDiscoveringChanged(this, discovering)); | 824 AdapterDiscoveringChanged(this, discovering)); |
823 } | 825 } |
824 | 826 |
825 void BluetoothAdapterChromeOS::PresentChanged(bool present) { | 827 void BluetoothAdapterChromeOS::PresentChanged(bool present) { |
826 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 828 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
827 AdapterPresentChanged(this, present)); | 829 AdapterPresentChanged(this, present)); |
828 } | 830 } |
829 | 831 |
830 void BluetoothAdapterChromeOS::NotifyDeviceChanged( | 832 void BluetoothAdapterChromeOS::NotifyDeviceChanged( |
831 BluetoothDeviceChromeOS* device) { | 833 BluetoothDeviceChromeOS* device) { |
| 834 DCHECK(device); |
832 DCHECK(device->adapter_ == this); | 835 DCHECK(device->adapter_ == this); |
833 | 836 |
834 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 837 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
835 DeviceChanged(this, device)); | 838 DeviceChanged(this, device)); |
836 } | 839 } |
837 | 840 |
838 void BluetoothAdapterChromeOS::NotifyGattServiceAdded( | 841 void BluetoothAdapterChromeOS::NotifyGattServiceAdded( |
839 BluetoothRemoteGattServiceChromeOS* service) { | 842 BluetoothRemoteGattServiceChromeOS* service) { |
840 DCHECK_EQ(service->GetAdapter(), this); | 843 DCHECK_EQ(service->GetAdapter(), this); |
841 DCHECK_EQ( | 844 DCHECK_EQ( |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, | 1073 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, |
1071 weak_ptr_factory_.GetWeakPtr(), | 1074 weak_ptr_factory_.GetWeakPtr(), |
1072 callback, | 1075 callback, |
1073 error_callback)); | 1076 error_callback)); |
1074 } | 1077 } |
1075 | 1078 |
1076 void BluetoothAdapterChromeOS::OnPropertyChangeCompleted( | 1079 void BluetoothAdapterChromeOS::OnPropertyChangeCompleted( |
1077 const base::Closure& callback, | 1080 const base::Closure& callback, |
1078 const ErrorCallback& error_callback, | 1081 const ErrorCallback& error_callback, |
1079 bool success) { | 1082 bool success) { |
1080 if (IsPresent() && success) | 1083 if (IsPresent() && success) { |
1081 callback.Run(); | 1084 callback.Run(); |
1082 else | 1085 } else { |
1083 error_callback.Run(); | 1086 error_callback.Run(); |
| 1087 } |
1084 } | 1088 } |
1085 | 1089 |
1086 void BluetoothAdapterChromeOS::AddDiscoverySession( | 1090 void BluetoothAdapterChromeOS::AddDiscoverySession( |
1087 BluetoothDiscoveryFilter* discovery_filter, | 1091 BluetoothDiscoveryFilter* discovery_filter, |
1088 const base::Closure& callback, | 1092 const base::Closure& callback, |
1089 const ErrorCallback& error_callback) { | 1093 const ErrorCallback& error_callback) { |
1090 if (!IsPresent()) { | 1094 if (!IsPresent()) { |
1091 error_callback.Run(); | 1095 error_callback.Run(); |
1092 return; | 1096 return; |
1093 } | 1097 } |
(...skipping 29 matching lines...) Expand all Loading... |
1123 scoped_ptr<BluetoothDiscoveryFilter> df(new BluetoothDiscoveryFilter( | 1127 scoped_ptr<BluetoothDiscoveryFilter> df(new BluetoothDiscoveryFilter( |
1124 BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL)); | 1128 BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL)); |
1125 df->CopyFrom(*discovery_filter); | 1129 df->CopyFrom(*discovery_filter); |
1126 SetDiscoveryFilter( | 1130 SetDiscoveryFilter( |
1127 df.Pass(), | 1131 df.Pass(), |
1128 base::Bind(&BluetoothAdapterChromeOS::OnPreSetDiscoveryFilter, | 1132 base::Bind(&BluetoothAdapterChromeOS::OnPreSetDiscoveryFilter, |
1129 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 1133 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
1130 base::Bind(&BluetoothAdapterChromeOS::OnPreSetDiscoveryFilterError, | 1134 base::Bind(&BluetoothAdapterChromeOS::OnPreSetDiscoveryFilterError, |
1131 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1135 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
1132 return; | 1136 return; |
1133 } else | 1137 } else { |
1134 current_filter_.reset(); | 1138 current_filter_.reset(); |
| 1139 } |
1135 | 1140 |
1136 // This is the first request to start device discovery. | 1141 // This is the first request to start device discovery. |
1137 discovery_request_pending_ = true; | 1142 discovery_request_pending_ = true; |
1138 DBusThreadManager::Get()->GetBluetoothAdapterClient()->StartDiscovery( | 1143 DBusThreadManager::Get()->GetBluetoothAdapterClient()->StartDiscovery( |
1139 object_path_, | 1144 object_path_, |
1140 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscovery, | 1145 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscovery, |
1141 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 1146 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
1142 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscoveryError, | 1147 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscoveryError, |
1143 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1148 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
1144 } | 1149 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 | 1273 |
1269 void BluetoothAdapterChromeOS::OnStartDiscovery( | 1274 void BluetoothAdapterChromeOS::OnStartDiscovery( |
1270 const base::Closure& callback, | 1275 const base::Closure& callback, |
1271 const ErrorCallback& error_callback) { | 1276 const ErrorCallback& error_callback) { |
1272 // Report success on the original request and increment the count. | 1277 // Report success on the original request and increment the count. |
1273 VLOG(1) << __func__; | 1278 VLOG(1) << __func__; |
1274 DCHECK(discovery_request_pending_); | 1279 DCHECK(discovery_request_pending_); |
1275 DCHECK_EQ(num_discovery_sessions_, 0); | 1280 DCHECK_EQ(num_discovery_sessions_, 0); |
1276 discovery_request_pending_ = false; | 1281 discovery_request_pending_ = false; |
1277 num_discovery_sessions_++; | 1282 num_discovery_sessions_++; |
1278 if (IsPresent()) | 1283 if (IsPresent()) { |
1279 callback.Run(); | 1284 callback.Run(); |
1280 else | 1285 } else { |
1281 error_callback.Run(); | 1286 error_callback.Run(); |
| 1287 } |
1282 | 1288 |
1283 // Try to add a new discovery session for each queued request. | 1289 // Try to add a new discovery session for each queued request. |
1284 ProcessQueuedDiscoveryRequests(); | 1290 ProcessQueuedDiscoveryRequests(); |
1285 } | 1291 } |
1286 | 1292 |
1287 void BluetoothAdapterChromeOS::OnStartDiscoveryError( | 1293 void BluetoothAdapterChromeOS::OnStartDiscoveryError( |
1288 const base::Closure& callback, | 1294 const base::Closure& callback, |
1289 const ErrorCallback& error_callback, | 1295 const ErrorCallback& error_callback, |
1290 const std::string& error_name, | 1296 const std::string& error_name, |
1291 const std::string& error_message) { | 1297 const std::string& error_message) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1375 | 1381 |
1376 // Try to add a new discovery session for each queued request. | 1382 // Try to add a new discovery session for each queued request. |
1377 ProcessQueuedDiscoveryRequests(); | 1383 ProcessQueuedDiscoveryRequests(); |
1378 } | 1384 } |
1379 | 1385 |
1380 void BluetoothAdapterChromeOS::OnSetDiscoveryFilter( | 1386 void BluetoothAdapterChromeOS::OnSetDiscoveryFilter( |
1381 const base::Closure& callback, | 1387 const base::Closure& callback, |
1382 const ErrorCallback& error_callback) { | 1388 const ErrorCallback& error_callback) { |
1383 // Report success on the original request and increment the count. | 1389 // Report success on the original request and increment the count. |
1384 VLOG(1) << __func__; | 1390 VLOG(1) << __func__; |
1385 if (IsPresent()) | 1391 if (IsPresent()) { |
1386 callback.Run(); | 1392 callback.Run(); |
1387 else | 1393 } else { |
1388 error_callback.Run(); | 1394 error_callback.Run(); |
| 1395 } |
1389 } | 1396 } |
1390 | 1397 |
1391 void BluetoothAdapterChromeOS::OnSetDiscoveryFilterError( | 1398 void BluetoothAdapterChromeOS::OnSetDiscoveryFilterError( |
1392 const base::Closure& callback, | 1399 const base::Closure& callback, |
1393 const ErrorCallback& error_callback, | 1400 const ErrorCallback& error_callback, |
1394 const std::string& error_name, | 1401 const std::string& error_name, |
1395 const std::string& error_message) { | 1402 const std::string& error_message) { |
1396 LOG(WARNING) << object_path_.value() | 1403 LOG(WARNING) << object_path_.value() |
1397 << ": Failed to set discovery filter: " << error_name << ": " | 1404 << ": Failed to set discovery filter: " << error_name << ": " |
1398 << error_message; | 1405 << error_message; |
(...skipping 14 matching lines...) Expand all Loading... |
1413 | 1420 |
1414 // If the queued request resulted in a pending call, then let it | 1421 // If the queued request resulted in a pending call, then let it |
1415 // asynchonously process the remaining queued requests once the pending | 1422 // asynchonously process the remaining queued requests once the pending |
1416 // call returns. | 1423 // call returns. |
1417 if (discovery_request_pending_) | 1424 if (discovery_request_pending_) |
1418 return; | 1425 return; |
1419 } | 1426 } |
1420 } | 1427 } |
1421 | 1428 |
1422 } // namespace chromeos | 1429 } // namespace chromeos |
OLD | NEW |