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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 new BluetoothAudioSinkChromeOS(this)); | 317 new BluetoothAudioSinkChromeOS(this)); |
318 audio_sink->Register( | 318 audio_sink->Register( |
319 options, | 319 options, |
320 base::Bind(&BluetoothAdapterChromeOS::OnRegisterAudioSink, | 320 base::Bind(&BluetoothAdapterChromeOS::OnRegisterAudioSink, |
321 weak_ptr_factory_.GetWeakPtr(), callback, audio_sink), | 321 weak_ptr_factory_.GetWeakPtr(), callback, audio_sink), |
322 error_callback); | 322 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 DCHECK(IsPresent()); | |
328 // Before removing a pairing delegate make sure that there aren't any devices | 327 // Before removing a pairing delegate make sure that there aren't any devices |
329 // currently using it; if there are, clear the pairing context which will | 328 // currently using it; if there are, clear the pairing context which will |
330 // make any responses no-ops. | 329 // make any responses no-ops. |
331 for (DevicesMap::iterator iter = devices_.begin(); | 330 for (DevicesMap::iterator iter = devices_.begin(); |
332 iter != devices_.end(); ++iter) { | 331 iter != devices_.end(); ++iter) { |
333 BluetoothDeviceChromeOS* device_chromeos = | 332 BluetoothDeviceChromeOS* device_chromeos = |
334 static_cast<BluetoothDeviceChromeOS*>(iter->second); | 333 static_cast<BluetoothDeviceChromeOS*>(iter->second); |
335 | 334 |
336 BluetoothPairingChromeOS* pairing = device_chromeos->GetPairing(); | 335 BluetoothPairingChromeOS* pairing = device_chromeos->GetPairing(); |
337 if (pairing && pairing->GetPairingDelegate() == pairing_delegate) | 336 if (pairing && pairing->GetPairingDelegate() == pairing_delegate) |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 | 473 |
475 // Properties structure can be removed, which triggers a change in the | 474 // Properties structure can be removed, which triggers a change in the |
476 // BluetoothDevice::IsConnectable() property, as does a change in the | 475 // BluetoothDevice::IsConnectable() property, as does a change in the |
477 // actual reconnect_mode property. | 476 // actual reconnect_mode property. |
478 if (!properties || | 477 if (!properties || |
479 property_name == properties->reconnect_mode.name()) | 478 property_name == properties->reconnect_mode.name()) |
480 NotifyDeviceChanged(device_chromeos); | 479 NotifyDeviceChanged(device_chromeos); |
481 } | 480 } |
482 | 481 |
483 void BluetoothAdapterChromeOS::Released() { | 482 void BluetoothAdapterChromeOS::Released() { |
484 DCHECK(IsPresent()); | 483 if (!IsPresent()) |
484 return; | |
armansito
2015/02/19 01:44:47
Since we don't really do anything, here I would ju
scheib
2015/02/19 21:34:15
Logging moved above return. The conditional return
| |
485 DCHECK(agent_.get()); | 485 DCHECK(agent_.get()); |
486 VLOG(1) << "Release"; | 486 VLOG(1) << "Release"; |
487 | 487 |
488 // 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 |
489 // capabilities. Nothing much to be done right now. | 489 // capabilities. Nothing much to be done right now. |
490 } | 490 } |
491 | 491 |
492 void BluetoothAdapterChromeOS::RequestPinCode( | 492 void BluetoothAdapterChromeOS::RequestPinCode( |
493 const dbus::ObjectPath& device_path, | 493 const dbus::ObjectPath& device_path, |
494 const PinCodeCallback& callback) { | 494 const PinCodeCallback& callback) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
617 callback.Run(REJECTED); | 617 callback.Run(REJECTED); |
618 } | 618 } |
619 | 619 |
620 void BluetoothAdapterChromeOS::Cancel() { | 620 void BluetoothAdapterChromeOS::Cancel() { |
621 DCHECK(IsPresent()); | 621 DCHECK(IsPresent()); |
622 DCHECK(agent_.get()); | 622 DCHECK(agent_.get()); |
623 VLOG(1) << "Cancel"; | 623 VLOG(1) << "Cancel"; |
624 } | 624 } |
625 | 625 |
626 void BluetoothAdapterChromeOS::OnRegisterAgent() { | 626 void BluetoothAdapterChromeOS::OnRegisterAgent() { |
627 DCHECK(IsPresent()); | |
628 VLOG(1) << "Pairing agent registered, requesting to be made default"; | 627 VLOG(1) << "Pairing agent registered, requesting to be made default"; |
629 | 628 |
630 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()-> | 629 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()-> |
631 RequestDefaultAgent( | 630 RequestDefaultAgent( |
632 dbus::ObjectPath(kAgentPath), | 631 dbus::ObjectPath(kAgentPath), |
633 base::Bind(&BluetoothAdapterChromeOS::OnRequestDefaultAgent, | 632 base::Bind(&BluetoothAdapterChromeOS::OnRequestDefaultAgent, |
634 weak_ptr_factory_.GetWeakPtr()), | 633 weak_ptr_factory_.GetWeakPtr()), |
635 base::Bind(&BluetoothAdapterChromeOS::OnRequestDefaultAgentError, | 634 base::Bind(&BluetoothAdapterChromeOS::OnRequestDefaultAgentError, |
636 weak_ptr_factory_.GetWeakPtr())); | 635 weak_ptr_factory_.GetWeakPtr())); |
637 } | 636 } |
638 | 637 |
639 void BluetoothAdapterChromeOS::OnRegisterAgentError( | 638 void BluetoothAdapterChromeOS::OnRegisterAgentError( |
640 const std::string& error_name, | 639 const std::string& error_name, |
641 const std::string& error_message) { | 640 const std::string& error_message) { |
642 DCHECK(IsPresent()); | |
643 // Our agent being already registered isn't an error. | 641 // Our agent being already registered isn't an error. |
644 if (error_name == bluetooth_agent_manager::kErrorAlreadyExists) | 642 if (error_name == bluetooth_agent_manager::kErrorAlreadyExists) |
645 return; | 643 return; |
646 | 644 |
647 LOG(WARNING) << ": Failed to register pairing agent: " | 645 LOG(WARNING) << ": Failed to register pairing agent: " |
648 << error_name << ": " << error_message; | 646 << error_name << ": " << error_message; |
649 } | 647 } |
650 | 648 |
651 void BluetoothAdapterChromeOS::OnRequestDefaultAgent() { | 649 void BluetoothAdapterChromeOS::OnRequestDefaultAgent() { |
652 DCHECK(IsPresent()); | |
653 VLOG(1) << "Pairing agent now default"; | 650 VLOG(1) << "Pairing agent now default"; |
654 } | 651 } |
655 | 652 |
656 void BluetoothAdapterChromeOS::OnRequestDefaultAgentError( | 653 void BluetoothAdapterChromeOS::OnRequestDefaultAgentError( |
657 const std::string& error_name, | 654 const std::string& error_name, |
658 const std::string& error_message) { | 655 const std::string& error_message) { |
659 DCHECK(IsPresent()); | |
660 LOG(WARNING) << ": Failed to make pairing agent default: " | 656 LOG(WARNING) << ": Failed to make pairing agent default: " |
661 << error_name << ": " << error_message; | 657 << error_name << ": " << error_message; |
662 } | 658 } |
663 | 659 |
664 void BluetoothAdapterChromeOS::OnRegisterAudioSink( | 660 void BluetoothAdapterChromeOS::OnRegisterAudioSink( |
665 const device::BluetoothAdapter::AcquiredCallback& callback, | 661 const device::BluetoothAdapter::AcquiredCallback& callback, |
666 scoped_refptr<BluetoothAudioSink> audio_sink) { | 662 scoped_refptr<BluetoothAudioSink> audio_sink) { |
663 if (!IsPresent()) | |
armansito
2015/02/19 01:44:47
This really shouldn't happen, since this method ge
scheib
2015/02/19 21:34:15
Done.
| |
664 return; | |
667 DCHECK(audio_sink.get()); | 665 DCHECK(audio_sink.get()); |
668 callback.Run(audio_sink); | 666 callback.Run(audio_sink); |
669 } | 667 } |
670 | 668 |
671 BluetoothDeviceChromeOS* | 669 BluetoothDeviceChromeOS* |
672 BluetoothAdapterChromeOS::GetDeviceWithPath( | 670 BluetoothAdapterChromeOS::GetDeviceWithPath( |
673 const dbus::ObjectPath& object_path) { | 671 const dbus::ObjectPath& object_path) { |
674 if (!IsPresent()) | 672 if (!IsPresent()) |
675 return NULL; | 673 return NULL; |
676 | 674 |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1012 << ": Failed to register profile: " << error_name << ": " | 1010 << ": Failed to register profile: " << error_name << ": " |
1013 << error_message; | 1011 << error_message; |
1014 error_callback.Run(error_message); | 1012 error_callback.Run(error_message); |
1015 ReleaseProfile(uuid); | 1013 ReleaseProfile(uuid); |
1016 } | 1014 } |
1017 | 1015 |
1018 void BluetoothAdapterChromeOS::OnSetDiscoverable( | 1016 void BluetoothAdapterChromeOS::OnSetDiscoverable( |
1019 const base::Closure& callback, | 1017 const base::Closure& callback, |
1020 const ErrorCallback& error_callback, | 1018 const ErrorCallback& error_callback, |
1021 bool success) { | 1019 bool success) { |
1022 DCHECK(IsPresent()); | 1020 if (!IsPresent()) { |
1021 error_callback.Run(); | |
1022 return; | |
1023 } | |
armansito
2015/02/19 01:44:47
nit: newline after '}'.
scheib
2015/02/19 21:34:15
Done.
| |
1023 // Set the discoverable_timeout property to zero so the adapter remains | 1024 // Set the discoverable_timeout property to zero so the adapter remains |
1024 // discoverable forever. | 1025 // discoverable forever. |
1025 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 1026 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> |
1026 GetProperties(object_path_)->discoverable_timeout.Set( | 1027 GetProperties(object_path_)->discoverable_timeout.Set( |
1027 0, | 1028 0, |
1028 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, | 1029 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, |
1029 weak_ptr_factory_.GetWeakPtr(), | 1030 weak_ptr_factory_.GetWeakPtr(), |
1030 callback, | 1031 callback, |
1031 error_callback)); | 1032 error_callback)); |
1032 } | 1033 } |
1033 | 1034 |
1034 void BluetoothAdapterChromeOS::OnPropertyChangeCompleted( | 1035 void BluetoothAdapterChromeOS::OnPropertyChangeCompleted( |
1035 const base::Closure& callback, | 1036 const base::Closure& callback, |
1036 const ErrorCallback& error_callback, | 1037 const ErrorCallback& error_callback, |
1037 bool success) { | 1038 bool success) { |
1038 DCHECK(IsPresent()); | 1039 if (IsPresent() && success) |
1039 if (success) | |
1040 callback.Run(); | 1040 callback.Run(); |
1041 else | 1041 else |
1042 error_callback.Run(); | 1042 error_callback.Run(); |
1043 } | 1043 } |
1044 | 1044 |
1045 void BluetoothAdapterChromeOS::AddDiscoverySession( | 1045 void BluetoothAdapterChromeOS::AddDiscoverySession( |
1046 const base::Closure& callback, | 1046 const base::Closure& callback, |
1047 const ErrorCallback& error_callback) { | 1047 const ErrorCallback& error_callback) { |
1048 if (!IsPresent()) { | 1048 if (!IsPresent()) { |
1049 error_callback.Run(); | 1049 error_callback.Run(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1082 callback), | 1082 callback), |
1083 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscoveryError, | 1083 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscoveryError, |
1084 weak_ptr_factory_.GetWeakPtr(), | 1084 weak_ptr_factory_.GetWeakPtr(), |
1085 callback, | 1085 callback, |
1086 error_callback)); | 1086 error_callback)); |
1087 } | 1087 } |
1088 | 1088 |
1089 void BluetoothAdapterChromeOS::RemoveDiscoverySession( | 1089 void BluetoothAdapterChromeOS::RemoveDiscoverySession( |
1090 const base::Closure& callback, | 1090 const base::Closure& callback, |
1091 const ErrorCallback& error_callback) { | 1091 const ErrorCallback& error_callback) { |
1092 DCHECK(IsPresent()); | 1092 if (!IsPresent()) { |
1093 error_callback.Run(); | |
1094 return; | |
1095 } | |
1096 | |
1093 VLOG(1) << __func__; | 1097 VLOG(1) << __func__; |
1094 // There are active sessions other than the one currently being removed. | 1098 // There are active sessions other than the one currently being removed. |
1095 if (num_discovery_sessions_ > 1) { | 1099 if (num_discovery_sessions_ > 1) { |
1096 DCHECK(IsDiscovering()); | 1100 DCHECK(IsDiscovering()); |
1097 DCHECK(!discovery_request_pending_); | 1101 DCHECK(!discovery_request_pending_); |
1098 num_discovery_sessions_--; | 1102 num_discovery_sessions_--; |
1099 callback.Run(); | 1103 callback.Run(); |
1100 return; | 1104 return; |
1101 } | 1105 } |
1102 | 1106 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1145 | 1149 |
1146 // Try to add a new discovery session for each queued request. | 1150 // Try to add a new discovery session for each queued request. |
1147 ProcessQueuedDiscoveryRequests(); | 1151 ProcessQueuedDiscoveryRequests(); |
1148 } | 1152 } |
1149 | 1153 |
1150 void BluetoothAdapterChromeOS::OnStartDiscoveryError( | 1154 void BluetoothAdapterChromeOS::OnStartDiscoveryError( |
1151 const base::Closure& callback, | 1155 const base::Closure& callback, |
1152 const ErrorCallback& error_callback, | 1156 const ErrorCallback& error_callback, |
1153 const std::string& error_name, | 1157 const std::string& error_name, |
1154 const std::string& error_message) { | 1158 const std::string& error_message) { |
1155 DCHECK(IsPresent()); | 1159 if (!IsPresent()) { |
1160 error_callback.Run(); | |
1161 return; | |
1162 } | |
1156 LOG(WARNING) << object_path_.value() << ": Failed to start discovery: " | 1163 LOG(WARNING) << object_path_.value() << ": Failed to start discovery: " |
1157 << error_name << ": " << error_message; | 1164 << error_name << ": " << error_message; |
1158 | 1165 |
1159 // Failed to start discovery. This can only happen if the count is at 0. | 1166 // Failed to start discovery. This can only happen if the count is at 0. |
1160 DCHECK_EQ(num_discovery_sessions_, 0); | 1167 DCHECK_EQ(num_discovery_sessions_, 0); |
1161 DCHECK(discovery_request_pending_); | 1168 DCHECK(discovery_request_pending_); |
1162 discovery_request_pending_ = false; | 1169 discovery_request_pending_ = false; |
1163 | 1170 |
1164 // Discovery request may fail if discovery was previously initiated by Chrome, | 1171 // Discovery request may fail if discovery was previously initiated by Chrome, |
1165 // but the session were invalidated due to the discovery state unexpectedly | 1172 // but the session were invalidated due to the discovery state unexpectedly |
(...skipping 21 matching lines...) Expand all Loading... | |
1187 callback.Run(); | 1194 callback.Run(); |
1188 | 1195 |
1189 // Try to add a new discovery session for each queued request. | 1196 // Try to add a new discovery session for each queued request. |
1190 ProcessQueuedDiscoveryRequests(); | 1197 ProcessQueuedDiscoveryRequests(); |
1191 } | 1198 } |
1192 | 1199 |
1193 void BluetoothAdapterChromeOS::OnStopDiscoveryError( | 1200 void BluetoothAdapterChromeOS::OnStopDiscoveryError( |
1194 const ErrorCallback& error_callback, | 1201 const ErrorCallback& error_callback, |
1195 const std::string& error_name, | 1202 const std::string& error_name, |
1196 const std::string& error_message) { | 1203 const std::string& error_message) { |
1197 DCHECK(IsPresent()); | |
1198 LOG(WARNING) << object_path_.value() << ": Failed to stop discovery: " | 1204 LOG(WARNING) << object_path_.value() << ": Failed to stop discovery: " |
1199 << error_name << ": " << error_message; | 1205 << error_name << ": " << error_message; |
1206 if (!IsPresent()) { | |
1207 error_callback.Run(); | |
1208 return; | |
1209 } | |
armansito
2015/02/19 01:44:47
Wouldn't we want to clear the pending discovery re
scheib
2015/02/19 21:34:15
Done.
| |
1200 | 1210 |
1201 // Failed to stop discovery. This can only happen if the count is at 1. | 1211 // Failed to stop discovery. This can only happen if the count is at 1. |
1202 DCHECK(discovery_request_pending_); | 1212 DCHECK(discovery_request_pending_); |
1203 DCHECK_EQ(num_discovery_sessions_, 1); | 1213 DCHECK_EQ(num_discovery_sessions_, 1); |
1204 discovery_request_pending_ = false; | 1214 discovery_request_pending_ = false; |
1205 error_callback.Run(); | 1215 error_callback.Run(); |
1206 | 1216 |
1207 // Try to add a new discovery session for each queued request. | 1217 // Try to add a new discovery session for each queued request. |
1208 ProcessQueuedDiscoveryRequests(); | 1218 ProcessQueuedDiscoveryRequests(); |
1209 } | 1219 } |
1210 | 1220 |
1211 void BluetoothAdapterChromeOS::ProcessQueuedDiscoveryRequests() { | 1221 void BluetoothAdapterChromeOS::ProcessQueuedDiscoveryRequests() { |
1212 while (!discovery_request_queue_.empty()) { | 1222 while (!discovery_request_queue_.empty()) { |
1213 VLOG(1) << "Process queued discovery request."; | 1223 VLOG(1) << "Process queued discovery request."; |
1214 DiscoveryCallbackPair callbacks = discovery_request_queue_.front(); | 1224 DiscoveryCallbackPair callbacks = discovery_request_queue_.front(); |
1215 discovery_request_queue_.pop(); | 1225 discovery_request_queue_.pop(); |
1216 AddDiscoverySession(callbacks.first, callbacks.second); | 1226 AddDiscoverySession(callbacks.first, callbacks.second); |
1217 | 1227 |
1218 // If the queued request resulted in a pending call, then let it | 1228 // If the queued request resulted in a pending call, then let it |
1219 // asynchonously process the remaining queued requests once the pending | 1229 // asynchonously process the remaining queued requests once the pending |
1220 // call returns. | 1230 // call returns. |
1221 if (discovery_request_pending_) | 1231 if (discovery_request_pending_) |
1222 return; | 1232 return; |
1223 } | 1233 } |
1224 } | 1234 } |
1225 | 1235 |
1226 } // namespace chromeos | 1236 } // namespace chromeos |
OLD | NEW |