| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 5 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 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/dbus/bluetooth_adapter_client.h" | |
| 17 #include "chromeos/dbus/bluetooth_agent_manager_client.h" | |
| 18 #include "chromeos/dbus/bluetooth_agent_service_provider.h" | |
| 19 #include "chromeos/dbus/bluetooth_device_client.h" | |
| 20 #include "chromeos/dbus/bluetooth_input_client.h" | |
| 21 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 22 #include "chromeos/system/devicetype.h" | 16 #include "chromeos/system/devicetype.h" |
| 23 #include "device/bluetooth/bluetooth_adapter_profile_chromeos.h" | 17 #include "device/bluetooth/bluetooth_adapter_profile_chromeos.h" |
| 24 #include "device/bluetooth/bluetooth_advertisement_chromeos.h" | 18 #include "device/bluetooth/bluetooth_advertisement_chromeos.h" |
| 25 #include "device/bluetooth/bluetooth_audio_sink_chromeos.h" | 19 #include "device/bluetooth/bluetooth_audio_sink_chromeos.h" |
| 26 #include "device/bluetooth/bluetooth_device.h" | 20 #include "device/bluetooth/bluetooth_device.h" |
| 27 #include "device/bluetooth/bluetooth_device_chromeos.h" | 21 #include "device/bluetooth/bluetooth_device_chromeos.h" |
| 28 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" | 22 #include "device/bluetooth/bluetooth_discovery_session_outcome.h" |
| 29 #include "device/bluetooth/bluetooth_pairing_chromeos.h" | 23 #include "device/bluetooth/bluetooth_pairing_chromeos.h" |
| 30 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h" | 24 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h" |
| 31 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h" | 25 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h" |
| 32 #include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h" | 26 #include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h" |
| 33 #include "device/bluetooth/bluetooth_socket_chromeos.h" | 27 #include "device/bluetooth/bluetooth_socket_chromeos.h" |
| 34 #include "device/bluetooth/bluetooth_socket_thread.h" | 28 #include "device/bluetooth/bluetooth_socket_thread.h" |
| 35 #include "device/bluetooth/bluetooth_uuid.h" | 29 #include "device/bluetooth/bluetooth_uuid.h" |
| 30 #include "device/bluetooth/dbus/bluetooth_adapter_client.h" |
| 31 #include "device/bluetooth/dbus/bluetooth_agent_manager_client.h" |
| 32 #include "device/bluetooth/dbus/bluetooth_agent_service_provider.h" |
| 33 #include "device/bluetooth/dbus/bluetooth_device_client.h" |
| 34 #include "device/bluetooth/dbus/bluetooth_input_client.h" |
| 35 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 36 #include "third_party/cros_system_api/dbus/service_constants.h" | 36 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 37 | 37 |
| 38 using device::BluetoothAdapter; | 38 using device::BluetoothAdapter; |
| 39 using device::BluetoothAudioSink; | 39 using device::BluetoothAudioSink; |
| 40 using device::BluetoothDevice; | 40 using device::BluetoothDevice; |
| 41 using device::BluetoothDiscoveryFilter; | 41 using device::BluetoothDiscoveryFilter; |
| 42 using device::BluetoothSocket; | 42 using device::BluetoothSocket; |
| 43 using device::BluetoothUUID; | 43 using device::BluetoothUUID; |
| 44 using device::UMABluetoothDiscoverySessionOutcome; | 44 using device::UMABluetoothDiscoverySessionOutcome; |
| 45 | 45 |
| 46 namespace { | 46 namespace { |
| 47 | 47 |
| 48 // The agent path is relatively meaningless since BlueZ only permits one to | 48 // 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. | 49 // exist per D-Bus connection, it just has to be unique within Chromium. |
| 50 const char kAgentPath[] = "/org/chromium/bluetooth_agent"; | 50 const char kAgentPath[] = "/org/chromium/bluetooth_agent"; |
| 51 | 51 |
| 52 void OnUnregisterAgentError(const std::string& error_name, | 52 void OnUnregisterAgentError(const std::string& error_name, |
| 53 const std::string& error_message) { | 53 const std::string& error_message) { |
| 54 // It's okay if the agent didn't exist, it means we never saw an adapter. | 54 // It's okay if the agent didn't exist, it means we never saw an adapter. |
| 55 if (error_name == bluetooth_agent_manager::kErrorDoesNotExist) | 55 if (error_name == bluetooth_agent_manager::kErrorDoesNotExist) |
| 56 return; | 56 return; |
| 57 | 57 |
| 58 LOG(WARNING) << "Failed to unregister pairing agent: " | 58 LOG(WARNING) << "Failed to unregister pairing agent: " |
| 59 << error_name << ": " << error_message; | 59 << error_name << ": " << error_message; |
| 60 } | 60 } |
| 61 | 61 |
| 62 UMABluetoothDiscoverySessionOutcome TranslateDiscoveryErrorToUMA( | 62 UMABluetoothDiscoverySessionOutcome TranslateDiscoveryErrorToUMA( |
| 63 const std::string& error_name) { | 63 const std::string& error_name) { |
| 64 if (error_name == chromeos::BluetoothAdapterClient::kUnknownAdapterError) { | 64 if (error_name == bluez::BluetoothAdapterClient::kUnknownAdapterError) { |
| 65 return UMABluetoothDiscoverySessionOutcome::CHROMEOS_DBUS_UNKNOWN_ADAPTER; | 65 return UMABluetoothDiscoverySessionOutcome::CHROMEOS_DBUS_UNKNOWN_ADAPTER; |
| 66 } else if (error_name == chromeos::BluetoothAdapterClient::kNoResponseError) { | 66 } else if (error_name == bluez::BluetoothAdapterClient::kNoResponseError) { |
| 67 return UMABluetoothDiscoverySessionOutcome::CHROMEOS_DBUS_NO_RESPONSE; | 67 return UMABluetoothDiscoverySessionOutcome::CHROMEOS_DBUS_NO_RESPONSE; |
| 68 } else if (error_name == bluetooth_device::kErrorInProgress) { | 68 } else if (error_name == bluetooth_device::kErrorInProgress) { |
| 69 return UMABluetoothDiscoverySessionOutcome::CHROMEOS_DBUS_IN_PROGRESS; | 69 return UMABluetoothDiscoverySessionOutcome::CHROMEOS_DBUS_IN_PROGRESS; |
| 70 } else if (error_name == bluetooth_device::kErrorNotReady) { | 70 } else if (error_name == bluetooth_device::kErrorNotReady) { |
| 71 return UMABluetoothDiscoverySessionOutcome::CHROMEOS_DBUS_NOT_READY; | 71 return UMABluetoothDiscoverySessionOutcome::CHROMEOS_DBUS_NOT_READY; |
| 72 } else if (error_name == bluetooth_device::kErrorFailed) { | 72 } else if (error_name == bluetooth_device::kErrorFailed) { |
| 73 return UMABluetoothDiscoverySessionOutcome::FAILED; | 73 return UMABluetoothDiscoverySessionOutcome::FAILED; |
| 74 } else { | 74 } else { |
| 75 LOG(WARNING) << "Can't histogram DBus error " << error_name; | 75 LOG(WARNING) << "Can't histogram DBus error " << error_name; |
| 76 return UMABluetoothDiscoverySessionOutcome::UNKNOWN; | 76 return UMABluetoothDiscoverySessionOutcome::UNKNOWN; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 93 | 93 |
| 94 // static | 94 // static |
| 95 base::WeakPtr<BluetoothAdapter> BluetoothAdapterChromeOS::CreateAdapter() { | 95 base::WeakPtr<BluetoothAdapter> BluetoothAdapterChromeOS::CreateAdapter() { |
| 96 BluetoothAdapterChromeOS* adapter = new BluetoothAdapterChromeOS(); | 96 BluetoothAdapterChromeOS* adapter = new BluetoothAdapterChromeOS(); |
| 97 return adapter->weak_ptr_factory_.GetWeakPtr(); | 97 return adapter->weak_ptr_factory_.GetWeakPtr(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void BluetoothAdapterChromeOS::Shutdown() { | 100 void BluetoothAdapterChromeOS::Shutdown() { |
| 101 if (dbus_is_shutdown_) | 101 if (dbus_is_shutdown_) |
| 102 return; | 102 return; |
| 103 DCHECK(DBusThreadManager::IsInitialized()) | 103 DCHECK(bluez::BluezDBusManager::IsInitialized()) |
| 104 << "Call BluetoothAdapterFactory::Shutdown() before " | 104 << "Call BluetoothAdapterFactory::Shutdown() before " |
| 105 "DBusThreadManager::Shutdown()."; | 105 "BluezDBusManager::Shutdown()."; |
| 106 | 106 |
| 107 if (IsPresent()) | 107 if (IsPresent()) |
| 108 RemoveAdapter(); // Also deletes devices_. | 108 RemoveAdapter(); // Also deletes devices_. |
| 109 DCHECK(devices_.empty()); | 109 DCHECK(devices_.empty()); |
| 110 // profiles_ is empty because all BluetoothSockets have been notified | 110 // profiles_ is empty because all BluetoothSockets have been notified |
| 111 // that this adapter is disappearing. | 111 // that this adapter is disappearing. |
| 112 DCHECK(profiles_.empty()); | 112 DCHECK(profiles_.empty()); |
| 113 | 113 |
| 114 for (auto& it : profile_queues_) | 114 for (auto& it : profile_queues_) |
| 115 delete it.second; | 115 delete it.second; |
| 116 profile_queues_.clear(); | 116 profile_queues_.clear(); |
| 117 | 117 |
| 118 DBusThreadManager::Get()->GetBluetoothAdapterClient()->RemoveObserver(this); | 118 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->RemoveObserver( |
| 119 DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this); | 119 this); |
| 120 DBusThreadManager::Get()->GetBluetoothInputClient()->RemoveObserver(this); | 120 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->RemoveObserver( |
| 121 this); |
| 122 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->RemoveObserver( |
| 123 this); |
| 121 | 124 |
| 122 VLOG(1) << "Unregistering pairing agent"; | 125 VLOG(1) << "Unregistering pairing agent"; |
| 123 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()->UnregisterAgent( | 126 bluez::BluezDBusManager::Get() |
| 124 dbus::ObjectPath(kAgentPath), base::Bind(&base::DoNothing), | 127 ->GetBluetoothAgentManagerClient() |
| 125 base::Bind(&OnUnregisterAgentError)); | 128 ->UnregisterAgent(dbus::ObjectPath(kAgentPath), |
| 129 base::Bind(&base::DoNothing), |
| 130 base::Bind(&OnUnregisterAgentError)); |
| 126 | 131 |
| 127 agent_.reset(); | 132 agent_.reset(); |
| 128 dbus_is_shutdown_ = true; | 133 dbus_is_shutdown_ = true; |
| 129 } | 134 } |
| 130 | 135 |
| 131 BluetoothAdapterChromeOS::BluetoothAdapterChromeOS() | 136 BluetoothAdapterChromeOS::BluetoothAdapterChromeOS() |
| 132 : dbus_is_shutdown_(false), | 137 : dbus_is_shutdown_(false), |
| 133 num_discovery_sessions_(0), | 138 num_discovery_sessions_(0), |
| 134 discovery_request_pending_(false), | 139 discovery_request_pending_(false), |
| 135 weak_ptr_factory_(this) { | 140 weak_ptr_factory_(this) { |
| 136 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 141 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 137 socket_thread_ = device::BluetoothSocketThread::Get(); | 142 socket_thread_ = device::BluetoothSocketThread::Get(); |
| 138 | 143 |
| 139 DBusThreadManager::Get()->GetBluetoothAdapterClient()->AddObserver(this); | 144 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->AddObserver( |
| 140 DBusThreadManager::Get()->GetBluetoothDeviceClient()->AddObserver(this); | 145 this); |
| 141 DBusThreadManager::Get()->GetBluetoothInputClient()->AddObserver(this); | 146 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->AddObserver(this); |
| 147 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->AddObserver(this); |
| 142 | 148 |
| 143 // Register the pairing agent. | 149 // Register the pairing agent. |
| 144 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); | 150 dbus::Bus* system_bus = bluez::BluezDBusManager::Get()->GetSystemBus(); |
| 145 agent_.reset(BluetoothAgentServiceProvider::Create( | 151 agent_.reset(bluez::BluetoothAgentServiceProvider::Create( |
| 146 system_bus, dbus::ObjectPath(kAgentPath), this)); | 152 system_bus, dbus::ObjectPath(kAgentPath), this)); |
| 147 DCHECK(agent_.get()); | 153 DCHECK(agent_.get()); |
| 148 | 154 |
| 149 std::vector<dbus::ObjectPath> object_paths = | 155 std::vector<dbus::ObjectPath> object_paths = bluez::BluezDBusManager::Get() |
| 150 DBusThreadManager::Get()->GetBluetoothAdapterClient()->GetAdapters(); | 156 ->GetBluetoothAdapterClient() |
| 157 ->GetAdapters(); |
| 151 | 158 |
| 152 if (!object_paths.empty()) { | 159 if (!object_paths.empty()) { |
| 153 VLOG(1) << object_paths.size() << " Bluetooth adapter(s) available."; | 160 VLOG(1) << object_paths.size() << " Bluetooth adapter(s) available."; |
| 154 SetAdapter(object_paths[0]); | 161 SetAdapter(object_paths[0]); |
| 155 } | 162 } |
| 156 } | 163 } |
| 157 | 164 |
| 158 BluetoothAdapterChromeOS::~BluetoothAdapterChromeOS() { | 165 BluetoothAdapterChromeOS::~BluetoothAdapterChromeOS() { |
| 159 Shutdown(); | 166 Shutdown(); |
| 160 } | 167 } |
| 161 | 168 |
| 162 std::string BluetoothAdapterChromeOS::GetAddress() const { | 169 std::string BluetoothAdapterChromeOS::GetAddress() const { |
| 163 if (!IsPresent()) | 170 if (!IsPresent()) |
| 164 return std::string(); | 171 return std::string(); |
| 165 | 172 |
| 166 BluetoothAdapterClient::Properties* properties = | 173 bluez::BluetoothAdapterClient::Properties* properties = |
| 167 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 174 bluez::BluezDBusManager::Get() |
| 168 GetProperties(object_path_); | 175 ->GetBluetoothAdapterClient() |
| 176 ->GetProperties(object_path_); |
| 169 DCHECK(properties); | 177 DCHECK(properties); |
| 170 | 178 |
| 171 return BluetoothDevice::CanonicalizeAddress(properties->address.value()); | 179 return BluetoothDevice::CanonicalizeAddress(properties->address.value()); |
| 172 } | 180 } |
| 173 | 181 |
| 174 std::string BluetoothAdapterChromeOS::GetName() const { | 182 std::string BluetoothAdapterChromeOS::GetName() const { |
| 175 if (!IsPresent()) | 183 if (!IsPresent()) |
| 176 return std::string(); | 184 return std::string(); |
| 177 | 185 |
| 178 BluetoothAdapterClient::Properties* properties = | 186 bluez::BluetoothAdapterClient::Properties* properties = |
| 179 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 187 bluez::BluezDBusManager::Get() |
| 180 GetProperties(object_path_); | 188 ->GetBluetoothAdapterClient() |
| 189 ->GetProperties(object_path_); |
| 181 DCHECK(properties); | 190 DCHECK(properties); |
| 182 | 191 |
| 183 return properties->alias.value(); | 192 return properties->alias.value(); |
| 184 } | 193 } |
| 185 | 194 |
| 186 void BluetoothAdapterChromeOS::SetName(const std::string& name, | 195 void BluetoothAdapterChromeOS::SetName(const std::string& name, |
| 187 const base::Closure& callback, | 196 const base::Closure& callback, |
| 188 const ErrorCallback& error_callback) { | 197 const ErrorCallback& error_callback) { |
| 189 if (!IsPresent()) { | 198 if (!IsPresent()) { |
| 190 error_callback.Run(); | 199 error_callback.Run(); |
| 191 return; | 200 return; |
| 192 } | 201 } |
| 193 | 202 |
| 194 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 203 bluez::BluezDBusManager::Get() |
| 195 GetProperties(object_path_)->alias.Set( | 204 ->GetBluetoothAdapterClient() |
| 205 ->GetProperties(object_path_) |
| 206 ->alias.Set( |
| 196 name, | 207 name, |
| 197 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, | 208 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, |
| 198 weak_ptr_factory_.GetWeakPtr(), | 209 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 199 callback, | |
| 200 error_callback)); | |
| 201 } | 210 } |
| 202 | 211 |
| 203 bool BluetoothAdapterChromeOS::IsInitialized() const { | 212 bool BluetoothAdapterChromeOS::IsInitialized() const { |
| 204 return true; | 213 return true; |
| 205 } | 214 } |
| 206 | 215 |
| 207 bool BluetoothAdapterChromeOS::IsPresent() const { | 216 bool BluetoothAdapterChromeOS::IsPresent() const { |
| 208 return !dbus_is_shutdown_ && !object_path_.value().empty(); | 217 return !dbus_is_shutdown_ && !object_path_.value().empty(); |
| 209 } | 218 } |
| 210 | 219 |
| 211 bool BluetoothAdapterChromeOS::IsPowered() const { | 220 bool BluetoothAdapterChromeOS::IsPowered() const { |
| 212 if (!IsPresent()) | 221 if (!IsPresent()) |
| 213 return false; | 222 return false; |
| 214 | 223 |
| 215 BluetoothAdapterClient::Properties* properties = | 224 bluez::BluetoothAdapterClient::Properties* properties = |
| 216 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 225 bluez::BluezDBusManager::Get() |
| 217 GetProperties(object_path_); | 226 ->GetBluetoothAdapterClient() |
| 227 ->GetProperties(object_path_); |
| 218 | 228 |
| 219 return properties->powered.value(); | 229 return properties->powered.value(); |
| 220 } | 230 } |
| 221 | 231 |
| 222 void BluetoothAdapterChromeOS::SetPowered( | 232 void BluetoothAdapterChromeOS::SetPowered( |
| 223 bool powered, | 233 bool powered, |
| 224 const base::Closure& callback, | 234 const base::Closure& callback, |
| 225 const ErrorCallback& error_callback) { | 235 const ErrorCallback& error_callback) { |
| 226 if (!IsPresent()) { | 236 if (!IsPresent()) { |
| 227 error_callback.Run(); | 237 error_callback.Run(); |
| 228 return; | 238 return; |
| 229 } | 239 } |
| 230 | 240 |
| 231 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 241 bluez::BluezDBusManager::Get() |
| 232 GetProperties(object_path_)->powered.Set( | 242 ->GetBluetoothAdapterClient() |
| 243 ->GetProperties(object_path_) |
| 244 ->powered.Set( |
| 233 powered, | 245 powered, |
| 234 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, | 246 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, |
| 235 weak_ptr_factory_.GetWeakPtr(), | 247 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 236 callback, | |
| 237 error_callback)); | |
| 238 } | 248 } |
| 239 | 249 |
| 240 bool BluetoothAdapterChromeOS::IsDiscoverable() const { | 250 bool BluetoothAdapterChromeOS::IsDiscoverable() const { |
| 241 if (!IsPresent()) | 251 if (!IsPresent()) |
| 242 return false; | 252 return false; |
| 243 | 253 |
| 244 BluetoothAdapterClient::Properties* properties = | 254 bluez::BluetoothAdapterClient::Properties* properties = |
| 245 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 255 bluez::BluezDBusManager::Get() |
| 246 GetProperties(object_path_); | 256 ->GetBluetoothAdapterClient() |
| 257 ->GetProperties(object_path_); |
| 247 | 258 |
| 248 return properties->discoverable.value(); | 259 return properties->discoverable.value(); |
| 249 } | 260 } |
| 250 | 261 |
| 251 void BluetoothAdapterChromeOS::SetDiscoverable( | 262 void BluetoothAdapterChromeOS::SetDiscoverable( |
| 252 bool discoverable, | 263 bool discoverable, |
| 253 const base::Closure& callback, | 264 const base::Closure& callback, |
| 254 const ErrorCallback& error_callback) { | 265 const ErrorCallback& error_callback) { |
| 255 if (!IsPresent()) { | 266 if (!IsPresent()) { |
| 256 error_callback.Run(); | 267 error_callback.Run(); |
| 257 return; | 268 return; |
| 258 } | 269 } |
| 259 | 270 |
| 260 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 271 bluez::BluezDBusManager::Get() |
| 261 GetProperties(object_path_)->discoverable.Set( | 272 ->GetBluetoothAdapterClient() |
| 273 ->GetProperties(object_path_) |
| 274 ->discoverable.Set( |
| 262 discoverable, | 275 discoverable, |
| 263 base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoverable, | 276 base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoverable, |
| 264 weak_ptr_factory_.GetWeakPtr(), | 277 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 265 callback, | |
| 266 error_callback)); | |
| 267 } | 278 } |
| 268 | 279 |
| 269 bool BluetoothAdapterChromeOS::IsDiscovering() const { | 280 bool BluetoothAdapterChromeOS::IsDiscovering() const { |
| 270 if (!IsPresent()) | 281 if (!IsPresent()) |
| 271 return false; | 282 return false; |
| 272 | 283 |
| 273 BluetoothAdapterClient::Properties* properties = | 284 bluez::BluetoothAdapterClient::Properties* properties = |
| 274 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 285 bluez::BluezDBusManager::Get() |
| 275 GetProperties(object_path_); | 286 ->GetBluetoothAdapterClient() |
| 287 ->GetProperties(object_path_); |
| 276 | 288 |
| 277 return properties->discovering.value(); | 289 return properties->discovering.value(); |
| 278 } | 290 } |
| 279 | 291 |
| 280 void BluetoothAdapterChromeOS::CreateRfcommService( | 292 void BluetoothAdapterChromeOS::CreateRfcommService( |
| 281 const BluetoothUUID& uuid, | 293 const BluetoothUUID& uuid, |
| 282 const ServiceOptions& options, | 294 const ServiceOptions& options, |
| 283 const CreateServiceCallback& callback, | 295 const CreateServiceCallback& callback, |
| 284 const CreateServiceErrorCallback& error_callback) { | 296 const CreateServiceErrorCallback& error_callback) { |
| 285 DCHECK(!dbus_is_shutdown_); | 297 DCHECK(!dbus_is_shutdown_); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 RemoveAdapter(); | 382 RemoveAdapter(); |
| 371 } | 383 } |
| 372 | 384 |
| 373 void BluetoothAdapterChromeOS::AdapterPropertyChanged( | 385 void BluetoothAdapterChromeOS::AdapterPropertyChanged( |
| 374 const dbus::ObjectPath& object_path, | 386 const dbus::ObjectPath& object_path, |
| 375 const std::string& property_name) { | 387 const std::string& property_name) { |
| 376 if (object_path != object_path_) | 388 if (object_path != object_path_) |
| 377 return; | 389 return; |
| 378 DCHECK(IsPresent()); | 390 DCHECK(IsPresent()); |
| 379 | 391 |
| 380 BluetoothAdapterClient::Properties* properties = | 392 bluez::BluetoothAdapterClient::Properties* properties = |
| 381 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 393 bluez::BluezDBusManager::Get() |
| 382 GetProperties(object_path_); | 394 ->GetBluetoothAdapterClient() |
| 395 ->GetProperties(object_path_); |
| 383 | 396 |
| 384 if (property_name == properties->powered.name()) { | 397 if (property_name == properties->powered.name()) { |
| 385 PoweredChanged(properties->powered.value()); | 398 PoweredChanged(properties->powered.value()); |
| 386 } else if (property_name == properties->discoverable.name()) { | 399 } else if (property_name == properties->discoverable.name()) { |
| 387 DiscoverableChanged(properties->discoverable.value()); | 400 DiscoverableChanged(properties->discoverable.value()); |
| 388 } else if (property_name == properties->discovering.name()) { | 401 } else if (property_name == properties->discovering.name()) { |
| 389 DiscoveringChanged(properties->discovering.value()); | 402 DiscoveringChanged(properties->discovering.value()); |
| 390 } | 403 } |
| 391 } | 404 } |
| 392 | 405 |
| 393 void BluetoothAdapterChromeOS::DeviceAdded( | 406 void BluetoothAdapterChromeOS::DeviceAdded( |
| 394 const dbus::ObjectPath& object_path) { | 407 const dbus::ObjectPath& object_path) { |
| 395 DCHECK(DBusThreadManager::Get()); | 408 DCHECK(bluez::BluezDBusManager::Get()); |
| 396 BluetoothDeviceClient::Properties* properties = | 409 bluez::BluetoothDeviceClient::Properties* properties = |
| 397 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 410 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 398 GetProperties(object_path); | 411 object_path); |
| 399 if (!properties || properties->adapter.value() != object_path_) | 412 if (!properties || properties->adapter.value() != object_path_) |
| 400 return; | 413 return; |
| 401 DCHECK(IsPresent()); | 414 DCHECK(IsPresent()); |
| 402 | 415 |
| 403 BluetoothDeviceChromeOS* device_chromeos = | 416 BluetoothDeviceChromeOS* device_chromeos = |
| 404 new BluetoothDeviceChromeOS(this, | 417 new BluetoothDeviceChromeOS(this, |
| 405 object_path, | 418 object_path, |
| 406 ui_task_runner_, | 419 ui_task_runner_, |
| 407 socket_thread_); | 420 socket_thread_); |
| 408 DCHECK(devices_.find(device_chromeos->GetAddress()) == devices_.end()); | 421 DCHECK(devices_.find(device_chromeos->GetAddress()) == devices_.end()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 430 } | 443 } |
| 431 } | 444 } |
| 432 | 445 |
| 433 void BluetoothAdapterChromeOS::DevicePropertyChanged( | 446 void BluetoothAdapterChromeOS::DevicePropertyChanged( |
| 434 const dbus::ObjectPath& object_path, | 447 const dbus::ObjectPath& object_path, |
| 435 const std::string& property_name) { | 448 const std::string& property_name) { |
| 436 BluetoothDeviceChromeOS* device_chromeos = GetDeviceWithPath(object_path); | 449 BluetoothDeviceChromeOS* device_chromeos = GetDeviceWithPath(object_path); |
| 437 if (!device_chromeos) | 450 if (!device_chromeos) |
| 438 return; | 451 return; |
| 439 | 452 |
| 440 BluetoothDeviceClient::Properties* properties = | 453 bluez::BluetoothDeviceClient::Properties* properties = |
| 441 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 454 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 442 GetProperties(object_path); | 455 object_path); |
| 443 | 456 |
| 444 if (property_name == properties->bluetooth_class.name() || | 457 if (property_name == properties->bluetooth_class.name() || |
| 445 property_name == properties->address.name() || | 458 property_name == properties->address.name() || |
| 446 property_name == properties->alias.name() || | 459 property_name == properties->alias.name() || |
| 447 property_name == properties->paired.name() || | 460 property_name == properties->paired.name() || |
| 448 property_name == properties->trusted.name() || | 461 property_name == properties->trusted.name() || |
| 449 property_name == properties->connected.name() || | 462 property_name == properties->connected.name() || |
| 450 property_name == properties->uuids.name() || | 463 property_name == properties->uuids.name() || |
| 451 property_name == properties->rssi.name() || | 464 property_name == properties->rssi.name() || |
| 452 property_name == properties->tx_power.name()) { | 465 property_name == properties->tx_power.name()) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 481 } | 494 } |
| 482 } | 495 } |
| 483 | 496 |
| 484 void BluetoothAdapterChromeOS::InputPropertyChanged( | 497 void BluetoothAdapterChromeOS::InputPropertyChanged( |
| 485 const dbus::ObjectPath& object_path, | 498 const dbus::ObjectPath& object_path, |
| 486 const std::string& property_name) { | 499 const std::string& property_name) { |
| 487 BluetoothDeviceChromeOS* device_chromeos = GetDeviceWithPath(object_path); | 500 BluetoothDeviceChromeOS* device_chromeos = GetDeviceWithPath(object_path); |
| 488 if (!device_chromeos) | 501 if (!device_chromeos) |
| 489 return; | 502 return; |
| 490 | 503 |
| 491 BluetoothInputClient::Properties* properties = | 504 bluez::BluetoothInputClient::Properties* properties = |
| 492 DBusThreadManager::Get()->GetBluetoothInputClient()-> | 505 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->GetProperties( |
| 493 GetProperties(object_path); | 506 object_path); |
| 494 | 507 |
| 495 // Properties structure can be removed, which triggers a change in the | 508 // Properties structure can be removed, which triggers a change in the |
| 496 // BluetoothDevice::IsConnectable() property, as does a change in the | 509 // BluetoothDevice::IsConnectable() property, as does a change in the |
| 497 // actual reconnect_mode property. | 510 // actual reconnect_mode property. |
| 498 if (!properties || property_name == properties->reconnect_mode.name()) { | 511 if (!properties || property_name == properties->reconnect_mode.name()) { |
| 499 NotifyDeviceChanged(device_chromeos); | 512 NotifyDeviceChanged(device_chromeos); |
| 500 } | 513 } |
| 501 } | 514 } |
| 502 | 515 |
| 503 void BluetoothAdapterChromeOS::Released() { | 516 void BluetoothAdapterChromeOS::Released() { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 | 653 |
| 641 void BluetoothAdapterChromeOS::Cancel() { | 654 void BluetoothAdapterChromeOS::Cancel() { |
| 642 DCHECK(IsPresent()); | 655 DCHECK(IsPresent()); |
| 643 DCHECK(agent_.get()); | 656 DCHECK(agent_.get()); |
| 644 VLOG(1) << "Cancel"; | 657 VLOG(1) << "Cancel"; |
| 645 } | 658 } |
| 646 | 659 |
| 647 void BluetoothAdapterChromeOS::OnRegisterAgent() { | 660 void BluetoothAdapterChromeOS::OnRegisterAgent() { |
| 648 VLOG(1) << "Pairing agent registered, requesting to be made default"; | 661 VLOG(1) << "Pairing agent registered, requesting to be made default"; |
| 649 | 662 |
| 650 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()-> | 663 bluez::BluezDBusManager::Get() |
| 651 RequestDefaultAgent( | 664 ->GetBluetoothAgentManagerClient() |
| 665 ->RequestDefaultAgent( |
| 652 dbus::ObjectPath(kAgentPath), | 666 dbus::ObjectPath(kAgentPath), |
| 653 base::Bind(&BluetoothAdapterChromeOS::OnRequestDefaultAgent, | 667 base::Bind(&BluetoothAdapterChromeOS::OnRequestDefaultAgent, |
| 654 weak_ptr_factory_.GetWeakPtr()), | 668 weak_ptr_factory_.GetWeakPtr()), |
| 655 base::Bind(&BluetoothAdapterChromeOS::OnRequestDefaultAgentError, | 669 base::Bind(&BluetoothAdapterChromeOS::OnRequestDefaultAgentError, |
| 656 weak_ptr_factory_.GetWeakPtr())); | 670 weak_ptr_factory_.GetWeakPtr())); |
| 657 } | 671 } |
| 658 | 672 |
| 659 void BluetoothAdapterChromeOS::OnRegisterAgentError( | 673 void BluetoothAdapterChromeOS::OnRegisterAgentError( |
| 660 const std::string& error_name, | 674 const std::string& error_name, |
| 661 const std::string& error_message) { | 675 const std::string& error_message) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 } | 746 } |
| 733 | 747 |
| 734 void BluetoothAdapterChromeOS::SetAdapter(const dbus::ObjectPath& object_path) { | 748 void BluetoothAdapterChromeOS::SetAdapter(const dbus::ObjectPath& object_path) { |
| 735 DCHECK(!IsPresent()); | 749 DCHECK(!IsPresent()); |
| 736 DCHECK(!dbus_is_shutdown_); | 750 DCHECK(!dbus_is_shutdown_); |
| 737 object_path_ = object_path; | 751 object_path_ = object_path; |
| 738 | 752 |
| 739 VLOG(1) << object_path_.value() << ": using adapter."; | 753 VLOG(1) << object_path_.value() << ": using adapter."; |
| 740 | 754 |
| 741 VLOG(1) << "Registering pairing agent"; | 755 VLOG(1) << "Registering pairing agent"; |
| 742 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()-> | 756 bluez::BluezDBusManager::Get() |
| 743 RegisterAgent( | 757 ->GetBluetoothAgentManagerClient() |
| 758 ->RegisterAgent( |
| 744 dbus::ObjectPath(kAgentPath), | 759 dbus::ObjectPath(kAgentPath), |
| 745 bluetooth_agent_manager::kKeyboardDisplayCapability, | 760 bluetooth_agent_manager::kKeyboardDisplayCapability, |
| 746 base::Bind(&BluetoothAdapterChromeOS::OnRegisterAgent, | 761 base::Bind(&BluetoothAdapterChromeOS::OnRegisterAgent, |
| 747 weak_ptr_factory_.GetWeakPtr()), | 762 weak_ptr_factory_.GetWeakPtr()), |
| 748 base::Bind(&BluetoothAdapterChromeOS::OnRegisterAgentError, | 763 base::Bind(&BluetoothAdapterChromeOS::OnRegisterAgentError, |
| 749 weak_ptr_factory_.GetWeakPtr())); | 764 weak_ptr_factory_.GetWeakPtr())); |
| 750 | 765 |
| 751 SetDefaultAdapterName(); | 766 SetDefaultAdapterName(); |
| 752 | 767 |
| 753 BluetoothAdapterClient::Properties* properties = | 768 bluez::BluetoothAdapterClient::Properties* properties = |
| 754 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 769 bluez::BluezDBusManager::Get() |
| 755 GetProperties(object_path_); | 770 ->GetBluetoothAdapterClient() |
| 771 ->GetProperties(object_path_); |
| 756 | 772 |
| 757 PresentChanged(true); | 773 PresentChanged(true); |
| 758 | 774 |
| 759 if (properties->powered.value()) | 775 if (properties->powered.value()) |
| 760 PoweredChanged(true); | 776 PoweredChanged(true); |
| 761 if (properties->discoverable.value()) | 777 if (properties->discoverable.value()) |
| 762 DiscoverableChanged(true); | 778 DiscoverableChanged(true); |
| 763 if (properties->discovering.value()) | 779 if (properties->discovering.value()) |
| 764 DiscoveringChanged(true); | 780 DiscoveringChanged(true); |
| 765 | 781 |
| 766 std::vector<dbus::ObjectPath> device_paths = | 782 std::vector<dbus::ObjectPath> device_paths = |
| 767 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 783 bluez::BluezDBusManager::Get() |
| 768 GetDevicesForAdapter(object_path_); | 784 ->GetBluetoothDeviceClient() |
| 785 ->GetDevicesForAdapter(object_path_); |
| 769 | 786 |
| 770 for (std::vector<dbus::ObjectPath>::iterator iter = device_paths.begin(); | 787 for (std::vector<dbus::ObjectPath>::iterator iter = device_paths.begin(); |
| 771 iter != device_paths.end(); ++iter) { | 788 iter != device_paths.end(); ++iter) { |
| 772 DeviceAdded(*iter); | 789 DeviceAdded(*iter); |
| 773 } | 790 } |
| 774 } | 791 } |
| 775 | 792 |
| 776 void BluetoothAdapterChromeOS::SetDefaultAdapterName() { | 793 void BluetoothAdapterChromeOS::SetDefaultAdapterName() { |
| 777 DCHECK(IsPresent()); | 794 DCHECK(IsPresent()); |
| 778 | 795 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 795 break; | 812 break; |
| 796 } | 813 } |
| 797 | 814 |
| 798 SetName(alias, base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); | 815 SetName(alias, base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); |
| 799 } | 816 } |
| 800 | 817 |
| 801 void BluetoothAdapterChromeOS::RemoveAdapter() { | 818 void BluetoothAdapterChromeOS::RemoveAdapter() { |
| 802 DCHECK(IsPresent()); | 819 DCHECK(IsPresent()); |
| 803 VLOG(1) << object_path_.value() << ": adapter removed."; | 820 VLOG(1) << object_path_.value() << ": adapter removed."; |
| 804 | 821 |
| 805 BluetoothAdapterClient::Properties* properties = | 822 bluez::BluetoothAdapterClient::Properties* properties = |
| 806 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 823 bluez::BluezDBusManager::Get() |
| 807 GetProperties(object_path_); | 824 ->GetBluetoothAdapterClient() |
| 825 ->GetProperties(object_path_); |
| 808 | 826 |
| 809 object_path_ = dbus::ObjectPath(""); | 827 object_path_ = dbus::ObjectPath(""); |
| 810 | 828 |
| 811 if (properties->powered.value()) | 829 if (properties->powered.value()) |
| 812 PoweredChanged(false); | 830 PoweredChanged(false); |
| 813 if (properties->discoverable.value()) | 831 if (properties->discoverable.value()) |
| 814 DiscoverableChanged(false); | 832 DiscoverableChanged(false); |
| 815 if (properties->discovering.value()) | 833 if (properties->discovering.value()) |
| 816 DiscoveringChanged(false); | 834 DiscoveringChanged(false); |
| 817 | 835 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 this); | 994 this); |
| 977 | 995 |
| 978 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 996 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, |
| 979 observers_, | 997 observers_, |
| 980 GattDescriptorValueChanged(this, descriptor, value)); | 998 GattDescriptorValueChanged(this, descriptor, value)); |
| 981 } | 999 } |
| 982 | 1000 |
| 983 void BluetoothAdapterChromeOS::UseProfile( | 1001 void BluetoothAdapterChromeOS::UseProfile( |
| 984 const BluetoothUUID& uuid, | 1002 const BluetoothUUID& uuid, |
| 985 const dbus::ObjectPath& device_path, | 1003 const dbus::ObjectPath& device_path, |
| 986 const BluetoothProfileManagerClient::Options& options, | 1004 const bluez::BluetoothProfileManagerClient::Options& options, |
| 987 BluetoothProfileServiceProvider::Delegate* delegate, | 1005 bluez::BluetoothProfileServiceProvider::Delegate* delegate, |
| 988 const ProfileRegisteredCallback& success_callback, | 1006 const ProfileRegisteredCallback& success_callback, |
| 989 const ErrorCompletionCallback& error_callback) { | 1007 const ErrorCompletionCallback& error_callback) { |
| 990 DCHECK(delegate); | 1008 DCHECK(delegate); |
| 991 | 1009 |
| 992 if (!IsPresent()) { | 1010 if (!IsPresent()) { |
| 993 VLOG(2) << "Adapter not present, erroring out"; | 1011 VLOG(2) << "Adapter not present, erroring out"; |
| 994 error_callback.Run("Adapter not present"); | 1012 error_callback.Run("Adapter not present"); |
| 995 return; | 1013 return; |
| 996 } | 1014 } |
| 997 | 1015 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 | 1066 |
| 1049 for (auto& it : *profile_queues_[uuid]) | 1067 for (auto& it : *profile_queues_[uuid]) |
| 1050 it.first.Run(); | 1068 it.first.Run(); |
| 1051 delete profile_queues_[uuid]; | 1069 delete profile_queues_[uuid]; |
| 1052 profile_queues_.erase(uuid); | 1070 profile_queues_.erase(uuid); |
| 1053 } | 1071 } |
| 1054 | 1072 |
| 1055 void BluetoothAdapterChromeOS::SetProfileDelegate( | 1073 void BluetoothAdapterChromeOS::SetProfileDelegate( |
| 1056 const BluetoothUUID& uuid, | 1074 const BluetoothUUID& uuid, |
| 1057 const dbus::ObjectPath& device_path, | 1075 const dbus::ObjectPath& device_path, |
| 1058 BluetoothProfileServiceProvider::Delegate* delegate, | 1076 bluez::BluetoothProfileServiceProvider::Delegate* delegate, |
| 1059 const ProfileRegisteredCallback& success_callback, | 1077 const ProfileRegisteredCallback& success_callback, |
| 1060 const ErrorCompletionCallback& error_callback) { | 1078 const ErrorCompletionCallback& error_callback) { |
| 1061 if (profiles_.find(uuid) == profiles_.end()) { | 1079 if (profiles_.find(uuid) == profiles_.end()) { |
| 1062 error_callback.Run("Cannot find profile!"); | 1080 error_callback.Run("Cannot find profile!"); |
| 1063 return; | 1081 return; |
| 1064 } | 1082 } |
| 1065 | 1083 |
| 1066 if (profiles_[uuid]->SetDelegate(device_path, delegate)) { | 1084 if (profiles_[uuid]->SetDelegate(device_path, delegate)) { |
| 1067 success_callback.Run(profiles_[uuid]); | 1085 success_callback.Run(profiles_[uuid]); |
| 1068 return; | 1086 return; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1091 const base::Closure& callback, | 1109 const base::Closure& callback, |
| 1092 const ErrorCallback& error_callback, | 1110 const ErrorCallback& error_callback, |
| 1093 bool success) { | 1111 bool success) { |
| 1094 if (!IsPresent()) { | 1112 if (!IsPresent()) { |
| 1095 error_callback.Run(); | 1113 error_callback.Run(); |
| 1096 return; | 1114 return; |
| 1097 } | 1115 } |
| 1098 | 1116 |
| 1099 // Set the discoverable_timeout property to zero so the adapter remains | 1117 // Set the discoverable_timeout property to zero so the adapter remains |
| 1100 // discoverable forever. | 1118 // discoverable forever. |
| 1101 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 1119 bluez::BluezDBusManager::Get() |
| 1102 GetProperties(object_path_)->discoverable_timeout.Set( | 1120 ->GetBluetoothAdapterClient() |
| 1121 ->GetProperties(object_path_) |
| 1122 ->discoverable_timeout.Set( |
| 1103 0, | 1123 0, |
| 1104 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, | 1124 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, |
| 1105 weak_ptr_factory_.GetWeakPtr(), | 1125 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 1106 callback, | |
| 1107 error_callback)); | |
| 1108 } | 1126 } |
| 1109 | 1127 |
| 1110 void BluetoothAdapterChromeOS::OnPropertyChangeCompleted( | 1128 void BluetoothAdapterChromeOS::OnPropertyChangeCompleted( |
| 1111 const base::Closure& callback, | 1129 const base::Closure& callback, |
| 1112 const ErrorCallback& error_callback, | 1130 const ErrorCallback& error_callback, |
| 1113 bool success) { | 1131 bool success) { |
| 1114 if (IsPresent() && success) { | 1132 if (IsPresent() && success) { |
| 1115 callback.Run(); | 1133 callback.Run(); |
| 1116 } else { | 1134 } else { |
| 1117 error_callback.Run(); | 1135 error_callback.Run(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 1183 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
| 1166 base::Bind(&BluetoothAdapterChromeOS::OnPreSetDiscoveryFilterError, | 1184 base::Bind(&BluetoothAdapterChromeOS::OnPreSetDiscoveryFilterError, |
| 1167 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1185 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 1168 return; | 1186 return; |
| 1169 } else { | 1187 } else { |
| 1170 current_filter_.reset(); | 1188 current_filter_.reset(); |
| 1171 } | 1189 } |
| 1172 | 1190 |
| 1173 // This is the first request to start device discovery. | 1191 // This is the first request to start device discovery. |
| 1174 discovery_request_pending_ = true; | 1192 discovery_request_pending_ = true; |
| 1175 DBusThreadManager::Get()->GetBluetoothAdapterClient()->StartDiscovery( | 1193 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StartDiscovery( |
| 1176 object_path_, | 1194 object_path_, |
| 1177 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscovery, | 1195 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscovery, |
| 1178 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 1196 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
| 1179 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscoveryError, | 1197 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscoveryError, |
| 1180 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1198 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 1181 } | 1199 } |
| 1182 | 1200 |
| 1183 void BluetoothAdapterChromeOS::RemoveDiscoverySession( | 1201 void BluetoothAdapterChromeOS::RemoveDiscoverySession( |
| 1184 BluetoothDiscoveryFilter* discovery_filter, | 1202 BluetoothDiscoveryFilter* discovery_filter, |
| 1185 const base::Closure& callback, | 1203 const base::Closure& callback, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1219 VLOG(1) << "No active discovery sessions. Returning error."; | 1237 VLOG(1) << "No active discovery sessions. Returning error."; |
| 1220 error_callback.Run( | 1238 error_callback.Run( |
| 1221 UMABluetoothDiscoverySessionOutcome::ACTIVE_SESSION_NOT_IN_ADAPTER); | 1239 UMABluetoothDiscoverySessionOutcome::ACTIVE_SESSION_NOT_IN_ADAPTER); |
| 1222 return; | 1240 return; |
| 1223 } | 1241 } |
| 1224 | 1242 |
| 1225 // There is exactly one active discovery session. Request BlueZ to stop | 1243 // There is exactly one active discovery session. Request BlueZ to stop |
| 1226 // discovery. | 1244 // discovery. |
| 1227 DCHECK_EQ(num_discovery_sessions_, 1); | 1245 DCHECK_EQ(num_discovery_sessions_, 1); |
| 1228 discovery_request_pending_ = true; | 1246 discovery_request_pending_ = true; |
| 1229 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 1247 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StopDiscovery( |
| 1230 StopDiscovery( | 1248 object_path_, base::Bind(&BluetoothAdapterChromeOS::OnStopDiscovery, |
| 1231 object_path_, | 1249 weak_ptr_factory_.GetWeakPtr(), callback), |
| 1232 base::Bind(&BluetoothAdapterChromeOS::OnStopDiscovery, | 1250 base::Bind(&BluetoothAdapterChromeOS::OnStopDiscoveryError, |
| 1233 weak_ptr_factory_.GetWeakPtr(), | 1251 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 1234 callback), | |
| 1235 base::Bind(&BluetoothAdapterChromeOS::OnStopDiscoveryError, | |
| 1236 weak_ptr_factory_.GetWeakPtr(), | |
| 1237 error_callback)); | |
| 1238 } | 1252 } |
| 1239 | 1253 |
| 1240 void BluetoothAdapterChromeOS::SetDiscoveryFilter( | 1254 void BluetoothAdapterChromeOS::SetDiscoveryFilter( |
| 1241 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 1255 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, |
| 1242 const base::Closure& callback, | 1256 const base::Closure& callback, |
| 1243 const DiscoverySessionErrorCallback& error_callback) { | 1257 const DiscoverySessionErrorCallback& error_callback) { |
| 1244 if (!IsPresent()) { | 1258 if (!IsPresent()) { |
| 1245 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); | 1259 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); |
| 1246 return; | 1260 return; |
| 1247 } | 1261 } |
| 1248 | 1262 |
| 1249 // If old and new filter are equal (null) then don't make request, just call | 1263 // If old and new filter are equal (null) then don't make request, just call |
| 1250 // succes callback | 1264 // succes callback |
| 1251 if (!current_filter_ && !discovery_filter.get()) { | 1265 if (!current_filter_ && !discovery_filter.get()) { |
| 1252 callback.Run(); | 1266 callback.Run(); |
| 1253 return; | 1267 return; |
| 1254 } | 1268 } |
| 1255 | 1269 |
| 1256 // If old and new filter are not null and equal then don't make request, just | 1270 // If old and new filter are not null and equal then don't make request, just |
| 1257 // call succes callback | 1271 // call succes callback |
| 1258 if (current_filter_ && discovery_filter && | 1272 if (current_filter_ && discovery_filter && |
| 1259 current_filter_->Equals(*discovery_filter)) { | 1273 current_filter_->Equals(*discovery_filter)) { |
| 1260 callback.Run(); | 1274 callback.Run(); |
| 1261 return; | 1275 return; |
| 1262 } | 1276 } |
| 1263 | 1277 |
| 1264 current_filter_.reset(discovery_filter.release()); | 1278 current_filter_.reset(discovery_filter.release()); |
| 1265 | 1279 |
| 1266 chromeos::BluetoothAdapterClient::DiscoveryFilter dbus_discovery_filter; | 1280 bluez::BluetoothAdapterClient::DiscoveryFilter dbus_discovery_filter; |
| 1267 | 1281 |
| 1268 if (current_filter_.get()) { | 1282 if (current_filter_.get()) { |
| 1269 uint16_t pathloss; | 1283 uint16_t pathloss; |
| 1270 int16_t rssi; | 1284 int16_t rssi; |
| 1271 uint8_t transport; | 1285 uint8_t transport; |
| 1272 std::set<device::BluetoothUUID> uuids; | 1286 std::set<device::BluetoothUUID> uuids; |
| 1273 | 1287 |
| 1274 if (current_filter_->GetPathloss(&pathloss)) | 1288 if (current_filter_->GetPathloss(&pathloss)) |
| 1275 dbus_discovery_filter.pathloss.reset(new uint16_t(pathloss)); | 1289 dbus_discovery_filter.pathloss.reset(new uint16_t(pathloss)); |
| 1276 | 1290 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1291 current_filter_->GetUUIDs(uuids); | 1305 current_filter_->GetUUIDs(uuids); |
| 1292 if (uuids.size()) { | 1306 if (uuids.size()) { |
| 1293 dbus_discovery_filter.uuids = | 1307 dbus_discovery_filter.uuids = |
| 1294 scoped_ptr<std::vector<std::string>>(new std::vector<std::string>); | 1308 scoped_ptr<std::vector<std::string>>(new std::vector<std::string>); |
| 1295 | 1309 |
| 1296 for (const auto& it : uuids) | 1310 for (const auto& it : uuids) |
| 1297 dbus_discovery_filter.uuids.get()->push_back(it.value()); | 1311 dbus_discovery_filter.uuids.get()->push_back(it.value()); |
| 1298 } | 1312 } |
| 1299 } | 1313 } |
| 1300 | 1314 |
| 1301 DBusThreadManager::Get()->GetBluetoothAdapterClient()->SetDiscoveryFilter( | 1315 bluez::BluezDBusManager::Get() |
| 1302 object_path_, dbus_discovery_filter, | 1316 ->GetBluetoothAdapterClient() |
| 1303 base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoveryFilter, | 1317 ->SetDiscoveryFilter( |
| 1304 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 1318 object_path_, dbus_discovery_filter, |
| 1305 base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoveryFilterError, | 1319 base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoveryFilter, |
| 1306 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1320 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
| 1321 base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoveryFilterError, |
| 1322 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 1307 } | 1323 } |
| 1308 | 1324 |
| 1309 void BluetoothAdapterChromeOS::OnStartDiscovery( | 1325 void BluetoothAdapterChromeOS::OnStartDiscovery( |
| 1310 const base::Closure& callback, | 1326 const base::Closure& callback, |
| 1311 const DiscoverySessionErrorCallback& error_callback) { | 1327 const DiscoverySessionErrorCallback& error_callback) { |
| 1312 // Report success on the original request and increment the count. | 1328 // Report success on the original request and increment the count. |
| 1313 VLOG(1) << __func__; | 1329 VLOG(1) << __func__; |
| 1314 DCHECK(discovery_request_pending_); | 1330 DCHECK(discovery_request_pending_); |
| 1315 DCHECK_EQ(num_discovery_sessions_, 0); | 1331 DCHECK_EQ(num_discovery_sessions_, 0); |
| 1316 discovery_request_pending_ = false; | 1332 discovery_request_pending_ = false; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 ProcessQueuedDiscoveryRequests(); | 1402 ProcessQueuedDiscoveryRequests(); |
| 1387 } | 1403 } |
| 1388 | 1404 |
| 1389 void BluetoothAdapterChromeOS::OnPreSetDiscoveryFilter( | 1405 void BluetoothAdapterChromeOS::OnPreSetDiscoveryFilter( |
| 1390 const base::Closure& callback, | 1406 const base::Closure& callback, |
| 1391 const DiscoverySessionErrorCallback& error_callback) { | 1407 const DiscoverySessionErrorCallback& error_callback) { |
| 1392 // This is the first request to start device discovery. | 1408 // This is the first request to start device discovery. |
| 1393 DCHECK(discovery_request_pending_); | 1409 DCHECK(discovery_request_pending_); |
| 1394 DCHECK_EQ(num_discovery_sessions_, 0); | 1410 DCHECK_EQ(num_discovery_sessions_, 0); |
| 1395 | 1411 |
| 1396 DBusThreadManager::Get()->GetBluetoothAdapterClient()->StartDiscovery( | 1412 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StartDiscovery( |
| 1397 object_path_, | 1413 object_path_, |
| 1398 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscovery, | 1414 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscovery, |
| 1399 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 1415 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
| 1400 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscoveryError, | 1416 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscoveryError, |
| 1401 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1417 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 1402 } | 1418 } |
| 1403 | 1419 |
| 1404 void BluetoothAdapterChromeOS::OnPreSetDiscoveryFilterError( | 1420 void BluetoothAdapterChromeOS::OnPreSetDiscoveryFilterError( |
| 1405 const base::Closure& callback, | 1421 const base::Closure& callback, |
| 1406 const DiscoverySessionErrorCallback& error_callback, | 1422 const DiscoverySessionErrorCallback& error_callback, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1465 | 1481 |
| 1466 // If the queued request resulted in a pending call, then let it | 1482 // If the queued request resulted in a pending call, then let it |
| 1467 // asynchonously process the remaining queued requests once the pending | 1483 // asynchonously process the remaining queued requests once the pending |
| 1468 // call returns. | 1484 // call returns. |
| 1469 if (discovery_request_pending_) | 1485 if (discovery_request_pending_) |
| 1470 return; | 1486 return; |
| 1471 } | 1487 } |
| 1472 } | 1488 } |
| 1473 | 1489 |
| 1474 } // namespace chromeos | 1490 } // namespace chromeos |
| OLD | NEW |