| 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_bluez.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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 16 #include "chromeos/system/devicetype.h" | 16 #include "device/bluetooth/bluetooth_adapter_profile_bluez.h" |
| 17 #include "device/bluetooth/bluetooth_adapter_profile_chromeos.h" | 17 #include "device/bluetooth/bluetooth_advertisement_bluez.h" |
| 18 #include "device/bluetooth/bluetooth_advertisement_chromeos.h" | 18 #include "device/bluetooth/bluetooth_audio_sink_bluez.h" |
| 19 #include "device/bluetooth/bluetooth_audio_sink_chromeos.h" | |
| 20 #include "device/bluetooth/bluetooth_device.h" | 19 #include "device/bluetooth/bluetooth_device.h" |
| 21 #include "device/bluetooth/bluetooth_device_chromeos.h" | 20 #include "device/bluetooth/bluetooth_device_bluez.h" |
| 22 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" | 21 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" |
| 23 #include "device/bluetooth/bluetooth_pairing_chromeos.h" | 22 #include "device/bluetooth/bluetooth_pairing_bluez.h" |
| 24 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h" | 23 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h" |
| 25 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h" | 24 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_bluez.h" |
| 26 #include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h" | 25 #include "device/bluetooth/bluetooth_remote_gatt_service_bluez.h" |
| 27 #include "device/bluetooth/bluetooth_socket_chromeos.h" | 26 #include "device/bluetooth/bluetooth_socket_bluez.h" |
| 28 #include "device/bluetooth/bluetooth_socket_thread.h" | 27 #include "device/bluetooth/bluetooth_socket_thread.h" |
| 29 #include "device/bluetooth/bluetooth_uuid.h" | 28 #include "device/bluetooth/bluetooth_uuid.h" |
| 30 #include "device/bluetooth/dbus/bluetooth_adapter_client.h" | 29 #include "device/bluetooth/dbus/bluetooth_adapter_client.h" |
| 31 #include "device/bluetooth/dbus/bluetooth_agent_manager_client.h" | 30 #include "device/bluetooth/dbus/bluetooth_agent_manager_client.h" |
| 32 #include "device/bluetooth/dbus/bluetooth_agent_service_provider.h" | 31 #include "device/bluetooth/dbus/bluetooth_agent_service_provider.h" |
| 33 #include "device/bluetooth/dbus/bluetooth_device_client.h" | 32 #include "device/bluetooth/dbus/bluetooth_device_client.h" |
| 34 #include "device/bluetooth/dbus/bluetooth_input_client.h" | 33 #include "device/bluetooth/dbus/bluetooth_input_client.h" |
| 35 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 34 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 36 #include "third_party/cros_system_api/dbus/service_constants.h" | 35 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 37 | 36 |
| 37 #if defined(OS_CHROMEOS) |
| 38 #include "chromeos/system/devicetype.h" |
| 39 #endif |
| 40 |
| 38 using device::BluetoothAdapter; | 41 using device::BluetoothAdapter; |
| 39 using device::BluetoothAudioSink; | 42 using device::BluetoothAudioSink; |
| 40 using device::BluetoothDevice; | 43 using device::BluetoothDevice; |
| 41 using device::BluetoothDiscoveryFilter; | 44 using device::BluetoothDiscoveryFilter; |
| 42 using device::BluetoothSocket; | 45 using device::BluetoothSocket; |
| 43 using device::BluetoothUUID; | 46 using device::BluetoothUUID; |
| 44 using device::UMABluetoothDiscoverySessionOutcome; | 47 using device::UMABluetoothDiscoverySessionOutcome; |
| 45 | 48 |
| 46 namespace { | 49 namespace { |
| 47 | 50 |
| 48 // The agent path is relatively meaningless since BlueZ only permits one to | 51 // The agent path is relatively meaningless since BlueZ only permits one to |
| 49 // exist per D-Bus connection, it just has to be unique within Chromium. | 52 // exist per D-Bus connection, it just has to be unique within Chromium. |
| 50 const char kAgentPath[] = "/org/chromium/bluetooth_agent"; | 53 const char kAgentPath[] = "/org/chromium/bluetooth_agent"; |
| 51 | 54 |
| 52 void OnUnregisterAgentError(const std::string& error_name, | 55 void OnUnregisterAgentError(const std::string& error_name, |
| 53 const std::string& error_message) { | 56 const std::string& error_message) { |
| 54 // It's okay if the agent didn't exist, it means we never saw an adapter. | 57 // It's okay if the agent didn't exist, it means we never saw an adapter. |
| 55 if (error_name == bluetooth_agent_manager::kErrorDoesNotExist) | 58 if (error_name == bluetooth_agent_manager::kErrorDoesNotExist) |
| 56 return; | 59 return; |
| 57 | 60 |
| 58 LOG(WARNING) << "Failed to unregister pairing agent: " | 61 LOG(WARNING) << "Failed to unregister pairing agent: " << error_name << ": " |
| 59 << error_name << ": " << error_message; | 62 << error_message; |
| 60 } | 63 } |
| 61 | 64 |
| 62 UMABluetoothDiscoverySessionOutcome TranslateDiscoveryErrorToUMA( | 65 UMABluetoothDiscoverySessionOutcome TranslateDiscoveryErrorToUMA( |
| 63 const std::string& error_name) { | 66 const std::string& error_name) { |
| 64 if (error_name == bluez::BluetoothAdapterClient::kUnknownAdapterError) { | 67 if (error_name == bluez::BluetoothAdapterClient::kUnknownAdapterError) { |
| 65 return UMABluetoothDiscoverySessionOutcome::CHROMEOS_DBUS_UNKNOWN_ADAPTER; | 68 return UMABluetoothDiscoverySessionOutcome::BLUEZ_DBUS_UNKNOWN_ADAPTER; |
| 66 } else if (error_name == bluez::BluetoothAdapterClient::kNoResponseError) { | 69 } else if (error_name == bluez::BluetoothAdapterClient::kNoResponseError) { |
| 67 return UMABluetoothDiscoverySessionOutcome::CHROMEOS_DBUS_NO_RESPONSE; | 70 return UMABluetoothDiscoverySessionOutcome::BLUEZ_DBUS_NO_RESPONSE; |
| 68 } else if (error_name == bluetooth_device::kErrorInProgress) { | 71 } else if (error_name == bluetooth_device::kErrorInProgress) { |
| 69 return UMABluetoothDiscoverySessionOutcome::CHROMEOS_DBUS_IN_PROGRESS; | 72 return UMABluetoothDiscoverySessionOutcome::BLUEZ_DBUS_IN_PROGRESS; |
| 70 } else if (error_name == bluetooth_device::kErrorNotReady) { | 73 } else if (error_name == bluetooth_device::kErrorNotReady) { |
| 71 return UMABluetoothDiscoverySessionOutcome::CHROMEOS_DBUS_NOT_READY; | 74 return UMABluetoothDiscoverySessionOutcome::BLUEZ_DBUS_NOT_READY; |
| 72 } else if (error_name == bluetooth_device::kErrorFailed) { | 75 } else if (error_name == bluetooth_device::kErrorFailed) { |
| 73 return UMABluetoothDiscoverySessionOutcome::FAILED; | 76 return UMABluetoothDiscoverySessionOutcome::FAILED; |
| 74 } else { | 77 } else { |
| 75 LOG(WARNING) << "Can't histogram DBus error " << error_name; | 78 LOG(WARNING) << "Can't histogram DBus error " << error_name; |
| 76 return UMABluetoothDiscoverySessionOutcome::UNKNOWN; | 79 return UMABluetoothDiscoverySessionOutcome::UNKNOWN; |
| 77 } | 80 } |
| 78 } | 81 } |
| 79 | 82 |
| 80 } // namespace | 83 } // namespace |
| 81 | 84 |
| 82 namespace device { | 85 namespace device { |
| 83 | 86 |
| 84 // static | 87 // static |
| 85 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( | 88 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( |
| 86 const InitCallback& init_callback) { | 89 const InitCallback& init_callback) { |
| 87 return chromeos::BluetoothAdapterChromeOS::CreateAdapter(); | 90 return bluez::BluetoothAdapterBlueZ::CreateAdapter(); |
| 88 } | 91 } |
| 89 | 92 |
| 90 } // namespace device | 93 } // namespace device |
| 91 | 94 |
| 92 namespace chromeos { | 95 namespace bluez { |
| 93 | 96 |
| 94 // static | 97 // static |
| 95 base::WeakPtr<BluetoothAdapter> BluetoothAdapterChromeOS::CreateAdapter() { | 98 base::WeakPtr<BluetoothAdapter> BluetoothAdapterBlueZ::CreateAdapter() { |
| 96 BluetoothAdapterChromeOS* adapter = new BluetoothAdapterChromeOS(); | 99 BluetoothAdapterBlueZ* adapter = new BluetoothAdapterBlueZ(); |
| 97 return adapter->weak_ptr_factory_.GetWeakPtr(); | 100 return adapter->weak_ptr_factory_.GetWeakPtr(); |
| 98 } | 101 } |
| 99 | 102 |
| 100 void BluetoothAdapterChromeOS::Shutdown() { | 103 void BluetoothAdapterBlueZ::Shutdown() { |
| 101 if (dbus_is_shutdown_) | 104 if (dbus_is_shutdown_) |
| 102 return; | 105 return; |
| 103 DCHECK(bluez::BluezDBusManager::IsInitialized()) | 106 DCHECK(bluez::BluezDBusManager::IsInitialized()) |
| 104 << "Call BluetoothAdapterFactory::Shutdown() before " | 107 << "Call BluetoothAdapterFactory::Shutdown() before " |
| 105 "BluezDBusManager::Shutdown()."; | 108 "BluezDBusManager::Shutdown()."; |
| 106 | 109 |
| 107 if (IsPresent()) | 110 if (IsPresent()) |
| 108 RemoveAdapter(); // Also deletes devices_. | 111 RemoveAdapter(); // Also deletes devices_. |
| 109 DCHECK(devices_.empty()); | 112 DCHECK(devices_.empty()); |
| 110 // profiles_ is empty because all BluetoothSockets have been notified | 113 // profiles_ is empty because all BluetoothSockets have been notified |
| (...skipping 15 matching lines...) Expand all Loading... |
| 126 bluez::BluezDBusManager::Get() | 129 bluez::BluezDBusManager::Get() |
| 127 ->GetBluetoothAgentManagerClient() | 130 ->GetBluetoothAgentManagerClient() |
| 128 ->UnregisterAgent(dbus::ObjectPath(kAgentPath), | 131 ->UnregisterAgent(dbus::ObjectPath(kAgentPath), |
| 129 base::Bind(&base::DoNothing), | 132 base::Bind(&base::DoNothing), |
| 130 base::Bind(&OnUnregisterAgentError)); | 133 base::Bind(&OnUnregisterAgentError)); |
| 131 | 134 |
| 132 agent_.reset(); | 135 agent_.reset(); |
| 133 dbus_is_shutdown_ = true; | 136 dbus_is_shutdown_ = true; |
| 134 } | 137 } |
| 135 | 138 |
| 136 BluetoothAdapterChromeOS::BluetoothAdapterChromeOS() | 139 BluetoothAdapterBlueZ::BluetoothAdapterBlueZ() |
| 137 : dbus_is_shutdown_(false), | 140 : dbus_is_shutdown_(false), |
| 138 num_discovery_sessions_(0), | 141 num_discovery_sessions_(0), |
| 139 discovery_request_pending_(false), | 142 discovery_request_pending_(false), |
| 140 weak_ptr_factory_(this) { | 143 weak_ptr_factory_(this) { |
| 141 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 144 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 142 socket_thread_ = device::BluetoothSocketThread::Get(); | 145 socket_thread_ = device::BluetoothSocketThread::Get(); |
| 143 | 146 |
| 144 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->AddObserver( | 147 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->AddObserver( |
| 145 this); | 148 this); |
| 146 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->AddObserver(this); | 149 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->AddObserver(this); |
| 147 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->AddObserver(this); | 150 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->AddObserver(this); |
| 148 | 151 |
| 149 // Register the pairing agent. | 152 // Register the pairing agent. |
| 150 dbus::Bus* system_bus = bluez::BluezDBusManager::Get()->GetSystemBus(); | 153 dbus::Bus* system_bus = bluez::BluezDBusManager::Get()->GetSystemBus(); |
| 151 agent_.reset(bluez::BluetoothAgentServiceProvider::Create( | 154 agent_.reset(bluez::BluetoothAgentServiceProvider::Create( |
| 152 system_bus, dbus::ObjectPath(kAgentPath), this)); | 155 system_bus, dbus::ObjectPath(kAgentPath), this)); |
| 153 DCHECK(agent_.get()); | 156 DCHECK(agent_.get()); |
| 154 | 157 |
| 155 std::vector<dbus::ObjectPath> object_paths = bluez::BluezDBusManager::Get() | 158 std::vector<dbus::ObjectPath> object_paths = bluez::BluezDBusManager::Get() |
| 156 ->GetBluetoothAdapterClient() | 159 ->GetBluetoothAdapterClient() |
| 157 ->GetAdapters(); | 160 ->GetAdapters(); |
| 158 | 161 |
| 159 if (!object_paths.empty()) { | 162 if (!object_paths.empty()) { |
| 160 VLOG(1) << object_paths.size() << " Bluetooth adapter(s) available."; | 163 VLOG(1) << object_paths.size() << " Bluetooth adapter(s) available."; |
| 161 SetAdapter(object_paths[0]); | 164 SetAdapter(object_paths[0]); |
| 162 } | 165 } |
| 163 } | 166 } |
| 164 | 167 |
| 165 BluetoothAdapterChromeOS::~BluetoothAdapterChromeOS() { | 168 BluetoothAdapterBlueZ::~BluetoothAdapterBlueZ() { |
| 166 Shutdown(); | 169 Shutdown(); |
| 167 } | 170 } |
| 168 | 171 |
| 169 std::string BluetoothAdapterChromeOS::GetAddress() const { | 172 std::string BluetoothAdapterBlueZ::GetAddress() const { |
| 170 if (!IsPresent()) | 173 if (!IsPresent()) |
| 171 return std::string(); | 174 return std::string(); |
| 172 | 175 |
| 173 bluez::BluetoothAdapterClient::Properties* properties = | 176 bluez::BluetoothAdapterClient::Properties* properties = |
| 174 bluez::BluezDBusManager::Get() | 177 bluez::BluezDBusManager::Get() |
| 175 ->GetBluetoothAdapterClient() | 178 ->GetBluetoothAdapterClient() |
| 176 ->GetProperties(object_path_); | 179 ->GetProperties(object_path_); |
| 177 DCHECK(properties); | 180 DCHECK(properties); |
| 178 | 181 |
| 179 return BluetoothDevice::CanonicalizeAddress(properties->address.value()); | 182 return BluetoothDevice::CanonicalizeAddress(properties->address.value()); |
| 180 } | 183 } |
| 181 | 184 |
| 182 std::string BluetoothAdapterChromeOS::GetName() const { | 185 std::string BluetoothAdapterBlueZ::GetName() const { |
| 183 if (!IsPresent()) | 186 if (!IsPresent()) |
| 184 return std::string(); | 187 return std::string(); |
| 185 | 188 |
| 186 bluez::BluetoothAdapterClient::Properties* properties = | 189 bluez::BluetoothAdapterClient::Properties* properties = |
| 187 bluez::BluezDBusManager::Get() | 190 bluez::BluezDBusManager::Get() |
| 188 ->GetBluetoothAdapterClient() | 191 ->GetBluetoothAdapterClient() |
| 189 ->GetProperties(object_path_); | 192 ->GetProperties(object_path_); |
| 190 DCHECK(properties); | 193 DCHECK(properties); |
| 191 | 194 |
| 192 return properties->alias.value(); | 195 return properties->alias.value(); |
| 193 } | 196 } |
| 194 | 197 |
| 195 void BluetoothAdapterChromeOS::SetName(const std::string& name, | 198 void BluetoothAdapterBlueZ::SetName(const std::string& name, |
| 196 const base::Closure& callback, | 199 const base::Closure& callback, |
| 197 const ErrorCallback& error_callback) { | 200 const ErrorCallback& error_callback) { |
| 198 if (!IsPresent()) { | 201 if (!IsPresent()) { |
| 199 error_callback.Run(); | 202 error_callback.Run(); |
| 200 return; | 203 return; |
| 201 } | 204 } |
| 202 | 205 |
| 203 bluez::BluezDBusManager::Get() | 206 bluez::BluezDBusManager::Get() |
| 204 ->GetBluetoothAdapterClient() | 207 ->GetBluetoothAdapterClient() |
| 205 ->GetProperties(object_path_) | 208 ->GetProperties(object_path_) |
| 206 ->alias.Set( | 209 ->alias.Set( |
| 207 name, | 210 name, |
| 208 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, | 211 base::Bind(&BluetoothAdapterBlueZ::OnPropertyChangeCompleted, |
| 209 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 212 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 210 } | 213 } |
| 211 | 214 |
| 212 bool BluetoothAdapterChromeOS::IsInitialized() const { | 215 bool BluetoothAdapterBlueZ::IsInitialized() const { |
| 213 return true; | 216 return true; |
| 214 } | 217 } |
| 215 | 218 |
| 216 bool BluetoothAdapterChromeOS::IsPresent() const { | 219 bool BluetoothAdapterBlueZ::IsPresent() const { |
| 217 return !dbus_is_shutdown_ && !object_path_.value().empty(); | 220 return !dbus_is_shutdown_ && !object_path_.value().empty(); |
| 218 } | 221 } |
| 219 | 222 |
| 220 bool BluetoothAdapterChromeOS::IsPowered() const { | 223 bool BluetoothAdapterBlueZ::IsPowered() const { |
| 221 if (!IsPresent()) | 224 if (!IsPresent()) |
| 222 return false; | 225 return false; |
| 223 | 226 |
| 224 bluez::BluetoothAdapterClient::Properties* properties = | 227 bluez::BluetoothAdapterClient::Properties* properties = |
| 225 bluez::BluezDBusManager::Get() | 228 bluez::BluezDBusManager::Get() |
| 226 ->GetBluetoothAdapterClient() | 229 ->GetBluetoothAdapterClient() |
| 227 ->GetProperties(object_path_); | 230 ->GetProperties(object_path_); |
| 228 | 231 |
| 229 return properties->powered.value(); | 232 return properties->powered.value(); |
| 230 } | 233 } |
| 231 | 234 |
| 232 void BluetoothAdapterChromeOS::SetPowered( | 235 void BluetoothAdapterBlueZ::SetPowered(bool powered, |
| 233 bool powered, | 236 const base::Closure& callback, |
| 234 const base::Closure& callback, | 237 const ErrorCallback& error_callback) { |
| 235 const ErrorCallback& error_callback) { | |
| 236 if (!IsPresent()) { | 238 if (!IsPresent()) { |
| 237 error_callback.Run(); | 239 error_callback.Run(); |
| 238 return; | 240 return; |
| 239 } | 241 } |
| 240 | 242 |
| 241 bluez::BluezDBusManager::Get() | 243 bluez::BluezDBusManager::Get() |
| 242 ->GetBluetoothAdapterClient() | 244 ->GetBluetoothAdapterClient() |
| 243 ->GetProperties(object_path_) | 245 ->GetProperties(object_path_) |
| 244 ->powered.Set( | 246 ->powered.Set( |
| 245 powered, | 247 powered, |
| 246 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, | 248 base::Bind(&BluetoothAdapterBlueZ::OnPropertyChangeCompleted, |
| 247 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 249 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 248 } | 250 } |
| 249 | 251 |
| 250 bool BluetoothAdapterChromeOS::IsDiscoverable() const { | 252 bool BluetoothAdapterBlueZ::IsDiscoverable() const { |
| 251 if (!IsPresent()) | 253 if (!IsPresent()) |
| 252 return false; | 254 return false; |
| 253 | 255 |
| 254 bluez::BluetoothAdapterClient::Properties* properties = | 256 bluez::BluetoothAdapterClient::Properties* properties = |
| 255 bluez::BluezDBusManager::Get() | 257 bluez::BluezDBusManager::Get() |
| 256 ->GetBluetoothAdapterClient() | 258 ->GetBluetoothAdapterClient() |
| 257 ->GetProperties(object_path_); | 259 ->GetProperties(object_path_); |
| 258 | 260 |
| 259 return properties->discoverable.value(); | 261 return properties->discoverable.value(); |
| 260 } | 262 } |
| 261 | 263 |
| 262 void BluetoothAdapterChromeOS::SetDiscoverable( | 264 void BluetoothAdapterBlueZ::SetDiscoverable( |
| 263 bool discoverable, | 265 bool discoverable, |
| 264 const base::Closure& callback, | 266 const base::Closure& callback, |
| 265 const ErrorCallback& error_callback) { | 267 const ErrorCallback& error_callback) { |
| 266 if (!IsPresent()) { | 268 if (!IsPresent()) { |
| 267 error_callback.Run(); | 269 error_callback.Run(); |
| 268 return; | 270 return; |
| 269 } | 271 } |
| 270 | 272 |
| 271 bluez::BluezDBusManager::Get() | 273 bluez::BluezDBusManager::Get() |
| 272 ->GetBluetoothAdapterClient() | 274 ->GetBluetoothAdapterClient() |
| 273 ->GetProperties(object_path_) | 275 ->GetProperties(object_path_) |
| 274 ->discoverable.Set( | 276 ->discoverable.Set( |
| 275 discoverable, | 277 discoverable, |
| 276 base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoverable, | 278 base::Bind(&BluetoothAdapterBlueZ::OnSetDiscoverable, |
| 277 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 279 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 278 } | 280 } |
| 279 | 281 |
| 280 bool BluetoothAdapterChromeOS::IsDiscovering() const { | 282 bool BluetoothAdapterBlueZ::IsDiscovering() const { |
| 281 if (!IsPresent()) | 283 if (!IsPresent()) |
| 282 return false; | 284 return false; |
| 283 | 285 |
| 284 bluez::BluetoothAdapterClient::Properties* properties = | 286 bluez::BluetoothAdapterClient::Properties* properties = |
| 285 bluez::BluezDBusManager::Get() | 287 bluez::BluezDBusManager::Get() |
| 286 ->GetBluetoothAdapterClient() | 288 ->GetBluetoothAdapterClient() |
| 287 ->GetProperties(object_path_); | 289 ->GetProperties(object_path_); |
| 288 | 290 |
| 289 return properties->discovering.value(); | 291 return properties->discovering.value(); |
| 290 } | 292 } |
| 291 | 293 |
| 292 void BluetoothAdapterChromeOS::CreateRfcommService( | 294 void BluetoothAdapterBlueZ::CreateRfcommService( |
| 293 const BluetoothUUID& uuid, | 295 const BluetoothUUID& uuid, |
| 294 const ServiceOptions& options, | 296 const ServiceOptions& options, |
| 295 const CreateServiceCallback& callback, | 297 const CreateServiceCallback& callback, |
| 296 const CreateServiceErrorCallback& error_callback) { | 298 const CreateServiceErrorCallback& error_callback) { |
| 297 DCHECK(!dbus_is_shutdown_); | 299 DCHECK(!dbus_is_shutdown_); |
| 298 VLOG(1) << object_path_.value() << ": Creating RFCOMM service: " | 300 VLOG(1) << object_path_.value() |
| 299 << uuid.canonical_value(); | 301 << ": Creating RFCOMM service: " << uuid.canonical_value(); |
| 300 scoped_refptr<BluetoothSocketChromeOS> socket = | 302 scoped_refptr<BluetoothSocketBlueZ> socket = |
| 301 BluetoothSocketChromeOS::CreateBluetoothSocket( | 303 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, |
| 302 ui_task_runner_, socket_thread_); | 304 socket_thread_); |
| 303 socket->Listen(this, | 305 socket->Listen(this, BluetoothSocketBlueZ::kRfcomm, uuid, options, |
| 304 BluetoothSocketChromeOS::kRfcomm, | 306 base::Bind(callback, socket), error_callback); |
| 305 uuid, | |
| 306 options, | |
| 307 base::Bind(callback, socket), | |
| 308 error_callback); | |
| 309 } | 307 } |
| 310 | 308 |
| 311 void BluetoothAdapterChromeOS::CreateL2capService( | 309 void BluetoothAdapterBlueZ::CreateL2capService( |
| 312 const BluetoothUUID& uuid, | 310 const BluetoothUUID& uuid, |
| 313 const ServiceOptions& options, | 311 const ServiceOptions& options, |
| 314 const CreateServiceCallback& callback, | 312 const CreateServiceCallback& callback, |
| 315 const CreateServiceErrorCallback& error_callback) { | 313 const CreateServiceErrorCallback& error_callback) { |
| 316 DCHECK(!dbus_is_shutdown_); | 314 DCHECK(!dbus_is_shutdown_); |
| 317 VLOG(1) << object_path_.value() << ": Creating L2CAP service: " | 315 VLOG(1) << object_path_.value() |
| 318 << uuid.canonical_value(); | 316 << ": Creating L2CAP service: " << uuid.canonical_value(); |
| 319 scoped_refptr<BluetoothSocketChromeOS> socket = | 317 scoped_refptr<BluetoothSocketBlueZ> socket = |
| 320 BluetoothSocketChromeOS::CreateBluetoothSocket( | 318 BluetoothSocketBlueZ::CreateBluetoothSocket(ui_task_runner_, |
| 321 ui_task_runner_, socket_thread_); | 319 socket_thread_); |
| 322 socket->Listen(this, | 320 socket->Listen(this, BluetoothSocketBlueZ::kL2cap, uuid, options, |
| 323 BluetoothSocketChromeOS::kL2cap, | 321 base::Bind(callback, socket), error_callback); |
| 324 uuid, | |
| 325 options, | |
| 326 base::Bind(callback, socket), | |
| 327 error_callback); | |
| 328 } | 322 } |
| 329 | 323 |
| 330 void BluetoothAdapterChromeOS::RegisterAudioSink( | 324 void BluetoothAdapterBlueZ::RegisterAudioSink( |
| 331 const BluetoothAudioSink::Options& options, | 325 const BluetoothAudioSink::Options& options, |
| 332 const device::BluetoothAdapter::AcquiredCallback& callback, | 326 const device::BluetoothAdapter::AcquiredCallback& callback, |
| 333 const BluetoothAudioSink::ErrorCallback& error_callback) { | 327 const BluetoothAudioSink::ErrorCallback& error_callback) { |
| 334 VLOG(1) << "Registering audio sink"; | 328 VLOG(1) << "Registering audio sink"; |
| 335 if (!this->IsPresent()) { | 329 if (!this->IsPresent()) { |
| 336 error_callback.Run(BluetoothAudioSink::ERROR_INVALID_ADAPTER); | 330 error_callback.Run(BluetoothAudioSink::ERROR_INVALID_ADAPTER); |
| 337 return; | 331 return; |
| 338 } | 332 } |
| 339 scoped_refptr<BluetoothAudioSinkChromeOS> audio_sink( | 333 scoped_refptr<BluetoothAudioSinkBlueZ> audio_sink( |
| 340 new BluetoothAudioSinkChromeOS(this)); | 334 new BluetoothAudioSinkBlueZ(this)); |
| 341 audio_sink->Register( | 335 audio_sink->Register(options, |
| 342 options, base::Bind(&BluetoothAdapterChromeOS::OnRegisterAudioSink, | 336 base::Bind(&BluetoothAdapterBlueZ::OnRegisterAudioSink, |
| 343 weak_ptr_factory_.GetWeakPtr(), callback, | 337 weak_ptr_factory_.GetWeakPtr(), callback, |
| 344 error_callback, audio_sink), | 338 error_callback, audio_sink), |
| 345 error_callback); | 339 error_callback); |
| 346 } | 340 } |
| 347 | 341 |
| 348 void BluetoothAdapterChromeOS::RegisterAdvertisement( | 342 void BluetoothAdapterBlueZ::RegisterAdvertisement( |
| 349 scoped_ptr<device::BluetoothAdvertisement::Data> advertisement_data, | 343 scoped_ptr<device::BluetoothAdvertisement::Data> advertisement_data, |
| 350 const CreateAdvertisementCallback& callback, | 344 const CreateAdvertisementCallback& callback, |
| 351 const CreateAdvertisementErrorCallback& error_callback) { | 345 const CreateAdvertisementErrorCallback& error_callback) { |
| 352 scoped_refptr<BluetoothAdvertisementChromeOS> advertisement( | 346 scoped_refptr<BluetoothAdvertisementBlueZ> advertisement( |
| 353 new BluetoothAdvertisementChromeOS(advertisement_data.Pass(), this)); | 347 new BluetoothAdvertisementBlueZ(advertisement_data.Pass(), this)); |
| 354 advertisement->Register(base::Bind(callback, advertisement), error_callback); | 348 advertisement->Register(base::Bind(callback, advertisement), error_callback); |
| 355 } | 349 } |
| 356 | 350 |
| 357 void BluetoothAdapterChromeOS::RemovePairingDelegateInternal( | 351 void BluetoothAdapterBlueZ::RemovePairingDelegateInternal( |
| 358 BluetoothDevice::PairingDelegate* pairing_delegate) { | 352 BluetoothDevice::PairingDelegate* pairing_delegate) { |
| 359 // Check if any device is using the pairing delegate. | 353 // Check if any device is using the pairing delegate. |
| 360 // If so, clear the pairing context which will make any responses no-ops. | 354 // If so, clear the pairing context which will make any responses no-ops. |
| 361 for (DevicesMap::const_iterator iter = devices_.begin(); | 355 for (DevicesMap::const_iterator iter = devices_.begin(); |
| 362 iter != devices_.end(); ++iter) { | 356 iter != devices_.end(); ++iter) { |
| 363 BluetoothDeviceChromeOS* device_chromeos = | 357 BluetoothDeviceBlueZ* device_bluez = |
| 364 static_cast<BluetoothDeviceChromeOS*>(iter->second); | 358 static_cast<BluetoothDeviceBlueZ*>(iter->second); |
| 365 | 359 |
| 366 BluetoothPairingChromeOS* pairing = device_chromeos->GetPairing(); | 360 BluetoothPairingBlueZ* pairing = device_bluez->GetPairing(); |
| 367 if (pairing && pairing->GetPairingDelegate() == pairing_delegate) | 361 if (pairing && pairing->GetPairingDelegate() == pairing_delegate) |
| 368 device_chromeos->EndPairing(); | 362 device_bluez->EndPairing(); |
| 369 } | 363 } |
| 370 } | 364 } |
| 371 | 365 |
| 372 void BluetoothAdapterChromeOS::AdapterAdded( | 366 void BluetoothAdapterBlueZ::AdapterAdded(const dbus::ObjectPath& object_path) { |
| 373 const dbus::ObjectPath& object_path) { | |
| 374 // Set the adapter to the newly added adapter only if no adapter is present. | 367 // Set the adapter to the newly added adapter only if no adapter is present. |
| 375 if (!IsPresent()) | 368 if (!IsPresent()) |
| 376 SetAdapter(object_path); | 369 SetAdapter(object_path); |
| 377 } | 370 } |
| 378 | 371 |
| 379 void BluetoothAdapterChromeOS::AdapterRemoved( | 372 void BluetoothAdapterBlueZ::AdapterRemoved( |
| 380 const dbus::ObjectPath& object_path) { | 373 const dbus::ObjectPath& object_path) { |
| 381 if (object_path == object_path_) | 374 if (object_path == object_path_) |
| 382 RemoveAdapter(); | 375 RemoveAdapter(); |
| 383 } | 376 } |
| 384 | 377 |
| 385 void BluetoothAdapterChromeOS::AdapterPropertyChanged( | 378 void BluetoothAdapterBlueZ::AdapterPropertyChanged( |
| 386 const dbus::ObjectPath& object_path, | 379 const dbus::ObjectPath& object_path, |
| 387 const std::string& property_name) { | 380 const std::string& property_name) { |
| 388 if (object_path != object_path_) | 381 if (object_path != object_path_) |
| 389 return; | 382 return; |
| 390 DCHECK(IsPresent()); | 383 DCHECK(IsPresent()); |
| 391 | 384 |
| 392 bluez::BluetoothAdapterClient::Properties* properties = | 385 bluez::BluetoothAdapterClient::Properties* properties = |
| 393 bluez::BluezDBusManager::Get() | 386 bluez::BluezDBusManager::Get() |
| 394 ->GetBluetoothAdapterClient() | 387 ->GetBluetoothAdapterClient() |
| 395 ->GetProperties(object_path_); | 388 ->GetProperties(object_path_); |
| 396 | 389 |
| 397 if (property_name == properties->powered.name()) { | 390 if (property_name == properties->powered.name()) { |
| 398 PoweredChanged(properties->powered.value()); | 391 PoweredChanged(properties->powered.value()); |
| 399 } else if (property_name == properties->discoverable.name()) { | 392 } else if (property_name == properties->discoverable.name()) { |
| 400 DiscoverableChanged(properties->discoverable.value()); | 393 DiscoverableChanged(properties->discoverable.value()); |
| 401 } else if (property_name == properties->discovering.name()) { | 394 } else if (property_name == properties->discovering.name()) { |
| 402 DiscoveringChanged(properties->discovering.value()); | 395 DiscoveringChanged(properties->discovering.value()); |
| 403 } | 396 } |
| 404 } | 397 } |
| 405 | 398 |
| 406 void BluetoothAdapterChromeOS::DeviceAdded( | 399 void BluetoothAdapterBlueZ::DeviceAdded(const dbus::ObjectPath& object_path) { |
| 407 const dbus::ObjectPath& object_path) { | |
| 408 DCHECK(bluez::BluezDBusManager::Get()); | 400 DCHECK(bluez::BluezDBusManager::Get()); |
| 409 bluez::BluetoothDeviceClient::Properties* properties = | 401 bluez::BluetoothDeviceClient::Properties* properties = |
| 410 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 402 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 411 object_path); | 403 object_path); |
| 412 if (!properties || properties->adapter.value() != object_path_) | 404 if (!properties || properties->adapter.value() != object_path_) |
| 413 return; | 405 return; |
| 414 DCHECK(IsPresent()); | 406 DCHECK(IsPresent()); |
| 415 | 407 |
| 416 BluetoothDeviceChromeOS* device_chromeos = | 408 BluetoothDeviceBlueZ* device_bluez = new BluetoothDeviceBlueZ( |
| 417 new BluetoothDeviceChromeOS(this, | 409 this, object_path, ui_task_runner_, socket_thread_); |
| 418 object_path, | 410 DCHECK(devices_.find(device_bluez->GetAddress()) == devices_.end()); |
| 419 ui_task_runner_, | |
| 420 socket_thread_); | |
| 421 DCHECK(devices_.find(device_chromeos->GetAddress()) == devices_.end()); | |
| 422 | 411 |
| 423 devices_.set(device_chromeos->GetAddress(), | 412 devices_.set(device_bluez->GetAddress(), |
| 424 scoped_ptr<BluetoothDevice>(device_chromeos)); | 413 scoped_ptr<BluetoothDevice>(device_bluez)); |
| 425 | 414 |
| 426 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 415 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 427 DeviceAdded(this, device_chromeos)); | 416 DeviceAdded(this, device_bluez)); |
| 428 } | 417 } |
| 429 | 418 |
| 430 void BluetoothAdapterChromeOS::DeviceRemoved( | 419 void BluetoothAdapterBlueZ::DeviceRemoved(const dbus::ObjectPath& object_path) { |
| 431 const dbus::ObjectPath& object_path) { | |
| 432 for (DevicesMap::const_iterator iter = devices_.begin(); | 420 for (DevicesMap::const_iterator iter = devices_.begin(); |
| 433 iter != devices_.end(); ++iter) { | 421 iter != devices_.end(); ++iter) { |
| 434 BluetoothDeviceChromeOS* device_chromeos = | 422 BluetoothDeviceBlueZ* device_bluez = |
| 435 static_cast<BluetoothDeviceChromeOS*>(iter->second); | 423 static_cast<BluetoothDeviceBlueZ*>(iter->second); |
| 436 if (device_chromeos->object_path() == object_path) { | 424 if (device_bluez->object_path() == object_path) { |
| 437 scoped_ptr<BluetoothDevice> scoped_device = | 425 scoped_ptr<BluetoothDevice> scoped_device = |
| 438 devices_.take_and_erase(iter->first); | 426 devices_.take_and_erase(iter->first); |
| 439 | 427 |
| 440 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 428 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 441 DeviceRemoved(this, device_chromeos)); | 429 DeviceRemoved(this, device_bluez)); |
| 442 return; | 430 return; |
| 443 } | 431 } |
| 444 } | 432 } |
| 445 } | 433 } |
| 446 | 434 |
| 447 void BluetoothAdapterChromeOS::DevicePropertyChanged( | 435 void BluetoothAdapterBlueZ::DevicePropertyChanged( |
| 448 const dbus::ObjectPath& object_path, | 436 const dbus::ObjectPath& object_path, |
| 449 const std::string& property_name) { | 437 const std::string& property_name) { |
| 450 BluetoothDeviceChromeOS* device_chromeos = GetDeviceWithPath(object_path); | 438 BluetoothDeviceBlueZ* device_bluez = GetDeviceWithPath(object_path); |
| 451 if (!device_chromeos) | 439 if (!device_bluez) |
| 452 return; | 440 return; |
| 453 | 441 |
| 454 bluez::BluetoothDeviceClient::Properties* properties = | 442 bluez::BluetoothDeviceClient::Properties* properties = |
| 455 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( | 443 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 456 object_path); | 444 object_path); |
| 457 | 445 |
| 458 if (property_name == properties->address.name()) { | 446 if (property_name == properties->address.name()) { |
| 459 for (DevicesMap::iterator iter = devices_.begin(); iter != devices_.end(); | 447 for (DevicesMap::iterator iter = devices_.begin(); iter != devices_.end(); |
| 460 ++iter) { | 448 ++iter) { |
| 461 if (iter->second->GetAddress() == device_chromeos->GetAddress()) { | 449 if (iter->second->GetAddress() == device_bluez->GetAddress()) { |
| 462 std::string old_address = iter->first; | 450 std::string old_address = iter->first; |
| 463 VLOG(1) << "Device changed address, old: " << old_address | 451 VLOG(1) << "Device changed address, old: " << old_address |
| 464 << " new: " << device_chromeos->GetAddress(); | 452 << " new: " << device_bluez->GetAddress(); |
| 465 scoped_ptr<BluetoothDevice> scoped_device = | 453 scoped_ptr<BluetoothDevice> scoped_device = |
| 466 devices_.take_and_erase(iter); | 454 devices_.take_and_erase(iter); |
| 467 ignore_result(scoped_device.release()); | 455 ignore_result(scoped_device.release()); |
| 468 | 456 |
| 469 DCHECK(devices_.find(device_chromeos->GetAddress()) == devices_.end()); | 457 DCHECK(devices_.find(device_bluez->GetAddress()) == devices_.end()); |
| 470 devices_.set(device_chromeos->GetAddress(), | 458 devices_.set(device_bluez->GetAddress(), |
| 471 scoped_ptr<BluetoothDevice>(device_chromeos)); | 459 scoped_ptr<BluetoothDevice>(device_bluez)); |
| 472 NotifyDeviceAddressChanged(device_chromeos, old_address); | 460 NotifyDeviceAddressChanged(device_bluez, old_address); |
| 473 break; | 461 break; |
| 474 } | 462 } |
| 475 } | 463 } |
| 476 } | 464 } |
| 477 | 465 |
| 478 if (property_name == properties->bluetooth_class.name() || | 466 if (property_name == properties->bluetooth_class.name() || |
| 479 property_name == properties->address.name() || | 467 property_name == properties->address.name() || |
| 480 property_name == properties->alias.name() || | 468 property_name == properties->alias.name() || |
| 481 property_name == properties->paired.name() || | 469 property_name == properties->paired.name() || |
| 482 property_name == properties->trusted.name() || | 470 property_name == properties->trusted.name() || |
| 483 property_name == properties->connected.name() || | 471 property_name == properties->connected.name() || |
| 484 property_name == properties->uuids.name() || | 472 property_name == properties->uuids.name() || |
| 485 property_name == properties->rssi.name() || | 473 property_name == properties->rssi.name() || |
| 486 property_name == properties->tx_power.name()) { | 474 property_name == properties->tx_power.name()) { |
| 487 NotifyDeviceChanged(device_chromeos); | 475 NotifyDeviceChanged(device_bluez); |
| 488 } | 476 } |
| 489 | 477 |
| 490 if (property_name == properties->gatt_services.name()) { | 478 if (property_name == properties->gatt_services.name()) { |
| 491 NotifyGattServicesDiscovered(device_chromeos); | 479 NotifyGattServicesDiscovered(device_bluez); |
| 492 } | 480 } |
| 493 | 481 |
| 494 // When a device becomes paired, mark it as trusted so that the user does | 482 // When a device becomes paired, mark it as trusted so that the user does |
| 495 // not need to approve every incoming connection | 483 // not need to approve every incoming connection |
| 496 if (property_name == properties->paired.name() && | 484 if (property_name == properties->paired.name() && |
| 497 properties->paired.value() && !properties->trusted.value()) { | 485 properties->paired.value() && !properties->trusted.value()) { |
| 498 device_chromeos->SetTrusted(); | 486 device_bluez->SetTrusted(); |
| 499 } | 487 } |
| 500 | 488 |
| 501 // UMA connection counting | 489 // UMA connection counting |
| 502 if (property_name == properties->connected.name()) { | 490 if (property_name == properties->connected.name()) { |
| 503 // PlayStation joystick tries to reconnect after disconnection from USB. | 491 // PlayStation joystick tries to reconnect after disconnection from USB. |
| 504 // If it is still not trusted, set it, so it becomes available on the | 492 // If it is still not trusted, set it, so it becomes available on the |
| 505 // list of known devices. | 493 // list of known devices. |
| 506 if (properties->connected.value() && device_chromeos->IsTrustable() && | 494 if (properties->connected.value() && device_bluez->IsTrustable() && |
| 507 !properties->trusted.value()) | 495 !properties->trusted.value()) |
| 508 device_chromeos->SetTrusted(); | 496 device_bluez->SetTrusted(); |
| 509 | 497 |
| 510 int count = 0; | 498 int count = 0; |
| 511 | 499 |
| 512 for (DevicesMap::const_iterator iter = devices_.begin(); | 500 for (DevicesMap::const_iterator iter = devices_.begin(); |
| 513 iter != devices_.end(); ++iter) { | 501 iter != devices_.end(); ++iter) { |
| 514 if (iter->second->IsPaired() && iter->second->IsConnected()) | 502 if (iter->second->IsPaired() && iter->second->IsConnected()) |
| 515 ++count; | 503 ++count; |
| 516 } | 504 } |
| 517 | 505 |
| 518 UMA_HISTOGRAM_COUNTS_100("Bluetooth.ConnectedDeviceCount", count); | 506 UMA_HISTOGRAM_COUNTS_100("Bluetooth.ConnectedDeviceCount", count); |
| 519 } | 507 } |
| 520 } | 508 } |
| 521 | 509 |
| 522 void BluetoothAdapterChromeOS::InputPropertyChanged( | 510 void BluetoothAdapterBlueZ::InputPropertyChanged( |
| 523 const dbus::ObjectPath& object_path, | 511 const dbus::ObjectPath& object_path, |
| 524 const std::string& property_name) { | 512 const std::string& property_name) { |
| 525 BluetoothDeviceChromeOS* device_chromeos = GetDeviceWithPath(object_path); | 513 BluetoothDeviceBlueZ* device_bluez = GetDeviceWithPath(object_path); |
| 526 if (!device_chromeos) | 514 if (!device_bluez) |
| 527 return; | 515 return; |
| 528 | 516 |
| 529 bluez::BluetoothInputClient::Properties* properties = | 517 bluez::BluetoothInputClient::Properties* properties = |
| 530 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->GetProperties( | 518 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->GetProperties( |
| 531 object_path); | 519 object_path); |
| 532 | 520 |
| 533 // Properties structure can be removed, which triggers a change in the | 521 // Properties structure can be removed, which triggers a change in the |
| 534 // BluetoothDevice::IsConnectable() property, as does a change in the | 522 // BluetoothDevice::IsConnectable() property, as does a change in the |
| 535 // actual reconnect_mode property. | 523 // actual reconnect_mode property. |
| 536 if (!properties || property_name == properties->reconnect_mode.name()) { | 524 if (!properties || property_name == properties->reconnect_mode.name()) { |
| 537 NotifyDeviceChanged(device_chromeos); | 525 NotifyDeviceChanged(device_bluez); |
| 538 } | 526 } |
| 539 } | 527 } |
| 540 | 528 |
| 541 void BluetoothAdapterChromeOS::Released() { | 529 void BluetoothAdapterBlueZ::Released() { |
| 542 VLOG(1) << "Release"; | 530 VLOG(1) << "Release"; |
| 543 if (!IsPresent()) | 531 if (!IsPresent()) |
| 544 return; | 532 return; |
| 545 DCHECK(agent_.get()); | 533 DCHECK(agent_.get()); |
| 546 | 534 |
| 547 // Called after we unregister the pairing agent, e.g. when changing I/O | 535 // Called after we unregister the pairing agent, e.g. when changing I/O |
| 548 // capabilities. Nothing much to be done right now. | 536 // capabilities. Nothing much to be done right now. |
| 549 } | 537 } |
| 550 | 538 |
| 551 void BluetoothAdapterChromeOS::RequestPinCode( | 539 void BluetoothAdapterBlueZ::RequestPinCode(const dbus::ObjectPath& device_path, |
| 552 const dbus::ObjectPath& device_path, | 540 const PinCodeCallback& callback) { |
| 553 const PinCodeCallback& callback) { | |
| 554 DCHECK(IsPresent()); | 541 DCHECK(IsPresent()); |
| 555 DCHECK(agent_.get()); | 542 DCHECK(agent_.get()); |
| 556 VLOG(1) << device_path.value() << ": RequestPinCode"; | 543 VLOG(1) << device_path.value() << ": RequestPinCode"; |
| 557 | 544 |
| 558 BluetoothPairingChromeOS* pairing = GetPairing(device_path); | 545 BluetoothPairingBlueZ* pairing = GetPairing(device_path); |
| 559 if (!pairing) { | 546 if (!pairing) { |
| 560 callback.Run(REJECTED, ""); | 547 callback.Run(REJECTED, ""); |
| 561 return; | 548 return; |
| 562 } | 549 } |
| 563 | 550 |
| 564 pairing->RequestPinCode(callback); | 551 pairing->RequestPinCode(callback); |
| 565 } | 552 } |
| 566 | 553 |
| 567 void BluetoothAdapterChromeOS::DisplayPinCode( | 554 void BluetoothAdapterBlueZ::DisplayPinCode(const dbus::ObjectPath& device_path, |
| 568 const dbus::ObjectPath& device_path, | 555 const std::string& pincode) { |
| 569 const std::string& pincode) { | |
| 570 DCHECK(IsPresent()); | 556 DCHECK(IsPresent()); |
| 571 DCHECK(agent_.get()); | 557 DCHECK(agent_.get()); |
| 572 VLOG(1) << device_path.value() << ": DisplayPinCode: " << pincode; | 558 VLOG(1) << device_path.value() << ": DisplayPinCode: " << pincode; |
| 573 | 559 |
| 574 BluetoothPairingChromeOS* pairing = GetPairing(device_path); | 560 BluetoothPairingBlueZ* pairing = GetPairing(device_path); |
| 575 if (!pairing) | 561 if (!pairing) |
| 576 return; | 562 return; |
| 577 | 563 |
| 578 pairing->DisplayPinCode(pincode); | 564 pairing->DisplayPinCode(pincode); |
| 579 } | 565 } |
| 580 | 566 |
| 581 void BluetoothAdapterChromeOS::RequestPasskey( | 567 void BluetoothAdapterBlueZ::RequestPasskey(const dbus::ObjectPath& device_path, |
| 582 const dbus::ObjectPath& device_path, | 568 const PasskeyCallback& callback) { |
| 583 const PasskeyCallback& callback) { | |
| 584 DCHECK(IsPresent()); | 569 DCHECK(IsPresent()); |
| 585 DCHECK(agent_.get()); | 570 DCHECK(agent_.get()); |
| 586 VLOG(1) << device_path.value() << ": RequestPasskey"; | 571 VLOG(1) << device_path.value() << ": RequestPasskey"; |
| 587 | 572 |
| 588 BluetoothPairingChromeOS* pairing = GetPairing(device_path); | 573 BluetoothPairingBlueZ* pairing = GetPairing(device_path); |
| 589 if (!pairing) { | 574 if (!pairing) { |
| 590 callback.Run(REJECTED, 0); | 575 callback.Run(REJECTED, 0); |
| 591 return; | 576 return; |
| 592 } | 577 } |
| 593 | 578 |
| 594 pairing->RequestPasskey(callback); | 579 pairing->RequestPasskey(callback); |
| 595 } | 580 } |
| 596 | 581 |
| 597 void BluetoothAdapterChromeOS::DisplayPasskey( | 582 void BluetoothAdapterBlueZ::DisplayPasskey(const dbus::ObjectPath& device_path, |
| 598 const dbus::ObjectPath& device_path, | 583 uint32 passkey, |
| 599 uint32 passkey, | 584 uint16 entered) { |
| 600 uint16 entered) { | |
| 601 DCHECK(IsPresent()); | 585 DCHECK(IsPresent()); |
| 602 DCHECK(agent_.get()); | 586 DCHECK(agent_.get()); |
| 603 VLOG(1) << device_path.value() << ": DisplayPasskey: " << passkey | 587 VLOG(1) << device_path.value() << ": DisplayPasskey: " << passkey << " (" |
| 604 << " (" << entered << " entered)"; | 588 << entered << " entered)"; |
| 605 | 589 |
| 606 BluetoothPairingChromeOS* pairing = GetPairing(device_path); | 590 BluetoothPairingBlueZ* pairing = GetPairing(device_path); |
| 607 if (!pairing) | 591 if (!pairing) |
| 608 return; | 592 return; |
| 609 | 593 |
| 610 if (entered == 0) | 594 if (entered == 0) |
| 611 pairing->DisplayPasskey(passkey); | 595 pairing->DisplayPasskey(passkey); |
| 612 | 596 |
| 613 pairing->KeysEntered(entered); | 597 pairing->KeysEntered(entered); |
| 614 } | 598 } |
| 615 | 599 |
| 616 void BluetoothAdapterChromeOS::RequestConfirmation( | 600 void BluetoothAdapterBlueZ::RequestConfirmation( |
| 617 const dbus::ObjectPath& device_path, | 601 const dbus::ObjectPath& device_path, |
| 618 uint32 passkey, | 602 uint32 passkey, |
| 619 const ConfirmationCallback& callback) { | 603 const ConfirmationCallback& callback) { |
| 620 DCHECK(IsPresent()); | 604 DCHECK(IsPresent()); |
| 621 DCHECK(agent_.get()); | 605 DCHECK(agent_.get()); |
| 622 VLOG(1) << device_path.value() << ": RequestConfirmation: " << passkey; | 606 VLOG(1) << device_path.value() << ": RequestConfirmation: " << passkey; |
| 623 | 607 |
| 624 BluetoothPairingChromeOS* pairing = GetPairing(device_path); | 608 BluetoothPairingBlueZ* pairing = GetPairing(device_path); |
| 625 if (!pairing) { | 609 if (!pairing) { |
| 626 callback.Run(REJECTED); | 610 callback.Run(REJECTED); |
| 627 return; | 611 return; |
| 628 } | 612 } |
| 629 | 613 |
| 630 pairing->RequestConfirmation(passkey, callback); | 614 pairing->RequestConfirmation(passkey, callback); |
| 631 } | 615 } |
| 632 | 616 |
| 633 void BluetoothAdapterChromeOS::RequestAuthorization( | 617 void BluetoothAdapterBlueZ::RequestAuthorization( |
| 634 const dbus::ObjectPath& device_path, | 618 const dbus::ObjectPath& device_path, |
| 635 const ConfirmationCallback& callback) { | 619 const ConfirmationCallback& callback) { |
| 636 DCHECK(IsPresent()); | 620 DCHECK(IsPresent()); |
| 637 DCHECK(agent_.get()); | 621 DCHECK(agent_.get()); |
| 638 VLOG(1) << device_path.value() << ": RequestAuthorization"; | 622 VLOG(1) << device_path.value() << ": RequestAuthorization"; |
| 639 | 623 |
| 640 BluetoothPairingChromeOS* pairing = GetPairing(device_path); | 624 BluetoothPairingBlueZ* pairing = GetPairing(device_path); |
| 641 if (!pairing) { | 625 if (!pairing) { |
| 642 callback.Run(REJECTED); | 626 callback.Run(REJECTED); |
| 643 return; | 627 return; |
| 644 } | 628 } |
| 645 | 629 |
| 646 pairing->RequestAuthorization(callback); | 630 pairing->RequestAuthorization(callback); |
| 647 } | 631 } |
| 648 | 632 |
| 649 void BluetoothAdapterChromeOS::AuthorizeService( | 633 void BluetoothAdapterBlueZ::AuthorizeService( |
| 650 const dbus::ObjectPath& device_path, | 634 const dbus::ObjectPath& device_path, |
| 651 const std::string& uuid, | 635 const std::string& uuid, |
| 652 const ConfirmationCallback& callback) { | 636 const ConfirmationCallback& callback) { |
| 653 DCHECK(IsPresent()); | 637 DCHECK(IsPresent()); |
| 654 DCHECK(agent_.get()); | 638 DCHECK(agent_.get()); |
| 655 VLOG(1) << device_path.value() << ": AuthorizeService: " << uuid; | 639 VLOG(1) << device_path.value() << ": AuthorizeService: " << uuid; |
| 656 | 640 |
| 657 BluetoothDeviceChromeOS* device_chromeos = GetDeviceWithPath(device_path); | 641 BluetoothDeviceBlueZ* device_bluez = GetDeviceWithPath(device_path); |
| 658 if (!device_chromeos) { | 642 if (!device_bluez) { |
| 659 callback.Run(CANCELLED); | 643 callback.Run(CANCELLED); |
| 660 return; | 644 return; |
| 661 } | 645 } |
| 662 | 646 |
| 663 // We always set paired devices to Trusted, so the only reason that this | 647 // We always set paired devices to Trusted, so the only reason that this |
| 664 // method call would ever be called is in the case of a race condition where | 648 // method call would ever be called is in the case of a race condition where |
| 665 // our "Set('Trusted', true)" method call is still pending in the Bluetooth | 649 // our "Set('Trusted', true)" method call is still pending in the Bluetooth |
| 666 // daemon because it's busy handling the incoming connection. | 650 // daemon because it's busy handling the incoming connection. |
| 667 if (device_chromeos->IsPaired()) { | 651 if (device_bluez->IsPaired()) { |
| 668 callback.Run(SUCCESS); | 652 callback.Run(SUCCESS); |
| 669 return; | 653 return; |
| 670 } | 654 } |
| 671 | 655 |
| 672 // TODO(keybuk): reject service authorizations when not paired, determine | 656 // TODO(keybuk): reject service authorizations when not paired, determine |
| 673 // whether this is acceptable long-term. | 657 // whether this is acceptable long-term. |
| 674 LOG(WARNING) << "Rejecting service connection from unpaired device " | 658 LOG(WARNING) << "Rejecting service connection from unpaired device " |
| 675 << device_chromeos->GetAddress() << " for UUID " << uuid; | 659 << device_bluez->GetAddress() << " for UUID " << uuid; |
| 676 callback.Run(REJECTED); | 660 callback.Run(REJECTED); |
| 677 } | 661 } |
| 678 | 662 |
| 679 void BluetoothAdapterChromeOS::Cancel() { | 663 void BluetoothAdapterBlueZ::Cancel() { |
| 680 DCHECK(IsPresent()); | 664 DCHECK(IsPresent()); |
| 681 DCHECK(agent_.get()); | 665 DCHECK(agent_.get()); |
| 682 VLOG(1) << "Cancel"; | 666 VLOG(1) << "Cancel"; |
| 683 } | 667 } |
| 684 | 668 |
| 685 void BluetoothAdapterChromeOS::OnRegisterAgent() { | 669 void BluetoothAdapterBlueZ::OnRegisterAgent() { |
| 686 VLOG(1) << "Pairing agent registered, requesting to be made default"; | 670 VLOG(1) << "Pairing agent registered, requesting to be made default"; |
| 687 | 671 |
| 688 bluez::BluezDBusManager::Get() | 672 bluez::BluezDBusManager::Get() |
| 689 ->GetBluetoothAgentManagerClient() | 673 ->GetBluetoothAgentManagerClient() |
| 690 ->RequestDefaultAgent( | 674 ->RequestDefaultAgent( |
| 691 dbus::ObjectPath(kAgentPath), | 675 dbus::ObjectPath(kAgentPath), |
| 692 base::Bind(&BluetoothAdapterChromeOS::OnRequestDefaultAgent, | 676 base::Bind(&BluetoothAdapterBlueZ::OnRequestDefaultAgent, |
| 693 weak_ptr_factory_.GetWeakPtr()), | 677 weak_ptr_factory_.GetWeakPtr()), |
| 694 base::Bind(&BluetoothAdapterChromeOS::OnRequestDefaultAgentError, | 678 base::Bind(&BluetoothAdapterBlueZ::OnRequestDefaultAgentError, |
| 695 weak_ptr_factory_.GetWeakPtr())); | 679 weak_ptr_factory_.GetWeakPtr())); |
| 696 } | 680 } |
| 697 | 681 |
| 698 void BluetoothAdapterChromeOS::OnRegisterAgentError( | 682 void BluetoothAdapterBlueZ::OnRegisterAgentError( |
| 699 const std::string& error_name, | 683 const std::string& error_name, |
| 700 const std::string& error_message) { | 684 const std::string& error_message) { |
| 701 // Our agent being already registered isn't an error. | 685 // Our agent being already registered isn't an error. |
| 702 if (error_name == bluetooth_agent_manager::kErrorAlreadyExists) | 686 if (error_name == bluetooth_agent_manager::kErrorAlreadyExists) |
| 703 return; | 687 return; |
| 704 | 688 |
| 705 LOG(WARNING) << ": Failed to register pairing agent: " | 689 LOG(WARNING) << ": Failed to register pairing agent: " << error_name << ": " |
| 706 << error_name << ": " << error_message; | 690 << error_message; |
| 707 } | 691 } |
| 708 | 692 |
| 709 void BluetoothAdapterChromeOS::OnRequestDefaultAgent() { | 693 void BluetoothAdapterBlueZ::OnRequestDefaultAgent() { |
| 710 VLOG(1) << "Pairing agent now default"; | 694 VLOG(1) << "Pairing agent now default"; |
| 711 } | 695 } |
| 712 | 696 |
| 713 void BluetoothAdapterChromeOS::OnRequestDefaultAgentError( | 697 void BluetoothAdapterBlueZ::OnRequestDefaultAgentError( |
| 714 const std::string& error_name, | 698 const std::string& error_name, |
| 715 const std::string& error_message) { | 699 const std::string& error_message) { |
| 716 LOG(WARNING) << ": Failed to make pairing agent default: " | 700 LOG(WARNING) << ": Failed to make pairing agent default: " << error_name |
| 717 << error_name << ": " << error_message; | 701 << ": " << error_message; |
| 718 } | 702 } |
| 719 | 703 |
| 720 void BluetoothAdapterChromeOS::OnRegisterAudioSink( | 704 void BluetoothAdapterBlueZ::OnRegisterAudioSink( |
| 721 const device::BluetoothAdapter::AcquiredCallback& callback, | 705 const device::BluetoothAdapter::AcquiredCallback& callback, |
| 722 const device::BluetoothAudioSink::ErrorCallback& error_callback, | 706 const device::BluetoothAudioSink::ErrorCallback& error_callback, |
| 723 scoped_refptr<BluetoothAudioSink> audio_sink) { | 707 scoped_refptr<BluetoothAudioSink> audio_sink) { |
| 724 if (!IsPresent()) { | 708 if (!IsPresent()) { |
| 725 VLOG(1) << "Failed to register audio sink, adapter not present"; | 709 VLOG(1) << "Failed to register audio sink, adapter not present"; |
| 726 error_callback.Run(BluetoothAudioSink::ERROR_INVALID_ADAPTER); | 710 error_callback.Run(BluetoothAudioSink::ERROR_INVALID_ADAPTER); |
| 727 return; | 711 return; |
| 728 } | 712 } |
| 729 DCHECK(audio_sink.get()); | 713 DCHECK(audio_sink.get()); |
| 730 callback.Run(audio_sink); | 714 callback.Run(audio_sink); |
| 731 } | 715 } |
| 732 | 716 |
| 733 BluetoothDeviceChromeOS* | 717 BluetoothDeviceBlueZ* BluetoothAdapterBlueZ::GetDeviceWithPath( |
| 734 BluetoothAdapterChromeOS::GetDeviceWithPath( | |
| 735 const dbus::ObjectPath& object_path) { | 718 const dbus::ObjectPath& object_path) { |
| 736 if (!IsPresent()) | 719 if (!IsPresent()) |
| 737 return nullptr; | 720 return nullptr; |
| 738 | 721 |
| 739 for (DevicesMap::const_iterator iter = devices_.begin(); | 722 for (DevicesMap::const_iterator iter = devices_.begin(); |
| 740 iter != devices_.end(); ++iter) { | 723 iter != devices_.end(); ++iter) { |
| 741 BluetoothDeviceChromeOS* device_chromeos = | 724 BluetoothDeviceBlueZ* device_bluez = |
| 742 static_cast<BluetoothDeviceChromeOS*>(iter->second); | 725 static_cast<BluetoothDeviceBlueZ*>(iter->second); |
| 743 if (device_chromeos->object_path() == object_path) | 726 if (device_bluez->object_path() == object_path) |
| 744 return device_chromeos; | 727 return device_bluez; |
| 745 } | 728 } |
| 746 | 729 |
| 747 return nullptr; | 730 return nullptr; |
| 748 } | 731 } |
| 749 | 732 |
| 750 BluetoothPairingChromeOS* BluetoothAdapterChromeOS::GetPairing( | 733 BluetoothPairingBlueZ* BluetoothAdapterBlueZ::GetPairing( |
| 751 const dbus::ObjectPath& object_path) { | 734 const dbus::ObjectPath& object_path) { |
| 752 DCHECK(IsPresent()); | 735 DCHECK(IsPresent()); |
| 753 BluetoothDeviceChromeOS* device_chromeos = GetDeviceWithPath(object_path); | 736 BluetoothDeviceBlueZ* device_bluez = GetDeviceWithPath(object_path); |
| 754 if (!device_chromeos) { | 737 if (!device_bluez) { |
| 755 LOG(WARNING) << "Pairing Agent request for unknown device: " | 738 LOG(WARNING) << "Pairing Agent request for unknown device: " |
| 756 << object_path.value(); | 739 << object_path.value(); |
| 757 return nullptr; | 740 return nullptr; |
| 758 } | 741 } |
| 759 | 742 |
| 760 BluetoothPairingChromeOS* pairing = device_chromeos->GetPairing(); | 743 BluetoothPairingBlueZ* pairing = device_bluez->GetPairing(); |
| 761 if (pairing) | 744 if (pairing) |
| 762 return pairing; | 745 return pairing; |
| 763 | 746 |
| 764 // The device doesn't have its own pairing context, so this is an incoming | 747 // The device doesn't have its own pairing context, so this is an incoming |
| 765 // pairing request that should use our best default delegate (if we have one). | 748 // pairing request that should use our best default delegate (if we have one). |
| 766 BluetoothDevice::PairingDelegate* pairing_delegate = DefaultPairingDelegate(); | 749 BluetoothDevice::PairingDelegate* pairing_delegate = DefaultPairingDelegate(); |
| 767 if (!pairing_delegate) | 750 if (!pairing_delegate) |
| 768 return nullptr; | 751 return nullptr; |
| 769 | 752 |
| 770 return device_chromeos->BeginPairing(pairing_delegate); | 753 return device_bluez->BeginPairing(pairing_delegate); |
| 771 } | 754 } |
| 772 | 755 |
| 773 void BluetoothAdapterChromeOS::SetAdapter(const dbus::ObjectPath& object_path) { | 756 void BluetoothAdapterBlueZ::SetAdapter(const dbus::ObjectPath& object_path) { |
| 774 DCHECK(!IsPresent()); | 757 DCHECK(!IsPresent()); |
| 775 DCHECK(!dbus_is_shutdown_); | 758 DCHECK(!dbus_is_shutdown_); |
| 776 object_path_ = object_path; | 759 object_path_ = object_path; |
| 777 | 760 |
| 778 VLOG(1) << object_path_.value() << ": using adapter."; | 761 VLOG(1) << object_path_.value() << ": using adapter."; |
| 779 | 762 |
| 780 VLOG(1) << "Registering pairing agent"; | 763 VLOG(1) << "Registering pairing agent"; |
| 781 bluez::BluezDBusManager::Get() | 764 bluez::BluezDBusManager::Get() |
| 782 ->GetBluetoothAgentManagerClient() | 765 ->GetBluetoothAgentManagerClient() |
| 783 ->RegisterAgent( | 766 ->RegisterAgent(dbus::ObjectPath(kAgentPath), |
| 784 dbus::ObjectPath(kAgentPath), | 767 bluetooth_agent_manager::kKeyboardDisplayCapability, |
| 785 bluetooth_agent_manager::kKeyboardDisplayCapability, | 768 base::Bind(&BluetoothAdapterBlueZ::OnRegisterAgent, |
| 786 base::Bind(&BluetoothAdapterChromeOS::OnRegisterAgent, | 769 weak_ptr_factory_.GetWeakPtr()), |
| 787 weak_ptr_factory_.GetWeakPtr()), | 770 base::Bind(&BluetoothAdapterBlueZ::OnRegisterAgentError, |
| 788 base::Bind(&BluetoothAdapterChromeOS::OnRegisterAgentError, | 771 weak_ptr_factory_.GetWeakPtr())); |
| 789 weak_ptr_factory_.GetWeakPtr())); | |
| 790 | 772 |
| 791 SetDefaultAdapterName(); | 773 SetDefaultAdapterName(); |
| 792 | 774 |
| 793 bluez::BluetoothAdapterClient::Properties* properties = | 775 bluez::BluetoothAdapterClient::Properties* properties = |
| 794 bluez::BluezDBusManager::Get() | 776 bluez::BluezDBusManager::Get() |
| 795 ->GetBluetoothAdapterClient() | 777 ->GetBluetoothAdapterClient() |
| 796 ->GetProperties(object_path_); | 778 ->GetProperties(object_path_); |
| 797 | 779 |
| 798 PresentChanged(true); | 780 PresentChanged(true); |
| 799 | 781 |
| 800 if (properties->powered.value()) | 782 if (properties->powered.value()) |
| 801 PoweredChanged(true); | 783 PoweredChanged(true); |
| 802 if (properties->discoverable.value()) | 784 if (properties->discoverable.value()) |
| 803 DiscoverableChanged(true); | 785 DiscoverableChanged(true); |
| 804 if (properties->discovering.value()) | 786 if (properties->discovering.value()) |
| 805 DiscoveringChanged(true); | 787 DiscoveringChanged(true); |
| 806 | 788 |
| 807 std::vector<dbus::ObjectPath> device_paths = | 789 std::vector<dbus::ObjectPath> device_paths = |
| 808 bluez::BluezDBusManager::Get() | 790 bluez::BluezDBusManager::Get() |
| 809 ->GetBluetoothDeviceClient() | 791 ->GetBluetoothDeviceClient() |
| 810 ->GetDevicesForAdapter(object_path_); | 792 ->GetDevicesForAdapter(object_path_); |
| 811 | 793 |
| 812 for (std::vector<dbus::ObjectPath>::iterator iter = device_paths.begin(); | 794 for (std::vector<dbus::ObjectPath>::iterator iter = device_paths.begin(); |
| 813 iter != device_paths.end(); ++iter) { | 795 iter != device_paths.end(); ++iter) { |
| 814 DeviceAdded(*iter); | 796 DeviceAdded(*iter); |
| 815 } | 797 } |
| 816 } | 798 } |
| 817 | 799 |
| 818 void BluetoothAdapterChromeOS::SetDefaultAdapterName() { | 800 void BluetoothAdapterBlueZ::SetDefaultAdapterName() { |
| 819 DCHECK(IsPresent()); | 801 DCHECK(IsPresent()); |
| 820 | 802 |
| 821 std::string alias; | 803 std::string alias; |
| 804 #if defined(OS_CHROMEOS) |
| 822 switch (chromeos::GetDeviceType()) { | 805 switch (chromeos::GetDeviceType()) { |
| 823 case DeviceType::kChromebase: | 806 case chromeos::DeviceType::kChromebase: |
| 824 alias = "Chromebase"; | 807 alias = "Chromebase"; |
| 825 break; | 808 break; |
| 826 case DeviceType::kChromebit: | 809 case chromeos::DeviceType::kChromebit: |
| 827 alias = "Chromebit"; | 810 alias = "Chromebit"; |
| 828 break; | 811 break; |
| 829 case DeviceType::kChromebook: | 812 case chromeos::DeviceType::kChromebook: |
| 830 alias = "Chromebook"; | 813 alias = "Chromebook"; |
| 831 break; | 814 break; |
| 832 case DeviceType::kChromebox: | 815 case chromeos::DeviceType::kChromebox: |
| 833 alias = "Chromebox"; | 816 alias = "Chromebox"; |
| 834 break; | 817 break; |
| 835 case DeviceType::kUnknown: | 818 case chromeos::DeviceType::kUnknown: |
| 836 alias = "Chromebook"; | 819 alias = "Chromebook"; |
| 837 break; | 820 break; |
| 838 } | 821 } |
| 822 #elif defined(OS_LINUX) |
| 823 alias = "ChromeLinux"; |
| 824 #endif |
| 839 | 825 |
| 840 SetName(alias, base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); | 826 SetName(alias, base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); |
| 841 } | 827 } |
| 842 | 828 |
| 843 void BluetoothAdapterChromeOS::RemoveAdapter() { | 829 void BluetoothAdapterBlueZ::RemoveAdapter() { |
| 844 DCHECK(IsPresent()); | 830 DCHECK(IsPresent()); |
| 845 VLOG(1) << object_path_.value() << ": adapter removed."; | 831 VLOG(1) << object_path_.value() << ": adapter removed."; |
| 846 | 832 |
| 847 bluez::BluetoothAdapterClient::Properties* properties = | 833 bluez::BluetoothAdapterClient::Properties* properties = |
| 848 bluez::BluezDBusManager::Get() | 834 bluez::BluezDBusManager::Get() |
| 849 ->GetBluetoothAdapterClient() | 835 ->GetBluetoothAdapterClient() |
| 850 ->GetProperties(object_path_); | 836 ->GetProperties(object_path_); |
| 851 | 837 |
| 852 object_path_ = dbus::ObjectPath(""); | 838 object_path_ = dbus::ObjectPath(""); |
| 853 | 839 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 865 devices_swapped.swap(devices_); | 851 devices_swapped.swap(devices_); |
| 866 | 852 |
| 867 for (auto& iter : devices_swapped) { | 853 for (auto& iter : devices_swapped) { |
| 868 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 854 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 869 DeviceRemoved(this, iter.second)); | 855 DeviceRemoved(this, iter.second)); |
| 870 } | 856 } |
| 871 | 857 |
| 872 PresentChanged(false); | 858 PresentChanged(false); |
| 873 } | 859 } |
| 874 | 860 |
| 875 void BluetoothAdapterChromeOS::PoweredChanged(bool powered) { | 861 void BluetoothAdapterBlueZ::PoweredChanged(bool powered) { |
| 876 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 862 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 877 AdapterPoweredChanged(this, powered)); | 863 AdapterPoweredChanged(this, powered)); |
| 878 } | 864 } |
| 879 | 865 |
| 880 void BluetoothAdapterChromeOS::DiscoverableChanged(bool discoverable) { | 866 void BluetoothAdapterBlueZ::DiscoverableChanged(bool discoverable) { |
| 881 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 867 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 882 AdapterDiscoverableChanged(this, discoverable)); | 868 AdapterDiscoverableChanged(this, discoverable)); |
| 883 } | 869 } |
| 884 | 870 |
| 885 void BluetoothAdapterChromeOS::DiscoveringChanged( | 871 void BluetoothAdapterBlueZ::DiscoveringChanged(bool discovering) { |
| 886 bool discovering) { | |
| 887 // If the adapter stopped discovery due to a reason other than a request by | 872 // If the adapter stopped discovery due to a reason other than a request by |
| 888 // us, reset the count to 0. | 873 // us, reset the count to 0. |
| 889 VLOG(1) << "Discovering changed: " << discovering; | 874 VLOG(1) << "Discovering changed: " << discovering; |
| 890 if (!discovering && !discovery_request_pending_ && | 875 if (!discovering && !discovery_request_pending_ && |
| 891 num_discovery_sessions_ > 0) { | 876 num_discovery_sessions_ > 0) { |
| 892 VLOG(1) << "Marking sessions as inactive."; | 877 VLOG(1) << "Marking sessions as inactive."; |
| 893 num_discovery_sessions_ = 0; | 878 num_discovery_sessions_ = 0; |
| 894 MarkDiscoverySessionsAsInactive(); | 879 MarkDiscoverySessionsAsInactive(); |
| 895 } | 880 } |
| 896 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 881 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 897 AdapterDiscoveringChanged(this, discovering)); | 882 AdapterDiscoveringChanged(this, discovering)); |
| 898 } | 883 } |
| 899 | 884 |
| 900 void BluetoothAdapterChromeOS::PresentChanged(bool present) { | 885 void BluetoothAdapterBlueZ::PresentChanged(bool present) { |
| 901 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 886 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 902 AdapterPresentChanged(this, present)); | 887 AdapterPresentChanged(this, present)); |
| 903 } | 888 } |
| 904 | 889 |
| 905 void BluetoothAdapterChromeOS::NotifyDeviceChanged( | 890 void BluetoothAdapterBlueZ::NotifyDeviceChanged(BluetoothDeviceBlueZ* device) { |
| 906 BluetoothDeviceChromeOS* device) { | |
| 907 DCHECK(device); | 891 DCHECK(device); |
| 908 DCHECK(device->adapter_ == this); | 892 DCHECK(device->adapter_ == this); |
| 909 | 893 |
| 910 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 894 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 911 DeviceChanged(this, device)); | 895 DeviceChanged(this, device)); |
| 912 } | 896 } |
| 913 | 897 |
| 914 void BluetoothAdapterChromeOS::NotifyDeviceAddressChanged( | 898 void BluetoothAdapterBlueZ::NotifyDeviceAddressChanged( |
| 915 BluetoothDeviceChromeOS* device, | 899 BluetoothDeviceBlueZ* device, |
| 916 const std::string& old_address) { | 900 const std::string& old_address) { |
| 917 DCHECK(device->adapter_ == this); | 901 DCHECK(device->adapter_ == this); |
| 918 | 902 |
| 919 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 903 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 920 DeviceAddressChanged(this, device, old_address)); | 904 DeviceAddressChanged(this, device, old_address)); |
| 921 } | 905 } |
| 922 | 906 |
| 923 void BluetoothAdapterChromeOS::NotifyGattServiceAdded( | 907 void BluetoothAdapterBlueZ::NotifyGattServiceAdded( |
| 924 BluetoothRemoteGattServiceChromeOS* service) { | 908 BluetoothRemoteGattServiceBlueZ* service) { |
| 925 DCHECK_EQ(service->GetAdapter(), this); | 909 DCHECK_EQ(service->GetAdapter(), this); |
| 926 DCHECK_EQ( | 910 DCHECK_EQ(static_cast<BluetoothDeviceBlueZ*>(service->GetDevice())->adapter_, |
| 927 static_cast<BluetoothDeviceChromeOS*>(service->GetDevice())->adapter_, | 911 this); |
| 928 this); | |
| 929 | 912 |
| 930 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 913 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 931 observers_, | |
| 932 GattServiceAdded(this, service->GetDevice(), service)); | 914 GattServiceAdded(this, service->GetDevice(), service)); |
| 933 } | 915 } |
| 934 | 916 |
| 935 void BluetoothAdapterChromeOS::NotifyGattServiceRemoved( | 917 void BluetoothAdapterBlueZ::NotifyGattServiceRemoved( |
| 936 BluetoothRemoteGattServiceChromeOS* service) { | 918 BluetoothRemoteGattServiceBlueZ* service) { |
| 937 DCHECK_EQ(service->GetAdapter(), this); | 919 DCHECK_EQ(service->GetAdapter(), this); |
| 938 DCHECK_EQ( | 920 DCHECK_EQ(static_cast<BluetoothDeviceBlueZ*>(service->GetDevice())->adapter_, |
| 939 static_cast<BluetoothDeviceChromeOS*>(service->GetDevice())->adapter_, | 921 this); |
| 940 this); | |
| 941 | 922 |
| 942 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 923 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 943 observers_, | |
| 944 GattServiceRemoved(this, service->GetDevice(), service)); | 924 GattServiceRemoved(this, service->GetDevice(), service)); |
| 945 } | 925 } |
| 946 | 926 |
| 947 void BluetoothAdapterChromeOS::NotifyGattServiceChanged( | 927 void BluetoothAdapterBlueZ::NotifyGattServiceChanged( |
| 948 BluetoothRemoteGattServiceChromeOS* service) { | 928 BluetoothRemoteGattServiceBlueZ* service) { |
| 949 DCHECK_EQ(service->GetAdapter(), this); | 929 DCHECK_EQ(service->GetAdapter(), this); |
| 950 | 930 |
| 951 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 931 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 952 observers_, | |
| 953 GattServiceChanged(this, service)); | 932 GattServiceChanged(this, service)); |
| 954 } | 933 } |
| 955 | 934 |
| 956 void BluetoothAdapterChromeOS::NotifyGattServicesDiscovered( | 935 void BluetoothAdapterBlueZ::NotifyGattServicesDiscovered( |
| 957 BluetoothDeviceChromeOS* device) { | 936 BluetoothDeviceBlueZ* device) { |
| 958 DCHECK(device->adapter_ == this); | 937 DCHECK(device->adapter_ == this); |
| 959 | 938 |
| 960 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | 939 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 961 GattServicesDiscovered(this, device)); | 940 GattServicesDiscovered(this, device)); |
| 962 } | 941 } |
| 963 | 942 |
| 964 void BluetoothAdapterChromeOS::NotifyGattDiscoveryComplete( | 943 void BluetoothAdapterBlueZ::NotifyGattDiscoveryComplete( |
| 965 BluetoothRemoteGattServiceChromeOS* service) { | 944 BluetoothRemoteGattServiceBlueZ* service) { |
| 966 DCHECK_EQ(service->GetAdapter(), this); | 945 DCHECK_EQ(service->GetAdapter(), this); |
| 967 | 946 |
| 968 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 947 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 969 observers_, | |
| 970 GattDiscoveryCompleteForService(this, service)); | 948 GattDiscoveryCompleteForService(this, service)); |
| 971 } | 949 } |
| 972 | 950 |
| 973 void BluetoothAdapterChromeOS::NotifyGattCharacteristicAdded( | 951 void BluetoothAdapterBlueZ::NotifyGattCharacteristicAdded( |
| 974 BluetoothRemoteGattCharacteristicChromeOS* characteristic) { | 952 BluetoothRemoteGattCharacteristicBlueZ* characteristic) { |
| 975 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>( | 953 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceBlueZ*>( |
| 976 characteristic->GetService())->GetAdapter(), | 954 characteristic->GetService()) |
| 955 ->GetAdapter(), |
| 977 this); | 956 this); |
| 978 | 957 |
| 979 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 958 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 980 observers_, | |
| 981 GattCharacteristicAdded(this, characteristic)); | 959 GattCharacteristicAdded(this, characteristic)); |
| 982 } | 960 } |
| 983 | 961 |
| 984 void BluetoothAdapterChromeOS::NotifyGattCharacteristicRemoved( | 962 void BluetoothAdapterBlueZ::NotifyGattCharacteristicRemoved( |
| 985 BluetoothRemoteGattCharacteristicChromeOS* characteristic) { | 963 BluetoothRemoteGattCharacteristicBlueZ* characteristic) { |
| 986 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>( | 964 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceBlueZ*>( |
| 987 characteristic->GetService())->GetAdapter(), | 965 characteristic->GetService()) |
| 966 ->GetAdapter(), |
| 988 this); | 967 this); |
| 989 | 968 |
| 990 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 969 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 991 observers_, | |
| 992 GattCharacteristicRemoved(this, characteristic)); | 970 GattCharacteristicRemoved(this, characteristic)); |
| 993 } | 971 } |
| 994 | 972 |
| 995 void BluetoothAdapterChromeOS::NotifyGattDescriptorAdded( | 973 void BluetoothAdapterBlueZ::NotifyGattDescriptorAdded( |
| 996 BluetoothRemoteGattDescriptorChromeOS* descriptor) { | 974 BluetoothRemoteGattDescriptorBlueZ* descriptor) { |
| 997 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>( | 975 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceBlueZ*>( |
| 998 descriptor->GetCharacteristic()->GetService())->GetAdapter(), | 976 descriptor->GetCharacteristic()->GetService()) |
| 977 ->GetAdapter(), |
| 999 this); | 978 this); |
| 1000 | 979 |
| 1001 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 980 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 1002 observers_, | |
| 1003 GattDescriptorAdded(this, descriptor)); | 981 GattDescriptorAdded(this, descriptor)); |
| 1004 } | 982 } |
| 1005 | 983 |
| 1006 void BluetoothAdapterChromeOS::NotifyGattDescriptorRemoved( | 984 void BluetoothAdapterBlueZ::NotifyGattDescriptorRemoved( |
| 1007 BluetoothRemoteGattDescriptorChromeOS* descriptor) { | 985 BluetoothRemoteGattDescriptorBlueZ* descriptor) { |
| 1008 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>( | 986 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceBlueZ*>( |
| 1009 descriptor->GetCharacteristic()->GetService())->GetAdapter(), | 987 descriptor->GetCharacteristic()->GetService()) |
| 988 ->GetAdapter(), |
| 1010 this); | 989 this); |
| 1011 | 990 |
| 1012 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 991 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 1013 observers_, | |
| 1014 GattDescriptorRemoved(this, descriptor)); | 992 GattDescriptorRemoved(this, descriptor)); |
| 1015 } | 993 } |
| 1016 | 994 |
| 1017 void BluetoothAdapterChromeOS::NotifyGattCharacteristicValueChanged( | 995 void BluetoothAdapterBlueZ::NotifyGattCharacteristicValueChanged( |
| 1018 BluetoothRemoteGattCharacteristicChromeOS* characteristic, | 996 BluetoothRemoteGattCharacteristicBlueZ* characteristic, |
| 1019 const std::vector<uint8>& value) { | 997 const std::vector<uint8>& value) { |
| 1020 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>( | 998 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceBlueZ*>( |
| 1021 characteristic->GetService())->GetAdapter(), | 999 characteristic->GetService()) |
| 1000 ->GetAdapter(), |
| 1022 this); | 1001 this); |
| 1023 | 1002 |
| 1024 FOR_EACH_OBSERVER( | 1003 FOR_EACH_OBSERVER( |
| 1025 BluetoothAdapter::Observer, | 1004 BluetoothAdapter::Observer, observers_, |
| 1026 observers_, | |
| 1027 GattCharacteristicValueChanged(this, characteristic, value)); | 1005 GattCharacteristicValueChanged(this, characteristic, value)); |
| 1028 } | 1006 } |
| 1029 | 1007 |
| 1030 void BluetoothAdapterChromeOS::NotifyGattDescriptorValueChanged( | 1008 void BluetoothAdapterBlueZ::NotifyGattDescriptorValueChanged( |
| 1031 BluetoothRemoteGattDescriptorChromeOS* descriptor, | 1009 BluetoothRemoteGattDescriptorBlueZ* descriptor, |
| 1032 const std::vector<uint8>& value) { | 1010 const std::vector<uint8>& value) { |
| 1033 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceChromeOS*>( | 1011 DCHECK_EQ(static_cast<BluetoothRemoteGattServiceBlueZ*>( |
| 1034 descriptor->GetCharacteristic()->GetService())->GetAdapter(), | 1012 descriptor->GetCharacteristic()->GetService()) |
| 1013 ->GetAdapter(), |
| 1035 this); | 1014 this); |
| 1036 | 1015 |
| 1037 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 1016 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
| 1038 observers_, | |
| 1039 GattDescriptorValueChanged(this, descriptor, value)); | 1017 GattDescriptorValueChanged(this, descriptor, value)); |
| 1040 } | 1018 } |
| 1041 | 1019 |
| 1042 void BluetoothAdapterChromeOS::UseProfile( | 1020 void BluetoothAdapterBlueZ::UseProfile( |
| 1043 const BluetoothUUID& uuid, | 1021 const BluetoothUUID& uuid, |
| 1044 const dbus::ObjectPath& device_path, | 1022 const dbus::ObjectPath& device_path, |
| 1045 const bluez::BluetoothProfileManagerClient::Options& options, | 1023 const bluez::BluetoothProfileManagerClient::Options& options, |
| 1046 bluez::BluetoothProfileServiceProvider::Delegate* delegate, | 1024 bluez::BluetoothProfileServiceProvider::Delegate* delegate, |
| 1047 const ProfileRegisteredCallback& success_callback, | 1025 const ProfileRegisteredCallback& success_callback, |
| 1048 const ErrorCompletionCallback& error_callback) { | 1026 const ErrorCompletionCallback& error_callback) { |
| 1049 DCHECK(delegate); | 1027 DCHECK(delegate); |
| 1050 | 1028 |
| 1051 if (!IsPresent()) { | 1029 if (!IsPresent()) { |
| 1052 VLOG(2) << "Adapter not present, erroring out"; | 1030 VLOG(2) << "Adapter not present, erroring out"; |
| 1053 error_callback.Run("Adapter not present"); | 1031 error_callback.Run("Adapter not present"); |
| 1054 return; | 1032 return; |
| 1055 } | 1033 } |
| 1056 | 1034 |
| 1057 if (profiles_.find(uuid) != profiles_.end()) { | 1035 if (profiles_.find(uuid) != profiles_.end()) { |
| 1058 // TODO(jamuraa) check that the options are the same and error when they are | 1036 // TODO(jamuraa) check that the options are the same and error when they are |
| 1059 // not. | 1037 // not. |
| 1060 SetProfileDelegate(uuid, device_path, delegate, success_callback, | 1038 SetProfileDelegate(uuid, device_path, delegate, success_callback, |
| 1061 error_callback); | 1039 error_callback); |
| 1062 return; | 1040 return; |
| 1063 } | 1041 } |
| 1064 | 1042 |
| 1065 if (profile_queues_.find(uuid) == profile_queues_.end()) { | 1043 if (profile_queues_.find(uuid) == profile_queues_.end()) { |
| 1066 BluetoothAdapterProfileChromeOS::Register( | 1044 BluetoothAdapterProfileBlueZ::Register( |
| 1067 uuid, options, | 1045 uuid, options, |
| 1068 base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfile, this, uuid), | 1046 base::Bind(&BluetoothAdapterBlueZ::OnRegisterProfile, this, uuid), |
| 1069 base::Bind(&BluetoothAdapterChromeOS::OnRegisterProfileError, this, | 1047 base::Bind(&BluetoothAdapterBlueZ::OnRegisterProfileError, this, uuid)); |
| 1070 uuid)); | |
| 1071 | 1048 |
| 1072 profile_queues_[uuid] = new std::vector<RegisterProfileCompletionPair>(); | 1049 profile_queues_[uuid] = new std::vector<RegisterProfileCompletionPair>(); |
| 1073 } | 1050 } |
| 1074 | 1051 |
| 1075 profile_queues_[uuid]->push_back(std::make_pair( | 1052 profile_queues_[uuid]->push_back(std::make_pair( |
| 1076 base::Bind(&BluetoothAdapterChromeOS::SetProfileDelegate, this, uuid, | 1053 base::Bind(&BluetoothAdapterBlueZ::SetProfileDelegate, this, uuid, |
| 1077 device_path, delegate, success_callback, error_callback), | 1054 device_path, delegate, success_callback, error_callback), |
| 1078 error_callback)); | 1055 error_callback)); |
| 1079 } | 1056 } |
| 1080 | 1057 |
| 1081 void BluetoothAdapterChromeOS::ReleaseProfile( | 1058 void BluetoothAdapterBlueZ::ReleaseProfile( |
| 1082 const dbus::ObjectPath& device_path, | 1059 const dbus::ObjectPath& device_path, |
| 1083 BluetoothAdapterProfileChromeOS* profile) { | 1060 BluetoothAdapterProfileBlueZ* profile) { |
| 1084 VLOG(2) << "Releasing Profile: " << profile->uuid().canonical_value() | 1061 VLOG(2) << "Releasing Profile: " << profile->uuid().canonical_value() |
| 1085 << " from " << device_path.value(); | 1062 << " from " << device_path.value(); |
| 1086 profile->RemoveDelegate( | 1063 profile->RemoveDelegate( |
| 1087 device_path, base::Bind(&BluetoothAdapterChromeOS::RemoveProfile, | 1064 device_path, base::Bind(&BluetoothAdapterBlueZ::RemoveProfile, |
| 1088 weak_ptr_factory_.GetWeakPtr(), profile->uuid())); | 1065 weak_ptr_factory_.GetWeakPtr(), profile->uuid())); |
| 1089 } | 1066 } |
| 1090 | 1067 |
| 1091 void BluetoothAdapterChromeOS::RemoveProfile(const BluetoothUUID& uuid) { | 1068 void BluetoothAdapterBlueZ::RemoveProfile(const BluetoothUUID& uuid) { |
| 1092 VLOG(2) << "Remove Profile: " << uuid.canonical_value(); | 1069 VLOG(2) << "Remove Profile: " << uuid.canonical_value(); |
| 1093 | 1070 |
| 1094 if (profiles_.find(uuid) != profiles_.end()) { | 1071 if (profiles_.find(uuid) != profiles_.end()) { |
| 1095 delete profiles_[uuid]; | 1072 delete profiles_[uuid]; |
| 1096 profiles_.erase(uuid); | 1073 profiles_.erase(uuid); |
| 1097 } | 1074 } |
| 1098 } | 1075 } |
| 1099 | 1076 |
| 1100 void BluetoothAdapterChromeOS::OnRegisterProfile( | 1077 void BluetoothAdapterBlueZ::OnRegisterProfile( |
| 1101 const BluetoothUUID& uuid, | 1078 const BluetoothUUID& uuid, |
| 1102 scoped_ptr<BluetoothAdapterProfileChromeOS> profile) { | 1079 scoped_ptr<BluetoothAdapterProfileBlueZ> profile) { |
| 1103 profiles_[uuid] = profile.release(); | 1080 profiles_[uuid] = profile.release(); |
| 1104 | 1081 |
| 1105 if (profile_queues_.find(uuid) == profile_queues_.end()) | 1082 if (profile_queues_.find(uuid) == profile_queues_.end()) |
| 1106 return; | 1083 return; |
| 1107 | 1084 |
| 1108 for (auto& it : *profile_queues_[uuid]) | 1085 for (auto& it : *profile_queues_[uuid]) |
| 1109 it.first.Run(); | 1086 it.first.Run(); |
| 1110 delete profile_queues_[uuid]; | 1087 delete profile_queues_[uuid]; |
| 1111 profile_queues_.erase(uuid); | 1088 profile_queues_.erase(uuid); |
| 1112 } | 1089 } |
| 1113 | 1090 |
| 1114 void BluetoothAdapterChromeOS::SetProfileDelegate( | 1091 void BluetoothAdapterBlueZ::SetProfileDelegate( |
| 1115 const BluetoothUUID& uuid, | 1092 const BluetoothUUID& uuid, |
| 1116 const dbus::ObjectPath& device_path, | 1093 const dbus::ObjectPath& device_path, |
| 1117 bluez::BluetoothProfileServiceProvider::Delegate* delegate, | 1094 bluez::BluetoothProfileServiceProvider::Delegate* delegate, |
| 1118 const ProfileRegisteredCallback& success_callback, | 1095 const ProfileRegisteredCallback& success_callback, |
| 1119 const ErrorCompletionCallback& error_callback) { | 1096 const ErrorCompletionCallback& error_callback) { |
| 1120 if (profiles_.find(uuid) == profiles_.end()) { | 1097 if (profiles_.find(uuid) == profiles_.end()) { |
| 1121 error_callback.Run("Cannot find profile!"); | 1098 error_callback.Run("Cannot find profile!"); |
| 1122 return; | 1099 return; |
| 1123 } | 1100 } |
| 1124 | 1101 |
| 1125 if (profiles_[uuid]->SetDelegate(device_path, delegate)) { | 1102 if (profiles_[uuid]->SetDelegate(device_path, delegate)) { |
| 1126 success_callback.Run(profiles_[uuid]); | 1103 success_callback.Run(profiles_[uuid]); |
| 1127 return; | 1104 return; |
| 1128 } | 1105 } |
| 1129 // Already set | 1106 // Already set |
| 1130 error_callback.Run(bluetooth_agent_manager::kErrorAlreadyExists); | 1107 error_callback.Run(bluetooth_agent_manager::kErrorAlreadyExists); |
| 1131 } | 1108 } |
| 1132 | 1109 |
| 1133 void BluetoothAdapterChromeOS::OnRegisterProfileError( | 1110 void BluetoothAdapterBlueZ::OnRegisterProfileError( |
| 1134 const BluetoothUUID& uuid, | 1111 const BluetoothUUID& uuid, |
| 1135 const std::string& error_name, | 1112 const std::string& error_name, |
| 1136 const std::string& error_message) { | 1113 const std::string& error_message) { |
| 1137 VLOG(2) << object_path_.value() << ": Failed to register profile: " | 1114 VLOG(2) << object_path_.value() |
| 1138 << error_name << ": " << error_message; | 1115 << ": Failed to register profile: " << error_name << ": " |
| 1116 << error_message; |
| 1139 if (profile_queues_.find(uuid) == profile_queues_.end()) | 1117 if (profile_queues_.find(uuid) == profile_queues_.end()) |
| 1140 return; | 1118 return; |
| 1141 | 1119 |
| 1142 for (auto& it : *profile_queues_[uuid]) | 1120 for (auto& it : *profile_queues_[uuid]) |
| 1143 it.second.Run(error_message); | 1121 it.second.Run(error_message); |
| 1144 | 1122 |
| 1145 delete profile_queues_[uuid]; | 1123 delete profile_queues_[uuid]; |
| 1146 profile_queues_.erase(uuid); | 1124 profile_queues_.erase(uuid); |
| 1147 } | 1125 } |
| 1148 | 1126 |
| 1149 void BluetoothAdapterChromeOS::OnSetDiscoverable( | 1127 void BluetoothAdapterBlueZ::OnSetDiscoverable( |
| 1150 const base::Closure& callback, | 1128 const base::Closure& callback, |
| 1151 const ErrorCallback& error_callback, | 1129 const ErrorCallback& error_callback, |
| 1152 bool success) { | 1130 bool success) { |
| 1153 if (!IsPresent()) { | 1131 if (!IsPresent()) { |
| 1154 error_callback.Run(); | 1132 error_callback.Run(); |
| 1155 return; | 1133 return; |
| 1156 } | 1134 } |
| 1157 | 1135 |
| 1158 // Set the discoverable_timeout property to zero so the adapter remains | 1136 // Set the discoverable_timeout property to zero so the adapter remains |
| 1159 // discoverable forever. | 1137 // discoverable forever. |
| 1160 bluez::BluezDBusManager::Get() | 1138 bluez::BluezDBusManager::Get() |
| 1161 ->GetBluetoothAdapterClient() | 1139 ->GetBluetoothAdapterClient() |
| 1162 ->GetProperties(object_path_) | 1140 ->GetProperties(object_path_) |
| 1163 ->discoverable_timeout.Set( | 1141 ->discoverable_timeout.Set( |
| 1164 0, | 1142 0, |
| 1165 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, | 1143 base::Bind(&BluetoothAdapterBlueZ::OnPropertyChangeCompleted, |
| 1166 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1144 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 1167 } | 1145 } |
| 1168 | 1146 |
| 1169 void BluetoothAdapterChromeOS::OnPropertyChangeCompleted( | 1147 void BluetoothAdapterBlueZ::OnPropertyChangeCompleted( |
| 1170 const base::Closure& callback, | 1148 const base::Closure& callback, |
| 1171 const ErrorCallback& error_callback, | 1149 const ErrorCallback& error_callback, |
| 1172 bool success) { | 1150 bool success) { |
| 1173 if (IsPresent() && success) { | 1151 if (IsPresent() && success) { |
| 1174 callback.Run(); | 1152 callback.Run(); |
| 1175 } else { | 1153 } else { |
| 1176 error_callback.Run(); | 1154 error_callback.Run(); |
| 1177 } | 1155 } |
| 1178 } | 1156 } |
| 1179 | 1157 |
| 1180 void BluetoothAdapterChromeOS::AddDiscoverySession( | 1158 void BluetoothAdapterBlueZ::AddDiscoverySession( |
| 1181 BluetoothDiscoveryFilter* discovery_filter, | 1159 BluetoothDiscoveryFilter* discovery_filter, |
| 1182 const base::Closure& callback, | 1160 const base::Closure& callback, |
| 1183 const DiscoverySessionErrorCallback& error_callback) { | 1161 const DiscoverySessionErrorCallback& error_callback) { |
| 1184 if (!IsPresent()) { | 1162 if (!IsPresent()) { |
| 1185 error_callback.Run( | 1163 error_callback.Run( |
| 1186 UMABluetoothDiscoverySessionOutcome::ADAPTER_NOT_PRESENT); | 1164 UMABluetoothDiscoverySessionOutcome::ADAPTER_NOT_PRESENT); |
| 1187 return; | 1165 return; |
| 1188 } | 1166 } |
| 1189 VLOG(1) << __func__; | 1167 VLOG(1) << __func__; |
| 1190 if (discovery_request_pending_) { | 1168 if (discovery_request_pending_) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1213 DCHECK_EQ(num_discovery_sessions_, 0); | 1191 DCHECK_EQ(num_discovery_sessions_, 0); |
| 1214 | 1192 |
| 1215 if (discovery_filter) { | 1193 if (discovery_filter) { |
| 1216 discovery_request_pending_ = true; | 1194 discovery_request_pending_ = true; |
| 1217 | 1195 |
| 1218 scoped_ptr<BluetoothDiscoveryFilter> df(new BluetoothDiscoveryFilter( | 1196 scoped_ptr<BluetoothDiscoveryFilter> df(new BluetoothDiscoveryFilter( |
| 1219 BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL)); | 1197 BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL)); |
| 1220 df->CopyFrom(*discovery_filter); | 1198 df->CopyFrom(*discovery_filter); |
| 1221 SetDiscoveryFilter( | 1199 SetDiscoveryFilter( |
| 1222 df.Pass(), | 1200 df.Pass(), |
| 1223 base::Bind(&BluetoothAdapterChromeOS::OnPreSetDiscoveryFilter, | 1201 base::Bind(&BluetoothAdapterBlueZ::OnPreSetDiscoveryFilter, |
| 1224 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 1202 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
| 1225 base::Bind(&BluetoothAdapterChromeOS::OnPreSetDiscoveryFilterError, | 1203 base::Bind(&BluetoothAdapterBlueZ::OnPreSetDiscoveryFilterError, |
| 1226 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1204 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 1227 return; | 1205 return; |
| 1228 } else { | 1206 } else { |
| 1229 current_filter_.reset(); | 1207 current_filter_.reset(); |
| 1230 } | 1208 } |
| 1231 | 1209 |
| 1232 // This is the first request to start device discovery. | 1210 // This is the first request to start device discovery. |
| 1233 discovery_request_pending_ = true; | 1211 discovery_request_pending_ = true; |
| 1234 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StartDiscovery( | 1212 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StartDiscovery( |
| 1235 object_path_, | 1213 object_path_, |
| 1236 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscovery, | 1214 base::Bind(&BluetoothAdapterBlueZ::OnStartDiscovery, |
| 1237 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 1215 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
| 1238 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscoveryError, | 1216 base::Bind(&BluetoothAdapterBlueZ::OnStartDiscoveryError, |
| 1239 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1217 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 1240 } | 1218 } |
| 1241 | 1219 |
| 1242 void BluetoothAdapterChromeOS::RemoveDiscoverySession( | 1220 void BluetoothAdapterBlueZ::RemoveDiscoverySession( |
| 1243 BluetoothDiscoveryFilter* discovery_filter, | 1221 BluetoothDiscoveryFilter* discovery_filter, |
| 1244 const base::Closure& callback, | 1222 const base::Closure& callback, |
| 1245 const DiscoverySessionErrorCallback& error_callback) { | 1223 const DiscoverySessionErrorCallback& error_callback) { |
| 1246 if (!IsPresent()) { | 1224 if (!IsPresent()) { |
| 1247 error_callback.Run( | 1225 error_callback.Run( |
| 1248 UMABluetoothDiscoverySessionOutcome::ADAPTER_NOT_PRESENT); | 1226 UMABluetoothDiscoverySessionOutcome::ADAPTER_NOT_PRESENT); |
| 1249 return; | 1227 return; |
| 1250 } | 1228 } |
| 1251 | 1229 |
| 1252 VLOG(1) << __func__; | 1230 VLOG(1) << __func__; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1279 error_callback.Run( | 1257 error_callback.Run( |
| 1280 UMABluetoothDiscoverySessionOutcome::ACTIVE_SESSION_NOT_IN_ADAPTER); | 1258 UMABluetoothDiscoverySessionOutcome::ACTIVE_SESSION_NOT_IN_ADAPTER); |
| 1281 return; | 1259 return; |
| 1282 } | 1260 } |
| 1283 | 1261 |
| 1284 // There is exactly one active discovery session. Request BlueZ to stop | 1262 // There is exactly one active discovery session. Request BlueZ to stop |
| 1285 // discovery. | 1263 // discovery. |
| 1286 DCHECK_EQ(num_discovery_sessions_, 1); | 1264 DCHECK_EQ(num_discovery_sessions_, 1); |
| 1287 discovery_request_pending_ = true; | 1265 discovery_request_pending_ = true; |
| 1288 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StopDiscovery( | 1266 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StopDiscovery( |
| 1289 object_path_, base::Bind(&BluetoothAdapterChromeOS::OnStopDiscovery, | 1267 object_path_, base::Bind(&BluetoothAdapterBlueZ::OnStopDiscovery, |
| 1290 weak_ptr_factory_.GetWeakPtr(), callback), | 1268 weak_ptr_factory_.GetWeakPtr(), callback), |
| 1291 base::Bind(&BluetoothAdapterChromeOS::OnStopDiscoveryError, | 1269 base::Bind(&BluetoothAdapterBlueZ::OnStopDiscoveryError, |
| 1292 weak_ptr_factory_.GetWeakPtr(), error_callback)); | 1270 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 1293 } | 1271 } |
| 1294 | 1272 |
| 1295 void BluetoothAdapterChromeOS::SetDiscoveryFilter( | 1273 void BluetoothAdapterBlueZ::SetDiscoveryFilter( |
| 1296 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 1274 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, |
| 1297 const base::Closure& callback, | 1275 const base::Closure& callback, |
| 1298 const DiscoverySessionErrorCallback& error_callback) { | 1276 const DiscoverySessionErrorCallback& error_callback) { |
| 1299 if (!IsPresent()) { | 1277 if (!IsPresent()) { |
| 1300 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); | 1278 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); |
| 1301 return; | 1279 return; |
| 1302 } | 1280 } |
| 1303 | 1281 |
| 1304 // If old and new filter are equal (null) then don't make request, just call | 1282 // If old and new filter are equal (null) then don't make request, just call |
| 1305 // succes callback | 1283 // succes callback |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 | 1328 |
| 1351 for (const auto& it : uuids) | 1329 for (const auto& it : uuids) |
| 1352 dbus_discovery_filter.uuids.get()->push_back(it.value()); | 1330 dbus_discovery_filter.uuids.get()->push_back(it.value()); |
| 1353 } | 1331 } |
| 1354 } | 1332 } |
| 1355 | 1333 |
| 1356 bluez::BluezDBusManager::Get() | 1334 bluez::BluezDBusManager::Get() |
| 1357 ->GetBluetoothAdapterClient() | 1335 ->GetBluetoothAdapterClient() |
| 1358 ->SetDiscoveryFilter( | 1336 ->SetDiscoveryFilter( |
| 1359 object_path_, dbus_discovery_filter, | 1337 object_path_, dbus_discovery_filter, |
| 1360 base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoveryFilter, | 1338 base::Bind(&BluetoothAdapterBlueZ::OnSetDiscoveryFilter, |
| 1361 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 1339 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
| 1362 base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoveryFilterError, | 1340 base::Bind(&BluetoothAdapterBlueZ::OnSetDiscoveryFilterError, |
| 1363 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1341 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 1364 } | 1342 } |
| 1365 | 1343 |
| 1366 void BluetoothAdapterChromeOS::OnStartDiscovery( | 1344 void BluetoothAdapterBlueZ::OnStartDiscovery( |
| 1367 const base::Closure& callback, | 1345 const base::Closure& callback, |
| 1368 const DiscoverySessionErrorCallback& error_callback) { | 1346 const DiscoverySessionErrorCallback& error_callback) { |
| 1369 // Report success on the original request and increment the count. | 1347 // Report success on the original request and increment the count. |
| 1370 VLOG(1) << __func__; | 1348 VLOG(1) << __func__; |
| 1371 DCHECK(discovery_request_pending_); | 1349 DCHECK(discovery_request_pending_); |
| 1372 DCHECK_EQ(num_discovery_sessions_, 0); | 1350 DCHECK_EQ(num_discovery_sessions_, 0); |
| 1373 discovery_request_pending_ = false; | 1351 discovery_request_pending_ = false; |
| 1374 num_discovery_sessions_++; | 1352 num_discovery_sessions_++; |
| 1375 if (IsPresent()) { | 1353 if (IsPresent()) { |
| 1376 callback.Run(); | 1354 callback.Run(); |
| 1377 } else { | 1355 } else { |
| 1378 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); | 1356 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); |
| 1379 } | 1357 } |
| 1380 | 1358 |
| 1381 // Try to add a new discovery session for each queued request. | 1359 // Try to add a new discovery session for each queued request. |
| 1382 ProcessQueuedDiscoveryRequests(); | 1360 ProcessQueuedDiscoveryRequests(); |
| 1383 } | 1361 } |
| 1384 | 1362 |
| 1385 void BluetoothAdapterChromeOS::OnStartDiscoveryError( | 1363 void BluetoothAdapterBlueZ::OnStartDiscoveryError( |
| 1386 const base::Closure& callback, | 1364 const base::Closure& callback, |
| 1387 const DiscoverySessionErrorCallback& error_callback, | 1365 const DiscoverySessionErrorCallback& error_callback, |
| 1388 const std::string& error_name, | 1366 const std::string& error_name, |
| 1389 const std::string& error_message) { | 1367 const std::string& error_message) { |
| 1390 LOG(WARNING) << object_path_.value() << ": Failed to start discovery: " | 1368 LOG(WARNING) << object_path_.value() |
| 1391 << error_name << ": " << error_message; | 1369 << ": Failed to start discovery: " << error_name << ": " |
| 1370 << error_message; |
| 1392 | 1371 |
| 1393 // Failed to start discovery. This can only happen if the count is at 0. | 1372 // Failed to start discovery. This can only happen if the count is at 0. |
| 1394 DCHECK_EQ(num_discovery_sessions_, 0); | 1373 DCHECK_EQ(num_discovery_sessions_, 0); |
| 1395 DCHECK(discovery_request_pending_); | 1374 DCHECK(discovery_request_pending_); |
| 1396 discovery_request_pending_ = false; | 1375 discovery_request_pending_ = false; |
| 1397 | 1376 |
| 1398 // Discovery request may fail if discovery was previously initiated by Chrome, | 1377 // Discovery request may fail if discovery was previously initiated by Chrome, |
| 1399 // but the session were invalidated due to the discovery state unexpectedly | 1378 // but the session were invalidated due to the discovery state unexpectedly |
| 1400 // changing to false and then back to true. In this case, report success. | 1379 // changing to false and then back to true. In this case, report success. |
| 1401 if (IsPresent() && error_name == bluetooth_device::kErrorInProgress && | 1380 if (IsPresent() && error_name == bluetooth_device::kErrorInProgress && |
| 1402 IsDiscovering()) { | 1381 IsDiscovering()) { |
| 1403 VLOG(1) << "Discovery previously initiated. Reporting success."; | 1382 VLOG(1) << "Discovery previously initiated. Reporting success."; |
| 1404 num_discovery_sessions_++; | 1383 num_discovery_sessions_++; |
| 1405 callback.Run(); | 1384 callback.Run(); |
| 1406 } else { | 1385 } else { |
| 1407 error_callback.Run(TranslateDiscoveryErrorToUMA(error_name)); | 1386 error_callback.Run(TranslateDiscoveryErrorToUMA(error_name)); |
| 1408 } | 1387 } |
| 1409 | 1388 |
| 1410 // Try to add a new discovery session for each queued request. | 1389 // Try to add a new discovery session for each queued request. |
| 1411 ProcessQueuedDiscoveryRequests(); | 1390 ProcessQueuedDiscoveryRequests(); |
| 1412 } | 1391 } |
| 1413 | 1392 |
| 1414 void BluetoothAdapterChromeOS::OnStopDiscovery(const base::Closure& callback) { | 1393 void BluetoothAdapterBlueZ::OnStopDiscovery(const base::Closure& callback) { |
| 1415 // Report success on the original request and decrement the count. | 1394 // Report success on the original request and decrement the count. |
| 1416 VLOG(1) << __func__; | 1395 VLOG(1) << __func__; |
| 1417 DCHECK(discovery_request_pending_); | 1396 DCHECK(discovery_request_pending_); |
| 1418 DCHECK_EQ(num_discovery_sessions_, 1); | 1397 DCHECK_EQ(num_discovery_sessions_, 1); |
| 1419 discovery_request_pending_ = false; | 1398 discovery_request_pending_ = false; |
| 1420 num_discovery_sessions_--; | 1399 num_discovery_sessions_--; |
| 1421 callback.Run(); | 1400 callback.Run(); |
| 1422 | 1401 |
| 1423 current_filter_.reset(); | 1402 current_filter_.reset(); |
| 1424 | 1403 |
| 1425 // Try to add a new discovery session for each queued request. | 1404 // Try to add a new discovery session for each queued request. |
| 1426 ProcessQueuedDiscoveryRequests(); | 1405 ProcessQueuedDiscoveryRequests(); |
| 1427 } | 1406 } |
| 1428 | 1407 |
| 1429 void BluetoothAdapterChromeOS::OnStopDiscoveryError( | 1408 void BluetoothAdapterBlueZ::OnStopDiscoveryError( |
| 1430 const DiscoverySessionErrorCallback& error_callback, | 1409 const DiscoverySessionErrorCallback& error_callback, |
| 1431 const std::string& error_name, | 1410 const std::string& error_name, |
| 1432 const std::string& error_message) { | 1411 const std::string& error_message) { |
| 1433 LOG(WARNING) << object_path_.value() << ": Failed to stop discovery: " | 1412 LOG(WARNING) << object_path_.value() |
| 1434 << error_name << ": " << error_message; | 1413 << ": Failed to stop discovery: " << error_name << ": " |
| 1414 << error_message; |
| 1435 | 1415 |
| 1436 // Failed to stop discovery. This can only happen if the count is at 1. | 1416 // Failed to stop discovery. This can only happen if the count is at 1. |
| 1437 DCHECK(discovery_request_pending_); | 1417 DCHECK(discovery_request_pending_); |
| 1438 DCHECK_EQ(num_discovery_sessions_, 1); | 1418 DCHECK_EQ(num_discovery_sessions_, 1); |
| 1439 discovery_request_pending_ = false; | 1419 discovery_request_pending_ = false; |
| 1440 error_callback.Run(TranslateDiscoveryErrorToUMA(error_name)); | 1420 error_callback.Run(TranslateDiscoveryErrorToUMA(error_name)); |
| 1441 | 1421 |
| 1442 // Try to add a new discovery session for each queued request. | 1422 // Try to add a new discovery session for each queued request. |
| 1443 ProcessQueuedDiscoveryRequests(); | 1423 ProcessQueuedDiscoveryRequests(); |
| 1444 } | 1424 } |
| 1445 | 1425 |
| 1446 void BluetoothAdapterChromeOS::OnPreSetDiscoveryFilter( | 1426 void BluetoothAdapterBlueZ::OnPreSetDiscoveryFilter( |
| 1447 const base::Closure& callback, | 1427 const base::Closure& callback, |
| 1448 const DiscoverySessionErrorCallback& error_callback) { | 1428 const DiscoverySessionErrorCallback& error_callback) { |
| 1449 // This is the first request to start device discovery. | 1429 // This is the first request to start device discovery. |
| 1450 DCHECK(discovery_request_pending_); | 1430 DCHECK(discovery_request_pending_); |
| 1451 DCHECK_EQ(num_discovery_sessions_, 0); | 1431 DCHECK_EQ(num_discovery_sessions_, 0); |
| 1452 | 1432 |
| 1453 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StartDiscovery( | 1433 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StartDiscovery( |
| 1454 object_path_, | 1434 object_path_, |
| 1455 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscovery, | 1435 base::Bind(&BluetoothAdapterBlueZ::OnStartDiscovery, |
| 1456 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 1436 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
| 1457 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscoveryError, | 1437 base::Bind(&BluetoothAdapterBlueZ::OnStartDiscoveryError, |
| 1458 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1438 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 1459 } | 1439 } |
| 1460 | 1440 |
| 1461 void BluetoothAdapterChromeOS::OnPreSetDiscoveryFilterError( | 1441 void BluetoothAdapterBlueZ::OnPreSetDiscoveryFilterError( |
| 1462 const base::Closure& callback, | 1442 const base::Closure& callback, |
| 1463 const DiscoverySessionErrorCallback& error_callback, | 1443 const DiscoverySessionErrorCallback& error_callback, |
| 1464 UMABluetoothDiscoverySessionOutcome outcome) { | 1444 UMABluetoothDiscoverySessionOutcome outcome) { |
| 1465 LOG(WARNING) << object_path_.value() | 1445 LOG(WARNING) << object_path_.value() |
| 1466 << ": Failed to pre set discovery filter."; | 1446 << ": Failed to pre set discovery filter."; |
| 1467 | 1447 |
| 1468 // Failed to start discovery. This can only happen if the count is at 0. | 1448 // Failed to start discovery. This can only happen if the count is at 0. |
| 1469 DCHECK_EQ(num_discovery_sessions_, 0); | 1449 DCHECK_EQ(num_discovery_sessions_, 0); |
| 1470 DCHECK(discovery_request_pending_); | 1450 DCHECK(discovery_request_pending_); |
| 1471 discovery_request_pending_ = false; | 1451 discovery_request_pending_ = false; |
| 1472 | 1452 |
| 1473 error_callback.Run(outcome); | 1453 error_callback.Run(outcome); |
| 1474 | 1454 |
| 1475 // Try to add a new discovery session for each queued request. | 1455 // Try to add a new discovery session for each queued request. |
| 1476 ProcessQueuedDiscoveryRequests(); | 1456 ProcessQueuedDiscoveryRequests(); |
| 1477 } | 1457 } |
| 1478 | 1458 |
| 1479 void BluetoothAdapterChromeOS::OnSetDiscoveryFilter( | 1459 void BluetoothAdapterBlueZ::OnSetDiscoveryFilter( |
| 1480 const base::Closure& callback, | 1460 const base::Closure& callback, |
| 1481 const DiscoverySessionErrorCallback& error_callback) { | 1461 const DiscoverySessionErrorCallback& error_callback) { |
| 1482 // Report success on the original request and increment the count. | 1462 // Report success on the original request and increment the count. |
| 1483 VLOG(1) << __func__; | 1463 VLOG(1) << __func__; |
| 1484 if (IsPresent()) { | 1464 if (IsPresent()) { |
| 1485 callback.Run(); | 1465 callback.Run(); |
| 1486 } else { | 1466 } else { |
| 1487 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); | 1467 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); |
| 1488 } | 1468 } |
| 1489 } | 1469 } |
| 1490 | 1470 |
| 1491 void BluetoothAdapterChromeOS::OnSetDiscoveryFilterError( | 1471 void BluetoothAdapterBlueZ::OnSetDiscoveryFilterError( |
| 1492 const base::Closure& callback, | 1472 const base::Closure& callback, |
| 1493 const DiscoverySessionErrorCallback& error_callback, | 1473 const DiscoverySessionErrorCallback& error_callback, |
| 1494 const std::string& error_name, | 1474 const std::string& error_name, |
| 1495 const std::string& error_message) { | 1475 const std::string& error_message) { |
| 1496 LOG(WARNING) << object_path_.value() | 1476 LOG(WARNING) << object_path_.value() |
| 1497 << ": Failed to set discovery filter: " << error_name << ": " | 1477 << ": Failed to set discovery filter: " << error_name << ": " |
| 1498 << error_message; | 1478 << error_message; |
| 1499 | 1479 |
| 1500 UMABluetoothDiscoverySessionOutcome outcome = | 1480 UMABluetoothDiscoverySessionOutcome outcome = |
| 1501 TranslateDiscoveryErrorToUMA(error_name); | 1481 TranslateDiscoveryErrorToUMA(error_name); |
| 1502 if (outcome == UMABluetoothDiscoverySessionOutcome::FAILED) { | 1482 if (outcome == UMABluetoothDiscoverySessionOutcome::FAILED) { |
| 1503 // bluez/doc/adapter-api.txt says "Failed" is returned from | 1483 // bluez/doc/adapter-api.txt says "Failed" is returned from |
| 1504 // SetDiscoveryFilter when the controller doesn't support the requested | 1484 // SetDiscoveryFilter when the controller doesn't support the requested |
| 1505 // transport. | 1485 // transport. |
| 1506 outcome = UMABluetoothDiscoverySessionOutcome:: | 1486 outcome = UMABluetoothDiscoverySessionOutcome:: |
| 1507 CHROMEOS_DBUS_FAILED_MAYBE_UNSUPPORTED_TRANSPORT; | 1487 BLUEZ_DBUS_FAILED_MAYBE_UNSUPPORTED_TRANSPORT; |
| 1508 } | 1488 } |
| 1509 error_callback.Run(outcome); | 1489 error_callback.Run(outcome); |
| 1510 | 1490 |
| 1511 // Try to add a new discovery session for each queued request. | 1491 // Try to add a new discovery session for each queued request. |
| 1512 ProcessQueuedDiscoveryRequests(); | 1492 ProcessQueuedDiscoveryRequests(); |
| 1513 } | 1493 } |
| 1514 | 1494 |
| 1515 void BluetoothAdapterChromeOS::ProcessQueuedDiscoveryRequests() { | 1495 void BluetoothAdapterBlueZ::ProcessQueuedDiscoveryRequests() { |
| 1516 while (!discovery_request_queue_.empty()) { | 1496 while (!discovery_request_queue_.empty()) { |
| 1517 VLOG(1) << "Process queued discovery request."; | 1497 VLOG(1) << "Process queued discovery request."; |
| 1518 DiscoveryParamTuple params = discovery_request_queue_.front(); | 1498 DiscoveryParamTuple params = discovery_request_queue_.front(); |
| 1519 discovery_request_queue_.pop(); | 1499 discovery_request_queue_.pop(); |
| 1520 AddDiscoverySession(std::get<0>(params), std::get<1>(params), | 1500 AddDiscoverySession(std::get<0>(params), std::get<1>(params), |
| 1521 std::get<2>(params)); | 1501 std::get<2>(params)); |
| 1522 | 1502 |
| 1523 // If the queued request resulted in a pending call, then let it | 1503 // If the queued request resulted in a pending call, then let it |
| 1524 // asynchonously process the remaining queued requests once the pending | 1504 // asynchonously process the remaining queued requests once the pending |
| 1525 // call returns. | 1505 // call returns. |
| 1526 if (discovery_request_pending_) | 1506 if (discovery_request_pending_) |
| 1527 return; | 1507 return; |
| 1528 } | 1508 } |
| 1529 } | 1509 } |
| 1530 | 1510 |
| 1531 } // namespace chromeos | 1511 } // namespace bluez |
| OLD | NEW |