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 DCHECK(profiles_.empty()); | |
armansito
2015/02/24 23:32:51
Is this because RemoveAdapter clears |profiles_|?
Marie Janssen
2015/02/27 18:56:58
RemoveAdapter() signals the profiles through Prese
| |
88 | 89 |
89 DBusThreadManager::Get()->GetBluetoothAdapterClient()->RemoveObserver(this); | 90 DBusThreadManager::Get()->GetBluetoothAdapterClient()->RemoveObserver(this); |
90 DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this); | 91 DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this); |
91 DBusThreadManager::Get()->GetBluetoothInputClient()->RemoveObserver(this); | 92 DBusThreadManager::Get()->GetBluetoothInputClient()->RemoveObserver(this); |
92 | 93 |
93 VLOG(1) << "Unregistering pairing agent"; | 94 VLOG(1) << "Unregistering pairing agent"; |
94 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()->UnregisterAgent( | 95 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()->UnregisterAgent( |
95 dbus::ObjectPath(kAgentPath), base::Bind(&base::DoNothing), | 96 dbus::ObjectPath(kAgentPath), base::Bind(&base::DoNothing), |
96 base::Bind(&OnUnregisterAgentError)); | 97 base::Bind(&OnUnregisterAgentError)); |
97 | 98 |
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
957 | 958 |
958 if (profiles_.find(uuid) != profiles_.end()) { | 959 if (profiles_.find(uuid) != profiles_.end()) { |
959 // TODO(jamuraa) check that the options are the same and error when they are | 960 // TODO(jamuraa) check that the options are the same and error when they are |
960 // not. | 961 // not. |
961 SetProfileDelegate(uuid, device_path, delegate, success_callback, | 962 SetProfileDelegate(uuid, device_path, delegate, success_callback, |
962 error_callback); | 963 error_callback); |
963 return; | 964 return; |
964 } | 965 } |
965 | 966 |
966 profiles_[uuid] = BluetoothAdapterProfileChromeOS::Register( | 967 profiles_[uuid] = BluetoothAdapterProfileChromeOS::Register( |
967 this, uuid, options, | 968 uuid, options, |
968 base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfile, this, uuid, | 969 base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfile, this, uuid, |
969 device_path, delegate, success_callback, error_callback), | 970 device_path, delegate, success_callback, error_callback), |
970 base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfileError, this, uuid, | 971 base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfileError, this, uuid, |
971 error_callback)); | 972 error_callback)); |
972 } | 973 } |
973 | 974 |
974 void BluetoothAdapterChromeOS::ReleaseProfile(const BluetoothUUID& uuid) { | 975 void BluetoothAdapterChromeOS::ReleaseProfile( |
976 const dbus::ObjectPath& device_path, | |
977 BluetoothAdapterProfileChromeOS* profile) { | |
armansito
2015/02/24 23:32:51
Add VLOG
Marie Janssen
2015/02/27 18:56:58
Done.
| |
978 profile->RemoveDelegate( | |
979 device_path, base::Bind(&BluetoothAdapterChromeOS::RemoveProfile, | |
980 weak_ptr_factory_.GetWeakPtr(), profile->uuid())); | |
981 } | |
982 | |
983 void BluetoothAdapterChromeOS::RemoveProfile(const BluetoothUUID& uuid) { | |
975 if (profiles_.find(uuid) != profiles_.end()) { | 984 if (profiles_.find(uuid) != profiles_.end()) { |
976 delete profiles_[uuid]; | 985 delete profiles_[uuid]; |
977 profiles_.erase(uuid); | 986 profiles_.erase(uuid); |
978 } | 987 } |
979 } | 988 } |
980 | 989 |
981 void BluetoothAdapterChromeOS::OnRegisterProfile( | 990 void BluetoothAdapterChromeOS::OnRegisterProfile( |
982 const BluetoothUUID& uuid, | 991 const BluetoothUUID& uuid, |
983 const dbus::ObjectPath& device_path, | 992 const dbus::ObjectPath& device_path, |
984 BluetoothProfileServiceProvider::Delegate* delegate, | 993 BluetoothProfileServiceProvider::Delegate* delegate, |
(...skipping 16 matching lines...) Expand all Loading... | |
1001 // Already set | 1010 // Already set |
1002 error_callback.Run(bluetooth_agent_manager::kErrorAlreadyExists); | 1011 error_callback.Run(bluetooth_agent_manager::kErrorAlreadyExists); |
1003 return false; | 1012 return false; |
1004 } | 1013 } |
1005 | 1014 |
1006 void BluetoothAdapterChromeOS::OnRegisterProfileError( | 1015 void BluetoothAdapterChromeOS::OnRegisterProfileError( |
1007 const BluetoothUUID& uuid, | 1016 const BluetoothUUID& uuid, |
1008 const ErrorCompletionCallback& error_callback, | 1017 const ErrorCompletionCallback& error_callback, |
1009 const std::string& error_name, | 1018 const std::string& error_name, |
1010 const std::string& error_message) { | 1019 const std::string& error_message) { |
1011 LOG(WARNING) << object_path_.value() | 1020 LOG(WARNING) << object_path_.value() |
armansito
2015/02/24 23:32:51
Change this to VLOG
Marie Janssen
2015/02/27 18:56:58
Done.
| |
1012 << ": Failed to register profile: " << error_name << ": " | 1021 << ": Failed to register profile: " << error_name << ": " |
1013 << error_message; | 1022 << error_message; |
1023 delete profiles_[uuid]; | |
1024 profiles_.erase(uuid); | |
armansito
2015/02/24 23:32:51
I think you can simplify the memory management her
Marie Janssen
2015/02/27 18:56:58
I've reworked this to avoid these problems. Now t
| |
1014 error_callback.Run(error_message); | 1025 error_callback.Run(error_message); |
1015 ReleaseProfile(uuid); | |
1016 } | 1026 } |
1017 | 1027 |
1018 void BluetoothAdapterChromeOS::OnSetDiscoverable( | 1028 void BluetoothAdapterChromeOS::OnSetDiscoverable( |
1019 const base::Closure& callback, | 1029 const base::Closure& callback, |
1020 const ErrorCallback& error_callback, | 1030 const ErrorCallback& error_callback, |
1021 bool success) { | 1031 bool success) { |
1022 DCHECK(IsPresent()); | 1032 DCHECK(IsPresent()); |
1023 // Set the discoverable_timeout property to zero so the adapter remains | 1033 // Set the discoverable_timeout property to zero so the adapter remains |
1024 // discoverable forever. | 1034 // discoverable forever. |
1025 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 1035 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |