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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 void BluetoothAdapterChromeOS::Shutdown() { | 78 void BluetoothAdapterChromeOS::Shutdown() { |
79 if (dbus_is_shutdown_) | 79 if (dbus_is_shutdown_) |
80 return; | 80 return; |
81 DCHECK(DBusThreadManager::IsInitialized()) | 81 DCHECK(DBusThreadManager::IsInitialized()) |
82 << "Call BluetoothAdapterFactory::Shutdown() before " | 82 << "Call BluetoothAdapterFactory::Shutdown() before " |
83 "DBusThreadManager::Shutdown()."; | 83 "DBusThreadManager::Shutdown()."; |
84 | 84 |
85 if (IsPresent()) | 85 if (IsPresent()) |
86 RemoveAdapter(); // Also deletes devices_. | 86 RemoveAdapter(); // Also deletes devices_. |
87 DCHECK(devices_.empty()); | 87 DCHECK(devices_.empty()); |
88 // profiles_ should be empty because all BluetoothSockets have been signaled | |
89 // that this adapter is disappearing. | |
90 DCHECK(profiles_.empty()); | |
armansito
2015/02/27 21:04:57
Do you need a DCHECK for |profile_queues_| being e
Marie Janssen
2015/02/27 22:56:06
Done.
| |
88 | 91 |
89 DBusThreadManager::Get()->GetBluetoothAdapterClient()->RemoveObserver(this); | 92 DBusThreadManager::Get()->GetBluetoothAdapterClient()->RemoveObserver(this); |
90 DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this); | 93 DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this); |
91 DBusThreadManager::Get()->GetBluetoothInputClient()->RemoveObserver(this); | 94 DBusThreadManager::Get()->GetBluetoothInputClient()->RemoveObserver(this); |
92 | 95 |
93 VLOG(1) << "Unregistering pairing agent"; | 96 VLOG(1) << "Unregistering pairing agent"; |
94 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()->UnregisterAgent( | 97 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()->UnregisterAgent( |
95 dbus::ObjectPath(kAgentPath), base::Bind(&base::DoNothing), | 98 dbus::ObjectPath(kAgentPath), base::Bind(&base::DoNothing), |
96 base::Bind(&OnUnregisterAgentError)); | 99 base::Bind(&OnUnregisterAgentError)); |
97 | 100 |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
956 DCHECK(delegate); | 959 DCHECK(delegate); |
957 | 960 |
958 if (profiles_.find(uuid) != profiles_.end()) { | 961 if (profiles_.find(uuid) != profiles_.end()) { |
959 // TODO(jamuraa) check that the options are the same and error when they are | 962 // TODO(jamuraa) check that the options are the same and error when they are |
960 // not. | 963 // not. |
961 SetProfileDelegate(uuid, device_path, delegate, success_callback, | 964 SetProfileDelegate(uuid, device_path, delegate, success_callback, |
962 error_callback); | 965 error_callback); |
963 return; | 966 return; |
964 } | 967 } |
965 | 968 |
966 profiles_[uuid] = BluetoothAdapterProfileChromeOS::Register( | 969 if (profile_queues_.find(uuid) == profile_queues_.end()) { |
967 this, uuid, options, | 970 BluetoothAdapterProfileChromeOS::Register( |
968 base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfile, this, uuid, | 971 uuid, options, |
972 base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfile, this, uuid), | |
973 base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfileError, this, | |
974 uuid)); | |
975 | |
976 profile_queues_[uuid] = new std::vector<RegisterProfileCompletionPair>(); | |
977 } | |
978 | |
979 profile_queues_[uuid]->push_back(std::make_pair( | |
980 base::Bind(&BluetoothAdapterChromeOS::SetProfileDelegate, this, uuid, | |
969 device_path, delegate, success_callback, error_callback), | 981 device_path, delegate, success_callback, error_callback), |
970 base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfileError, this, uuid, | 982 error_callback)); |
971 error_callback)); | |
972 } | 983 } |
973 | 984 |
974 void BluetoothAdapterChromeOS::ReleaseProfile(const BluetoothUUID& uuid) { | 985 void BluetoothAdapterChromeOS::ReleaseProfile( |
986 const dbus::ObjectPath& device_path, | |
987 BluetoothAdapterProfileChromeOS* profile) { | |
988 VLOG(2) << "Releasing Profile: " << profile->uuid().canonical_value() | |
989 << " from " << device_path.value(); | |
990 profile->RemoveDelegate( | |
991 device_path, base::Bind(&BluetoothAdapterChromeOS::RemoveProfile, | |
992 weak_ptr_factory_.GetWeakPtr(), profile->uuid())); | |
993 } | |
994 | |
995 void BluetoothAdapterChromeOS::RemoveProfile(const BluetoothUUID& uuid) { | |
975 if (profiles_.find(uuid) != profiles_.end()) { | 996 if (profiles_.find(uuid) != profiles_.end()) { |
976 delete profiles_[uuid]; | 997 delete profiles_[uuid]; |
977 profiles_.erase(uuid); | 998 profiles_.erase(uuid); |
978 } | 999 } |
979 } | 1000 } |
980 | 1001 |
981 void BluetoothAdapterChromeOS::OnRegisterProfile( | 1002 void BluetoothAdapterChromeOS::OnRegisterProfile( |
982 const BluetoothUUID& uuid, | 1003 const BluetoothUUID& uuid, |
983 const dbus::ObjectPath& device_path, | 1004 BluetoothAdapterProfileChromeOS* profile) { |
984 BluetoothProfileServiceProvider::Delegate* delegate, | 1005 profiles_[uuid] = profile; |
985 const ProfileRegisteredCallback& success_callback, | 1006 for (auto& it : *profile_queues_[uuid]) { |
986 const ErrorCompletionCallback& error_callback) { | 1007 it.first.Run(); |
987 SetProfileDelegate(uuid, device_path, delegate, success_callback, | 1008 } |
988 error_callback); | 1009 delete profile_queues_[uuid]; |
1010 profile_queues_.erase(uuid); | |
989 } | 1011 } |
990 | 1012 |
991 bool BluetoothAdapterChromeOS::SetProfileDelegate( | 1013 void BluetoothAdapterChromeOS::SetProfileDelegate( |
992 const BluetoothUUID& uuid, | 1014 const BluetoothUUID& uuid, |
993 const dbus::ObjectPath& device_path, | 1015 const dbus::ObjectPath& device_path, |
994 BluetoothProfileServiceProvider::Delegate* delegate, | 1016 BluetoothProfileServiceProvider::Delegate* delegate, |
995 const ProfileRegisteredCallback& success_callback, | 1017 const ProfileRegisteredCallback& success_callback, |
996 const ErrorCompletionCallback& error_callback) { | 1018 const ErrorCompletionCallback& error_callback) { |
997 if (profiles_[uuid]->SetDelegate(device_path, delegate)) { | 1019 if (profiles_[uuid]->SetDelegate(device_path, delegate)) { |
998 success_callback.Run(profiles_[uuid]); | 1020 success_callback.Run(profiles_[uuid]); |
999 return true; | 1021 return; |
1000 } | 1022 } |
1001 // Already set | 1023 // Already set |
1002 error_callback.Run(bluetooth_agent_manager::kErrorAlreadyExists); | 1024 error_callback.Run(bluetooth_agent_manager::kErrorAlreadyExists); |
1003 return false; | |
1004 } | 1025 } |
1005 | 1026 |
1006 void BluetoothAdapterChromeOS::OnRegisterProfileError( | 1027 void BluetoothAdapterChromeOS::OnRegisterProfileError( |
1007 const BluetoothUUID& uuid, | 1028 const BluetoothUUID& uuid, |
1008 const ErrorCompletionCallback& error_callback, | |
1009 const std::string& error_name, | 1029 const std::string& error_name, |
1010 const std::string& error_message) { | 1030 const std::string& error_message) { |
1011 LOG(WARNING) << object_path_.value() | 1031 VLOG(2) << object_path_.value() << ": Failed to register profile: " |
1012 << ": Failed to register profile: " << error_name << ": " | 1032 << error_name << ": " << error_message; |
1013 << error_message; | 1033 for (auto& it : *profile_queues_[uuid]) { |
1014 error_callback.Run(error_message); | 1034 it.second.Run(error_message); |
1015 ReleaseProfile(uuid); | 1035 } |
armansito
2015/02/27 21:04:57
nit: no need for curly braces in single-line if bo
Marie Janssen
2015/02/27 22:56:06
Done.
| |
1036 delete profile_queues_[uuid]; | |
1037 profile_queues_.erase(uuid); | |
1016 } | 1038 } |
1017 | 1039 |
1018 void BluetoothAdapterChromeOS::OnSetDiscoverable( | 1040 void BluetoothAdapterChromeOS::OnSetDiscoverable( |
1019 const base::Closure& callback, | 1041 const base::Closure& callback, |
1020 const ErrorCallback& error_callback, | 1042 const ErrorCallback& error_callback, |
1021 bool success) { | 1043 bool success) { |
1022 DCHECK(IsPresent()); | 1044 DCHECK(IsPresent()); |
1023 // Set the discoverable_timeout property to zero so the adapter remains | 1045 // Set the discoverable_timeout property to zero so the adapter remains |
1024 // discoverable forever. | 1046 // discoverable forever. |
1025 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 1047 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1217 | 1239 |
1218 // If the queued request resulted in a pending call, then let it | 1240 // If the queued request resulted in a pending call, then let it |
1219 // asynchonously process the remaining queued requests once the pending | 1241 // asynchonously process the remaining queued requests once the pending |
1220 // call returns. | 1242 // call returns. |
1221 if (discovery_request_pending_) | 1243 if (discovery_request_pending_) |
1222 return; | 1244 return; |
1223 } | 1245 } |
1224 } | 1246 } |
1225 | 1247 |
1226 } // namespace chromeos | 1248 } // namespace chromeos |
OLD | NEW |