| 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->address.name()) { | 457 if (property_name == properties->address.name()) { |
| 445 for (auto iter = devices_.begin(); iter != devices_.end(); ++iter) { | 458 for (auto iter = devices_.begin(); iter != devices_.end(); ++iter) { |
| 446 if (iter->second->GetAddress() == device_chromeos->GetAddress()) { | 459 if (iter->second->GetAddress() == device_chromeos->GetAddress()) { |
| 447 std::string old_address = iter->first; | 460 std::string old_address = iter->first; |
| 448 VLOG(1) << "Device changed address, old: " << old_address | 461 VLOG(1) << "Device changed address, old: " << old_address |
| 449 << " new: " << device_chromeos->GetAddress(); | 462 << " new: " << device_chromeos->GetAddress(); |
| 450 devices_.erase(iter); | 463 devices_.erase(iter); |
| 451 | 464 |
| 452 DCHECK(devices_.find(device_chromeos->GetAddress()) == devices_.end()); | 465 DCHECK(devices_.find(device_chromeos->GetAddress()) == devices_.end()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 } | 510 } |
| 498 } | 511 } |
| 499 | 512 |
| 500 void BluetoothAdapterChromeOS::InputPropertyChanged( | 513 void BluetoothAdapterChromeOS::InputPropertyChanged( |
| 501 const dbus::ObjectPath& object_path, | 514 const dbus::ObjectPath& object_path, |
| 502 const std::string& property_name) { | 515 const std::string& property_name) { |
| 503 BluetoothDeviceChromeOS* device_chromeos = GetDeviceWithPath(object_path); | 516 BluetoothDeviceChromeOS* device_chromeos = GetDeviceWithPath(object_path); |
| 504 if (!device_chromeos) | 517 if (!device_chromeos) |
| 505 return; | 518 return; |
| 506 | 519 |
| 507 BluetoothInputClient::Properties* properties = | 520 bluez::BluetoothInputClient::Properties* properties = |
| 508 DBusThreadManager::Get()->GetBluetoothInputClient()-> | 521 bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->GetProperties( |
| 509 GetProperties(object_path); | 522 object_path); |
| 510 | 523 |
| 511 // Properties structure can be removed, which triggers a change in the | 524 // Properties structure can be removed, which triggers a change in the |
| 512 // BluetoothDevice::IsConnectable() property, as does a change in the | 525 // BluetoothDevice::IsConnectable() property, as does a change in the |
| 513 // actual reconnect_mode property. | 526 // actual reconnect_mode property. |
| 514 if (!properties || property_name == properties->reconnect_mode.name()) { | 527 if (!properties || property_name == properties->reconnect_mode.name()) { |
| 515 NotifyDeviceChanged(device_chromeos); | 528 NotifyDeviceChanged(device_chromeos); |
| 516 } | 529 } |
| 517 } | 530 } |
| 518 | 531 |
| 519 void BluetoothAdapterChromeOS::Released() { | 532 void BluetoothAdapterChromeOS::Released() { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 | 669 |
| 657 void BluetoothAdapterChromeOS::Cancel() { | 670 void BluetoothAdapterChromeOS::Cancel() { |
| 658 DCHECK(IsPresent()); | 671 DCHECK(IsPresent()); |
| 659 DCHECK(agent_.get()); | 672 DCHECK(agent_.get()); |
| 660 VLOG(1) << "Cancel"; | 673 VLOG(1) << "Cancel"; |
| 661 } | 674 } |
| 662 | 675 |
| 663 void BluetoothAdapterChromeOS::OnRegisterAgent() { | 676 void BluetoothAdapterChromeOS::OnRegisterAgent() { |
| 664 VLOG(1) << "Pairing agent registered, requesting to be made default"; | 677 VLOG(1) << "Pairing agent registered, requesting to be made default"; |
| 665 | 678 |
| 666 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()-> | 679 bluez::BluezDBusManager::Get() |
| 667 RequestDefaultAgent( | 680 ->GetBluetoothAgentManagerClient() |
| 681 ->RequestDefaultAgent( |
| 668 dbus::ObjectPath(kAgentPath), | 682 dbus::ObjectPath(kAgentPath), |
| 669 base::Bind(&BluetoothAdapterChromeOS::OnRequestDefaultAgent, | 683 base::Bind(&BluetoothAdapterChromeOS::OnRequestDefaultAgent, |
| 670 weak_ptr_factory_.GetWeakPtr()), | 684 weak_ptr_factory_.GetWeakPtr()), |
| 671 base::Bind(&BluetoothAdapterChromeOS::OnRequestDefaultAgentError, | 685 base::Bind(&BluetoothAdapterChromeOS::OnRequestDefaultAgentError, |
| 672 weak_ptr_factory_.GetWeakPtr())); | 686 weak_ptr_factory_.GetWeakPtr())); |
| 673 } | 687 } |
| 674 | 688 |
| 675 void BluetoothAdapterChromeOS::OnRegisterAgentError( | 689 void BluetoothAdapterChromeOS::OnRegisterAgentError( |
| 676 const std::string& error_name, | 690 const std::string& error_name, |
| 677 const std::string& error_message) { | 691 const std::string& error_message) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 } | 762 } |
| 749 | 763 |
| 750 void BluetoothAdapterChromeOS::SetAdapter(const dbus::ObjectPath& object_path) { | 764 void BluetoothAdapterChromeOS::SetAdapter(const dbus::ObjectPath& object_path) { |
| 751 DCHECK(!IsPresent()); | 765 DCHECK(!IsPresent()); |
| 752 DCHECK(!dbus_is_shutdown_); | 766 DCHECK(!dbus_is_shutdown_); |
| 753 object_path_ = object_path; | 767 object_path_ = object_path; |
| 754 | 768 |
| 755 VLOG(1) << object_path_.value() << ": using adapter."; | 769 VLOG(1) << object_path_.value() << ": using adapter."; |
| 756 | 770 |
| 757 VLOG(1) << "Registering pairing agent"; | 771 VLOG(1) << "Registering pairing agent"; |
| 758 DBusThreadManager::Get()->GetBluetoothAgentManagerClient()-> | 772 bluez::BluezDBusManager::Get() |
| 759 RegisterAgent( | 773 ->GetBluetoothAgentManagerClient() |
| 774 ->RegisterAgent( |
| 760 dbus::ObjectPath(kAgentPath), | 775 dbus::ObjectPath(kAgentPath), |
| 761 bluetooth_agent_manager::kKeyboardDisplayCapability, | 776 bluetooth_agent_manager::kKeyboardDisplayCapability, |
| 762 base::Bind(&BluetoothAdapterChromeOS::OnRegisterAgent, | 777 base::Bind(&BluetoothAdapterChromeOS::OnRegisterAgent, |
| 763 weak_ptr_factory_.GetWeakPtr()), | 778 weak_ptr_factory_.GetWeakPtr()), |
| 764 base::Bind(&BluetoothAdapterChromeOS::OnRegisterAgentError, | 779 base::Bind(&BluetoothAdapterChromeOS::OnRegisterAgentError, |
| 765 weak_ptr_factory_.GetWeakPtr())); | 780 weak_ptr_factory_.GetWeakPtr())); |
| 766 | 781 |
| 767 SetDefaultAdapterName(); | 782 SetDefaultAdapterName(); |
| 768 | 783 |
| 769 BluetoothAdapterClient::Properties* properties = | 784 bluez::BluetoothAdapterClient::Properties* properties = |
| 770 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 785 bluez::BluezDBusManager::Get() |
| 771 GetProperties(object_path_); | 786 ->GetBluetoothAdapterClient() |
| 787 ->GetProperties(object_path_); |
| 772 | 788 |
| 773 PresentChanged(true); | 789 PresentChanged(true); |
| 774 | 790 |
| 775 if (properties->powered.value()) | 791 if (properties->powered.value()) |
| 776 PoweredChanged(true); | 792 PoweredChanged(true); |
| 777 if (properties->discoverable.value()) | 793 if (properties->discoverable.value()) |
| 778 DiscoverableChanged(true); | 794 DiscoverableChanged(true); |
| 779 if (properties->discovering.value()) | 795 if (properties->discovering.value()) |
| 780 DiscoveringChanged(true); | 796 DiscoveringChanged(true); |
| 781 | 797 |
| 782 std::vector<dbus::ObjectPath> device_paths = | 798 std::vector<dbus::ObjectPath> device_paths = |
| 783 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 799 bluez::BluezDBusManager::Get() |
| 784 GetDevicesForAdapter(object_path_); | 800 ->GetBluetoothDeviceClient() |
| 801 ->GetDevicesForAdapter(object_path_); |
| 785 | 802 |
| 786 for (std::vector<dbus::ObjectPath>::iterator iter = device_paths.begin(); | 803 for (std::vector<dbus::ObjectPath>::iterator iter = device_paths.begin(); |
| 787 iter != device_paths.end(); ++iter) { | 804 iter != device_paths.end(); ++iter) { |
| 788 DeviceAdded(*iter); | 805 DeviceAdded(*iter); |
| 789 } | 806 } |
| 790 } | 807 } |
| 791 | 808 |
| 792 void BluetoothAdapterChromeOS::SetDefaultAdapterName() { | 809 void BluetoothAdapterChromeOS::SetDefaultAdapterName() { |
| 793 DCHECK(IsPresent()); | 810 DCHECK(IsPresent()); |
| 794 | 811 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 811 break; | 828 break; |
| 812 } | 829 } |
| 813 | 830 |
| 814 SetName(alias, base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); | 831 SetName(alias, base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); |
| 815 } | 832 } |
| 816 | 833 |
| 817 void BluetoothAdapterChromeOS::RemoveAdapter() { | 834 void BluetoothAdapterChromeOS::RemoveAdapter() { |
| 818 DCHECK(IsPresent()); | 835 DCHECK(IsPresent()); |
| 819 VLOG(1) << object_path_.value() << ": adapter removed."; | 836 VLOG(1) << object_path_.value() << ": adapter removed."; |
| 820 | 837 |
| 821 BluetoothAdapterClient::Properties* properties = | 838 bluez::BluetoothAdapterClient::Properties* properties = |
| 822 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 839 bluez::BluezDBusManager::Get() |
| 823 GetProperties(object_path_); | 840 ->GetBluetoothAdapterClient() |
| 841 ->GetProperties(object_path_); |
| 824 | 842 |
| 825 object_path_ = dbus::ObjectPath(""); | 843 object_path_ = dbus::ObjectPath(""); |
| 826 | 844 |
| 827 if (properties->powered.value()) | 845 if (properties->powered.value()) |
| 828 PoweredChanged(false); | 846 PoweredChanged(false); |
| 829 if (properties->discoverable.value()) | 847 if (properties->discoverable.value()) |
| 830 DiscoverableChanged(false); | 848 DiscoverableChanged(false); |
| 831 if (properties->discovering.value()) | 849 if (properties->discovering.value()) |
| 832 DiscoveringChanged(false); | 850 DiscoveringChanged(false); |
| 833 | 851 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 this); | 1019 this); |
| 1002 | 1020 |
| 1003 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 1021 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, |
| 1004 observers_, | 1022 observers_, |
| 1005 GattDescriptorValueChanged(this, descriptor, value)); | 1023 GattDescriptorValueChanged(this, descriptor, value)); |
| 1006 } | 1024 } |
| 1007 | 1025 |
| 1008 void BluetoothAdapterChromeOS::UseProfile( | 1026 void BluetoothAdapterChromeOS::UseProfile( |
| 1009 const BluetoothUUID& uuid, | 1027 const BluetoothUUID& uuid, |
| 1010 const dbus::ObjectPath& device_path, | 1028 const dbus::ObjectPath& device_path, |
| 1011 const BluetoothProfileManagerClient::Options& options, | 1029 const bluez::BluetoothProfileManagerClient::Options& options, |
| 1012 BluetoothProfileServiceProvider::Delegate* delegate, | 1030 bluez::BluetoothProfileServiceProvider::Delegate* delegate, |
| 1013 const ProfileRegisteredCallback& success_callback, | 1031 const ProfileRegisteredCallback& success_callback, |
| 1014 const ErrorCompletionCallback& error_callback) { | 1032 const ErrorCompletionCallback& error_callback) { |
| 1015 DCHECK(delegate); | 1033 DCHECK(delegate); |
| 1016 | 1034 |
| 1017 if (!IsPresent()) { | 1035 if (!IsPresent()) { |
| 1018 VLOG(2) << "Adapter not present, erroring out"; | 1036 VLOG(2) << "Adapter not present, erroring out"; |
| 1019 error_callback.Run("Adapter not present"); | 1037 error_callback.Run("Adapter not present"); |
| 1020 return; | 1038 return; |
| 1021 } | 1039 } |
| 1022 | 1040 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 | 1091 |
| 1074 for (auto& it : *profile_queues_[uuid]) | 1092 for (auto& it : *profile_queues_[uuid]) |
| 1075 it.first.Run(); | 1093 it.first.Run(); |
| 1076 delete profile_queues_[uuid]; | 1094 delete profile_queues_[uuid]; |
| 1077 profile_queues_.erase(uuid); | 1095 profile_queues_.erase(uuid); |
| 1078 } | 1096 } |
| 1079 | 1097 |
| 1080 void BluetoothAdapterChromeOS::SetProfileDelegate( | 1098 void BluetoothAdapterChromeOS::SetProfileDelegate( |
| 1081 const BluetoothUUID& uuid, | 1099 const BluetoothUUID& uuid, |
| 1082 const dbus::ObjectPath& device_path, | 1100 const dbus::ObjectPath& device_path, |
| 1083 BluetoothProfileServiceProvider::Delegate* delegate, | 1101 bluez::BluetoothProfileServiceProvider::Delegate* delegate, |
| 1084 const ProfileRegisteredCallback& success_callback, | 1102 const ProfileRegisteredCallback& success_callback, |
| 1085 const ErrorCompletionCallback& error_callback) { | 1103 const ErrorCompletionCallback& error_callback) { |
| 1086 if (profiles_.find(uuid) == profiles_.end()) { | 1104 if (profiles_.find(uuid) == profiles_.end()) { |
| 1087 error_callback.Run("Cannot find profile!"); | 1105 error_callback.Run("Cannot find profile!"); |
| 1088 return; | 1106 return; |
| 1089 } | 1107 } |
| 1090 | 1108 |
| 1091 if (profiles_[uuid]->SetDelegate(device_path, delegate)) { | 1109 if (profiles_[uuid]->SetDelegate(device_path, delegate)) { |
| 1092 success_callback.Run(profiles_[uuid]); | 1110 success_callback.Run(profiles_[uuid]); |
| 1093 return; | 1111 return; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1116 const base::Closure& callback, | 1134 const base::Closure& callback, |
| 1117 const ErrorCallback& error_callback, | 1135 const ErrorCallback& error_callback, |
| 1118 bool success) { | 1136 bool success) { |
| 1119 if (!IsPresent()) { | 1137 if (!IsPresent()) { |
| 1120 error_callback.Run(); | 1138 error_callback.Run(); |
| 1121 return; | 1139 return; |
| 1122 } | 1140 } |
| 1123 | 1141 |
| 1124 // Set the discoverable_timeout property to zero so the adapter remains | 1142 // Set the discoverable_timeout property to zero so the adapter remains |
| 1125 // discoverable forever. | 1143 // discoverable forever. |
| 1126 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 1144 bluez::BluezDBusManager::Get() |
| 1127 GetProperties(object_path_)->discoverable_timeout.Set( | 1145 ->GetBluetoothAdapterClient() |
| 1146 ->GetProperties(object_path_) |
| 1147 ->discoverable_timeout.Set( |
| 1128 0, | 1148 0, |
| 1129 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, | 1149 base::Bind(&BluetoothAdapterChromeOS::OnPropertyChangeCompleted, |
| 1130 weak_ptr_factory_.GetWeakPtr(), | 1150 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 1131 callback, | |
| 1132 error_callback)); | |
| 1133 } | 1151 } |
| 1134 | 1152 |
| 1135 void BluetoothAdapterChromeOS::OnPropertyChangeCompleted( | 1153 void BluetoothAdapterChromeOS::OnPropertyChangeCompleted( |
| 1136 const base::Closure& callback, | 1154 const base::Closure& callback, |
| 1137 const ErrorCallback& error_callback, | 1155 const ErrorCallback& error_callback, |
| 1138 bool success) { | 1156 bool success) { |
| 1139 if (IsPresent() && success) { | 1157 if (IsPresent() && success) { |
| 1140 callback.Run(); | 1158 callback.Run(); |
| 1141 } else { | 1159 } else { |
| 1142 error_callback.Run(); | 1160 error_callback.Run(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 1208 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
| 1191 base::Bind(&BluetoothAdapterChromeOS::OnPreSetDiscoveryFilterError, | 1209 base::Bind(&BluetoothAdapterChromeOS::OnPreSetDiscoveryFilterError, |
| 1192 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1210 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 1193 return; | 1211 return; |
| 1194 } else { | 1212 } else { |
| 1195 current_filter_.reset(); | 1213 current_filter_.reset(); |
| 1196 } | 1214 } |
| 1197 | 1215 |
| 1198 // This is the first request to start device discovery. | 1216 // This is the first request to start device discovery. |
| 1199 discovery_request_pending_ = true; | 1217 discovery_request_pending_ = true; |
| 1200 DBusThreadManager::Get()->GetBluetoothAdapterClient()->StartDiscovery( | 1218 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StartDiscovery( |
| 1201 object_path_, | 1219 object_path_, |
| 1202 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscovery, | 1220 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscovery, |
| 1203 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 1221 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
| 1204 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscoveryError, | 1222 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscoveryError, |
| 1205 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1223 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 1206 } | 1224 } |
| 1207 | 1225 |
| 1208 void BluetoothAdapterChromeOS::RemoveDiscoverySession( | 1226 void BluetoothAdapterChromeOS::RemoveDiscoverySession( |
| 1209 BluetoothDiscoveryFilter* discovery_filter, | 1227 BluetoothDiscoveryFilter* discovery_filter, |
| 1210 const base::Closure& callback, | 1228 const base::Closure& callback, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1244 VLOG(1) << "No active discovery sessions. Returning error."; | 1262 VLOG(1) << "No active discovery sessions. Returning error."; |
| 1245 error_callback.Run( | 1263 error_callback.Run( |
| 1246 UMABluetoothDiscoverySessionOutcome::ACTIVE_SESSION_NOT_IN_ADAPTER); | 1264 UMABluetoothDiscoverySessionOutcome::ACTIVE_SESSION_NOT_IN_ADAPTER); |
| 1247 return; | 1265 return; |
| 1248 } | 1266 } |
| 1249 | 1267 |
| 1250 // There is exactly one active discovery session. Request BlueZ to stop | 1268 // There is exactly one active discovery session. Request BlueZ to stop |
| 1251 // discovery. | 1269 // discovery. |
| 1252 DCHECK_EQ(num_discovery_sessions_, 1); | 1270 DCHECK_EQ(num_discovery_sessions_, 1); |
| 1253 discovery_request_pending_ = true; | 1271 discovery_request_pending_ = true; |
| 1254 DBusThreadManager::Get()->GetBluetoothAdapterClient()-> | 1272 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StopDiscovery( |
| 1255 StopDiscovery( | 1273 object_path_, base::Bind(&BluetoothAdapterChromeOS::OnStopDiscovery, |
| 1256 object_path_, | 1274 weak_ptr_factory_.GetWeakPtr(), callback), |
| 1257 base::Bind(&BluetoothAdapterChromeOS::OnStopDiscovery, | 1275 base::Bind(&BluetoothAdapterChromeOS::OnStopDiscoveryError, |
| 1258 weak_ptr_factory_.GetWeakPtr(), | 1276 weak_ptr_factory_.GetWeakPtr(), error_callback)); |
| 1259 callback), | |
| 1260 base::Bind(&BluetoothAdapterChromeOS::OnStopDiscoveryError, | |
| 1261 weak_ptr_factory_.GetWeakPtr(), | |
| 1262 error_callback)); | |
| 1263 } | 1277 } |
| 1264 | 1278 |
| 1265 void BluetoothAdapterChromeOS::SetDiscoveryFilter( | 1279 void BluetoothAdapterChromeOS::SetDiscoveryFilter( |
| 1266 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, | 1280 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter, |
| 1267 const base::Closure& callback, | 1281 const base::Closure& callback, |
| 1268 const DiscoverySessionErrorCallback& error_callback) { | 1282 const DiscoverySessionErrorCallback& error_callback) { |
| 1269 if (!IsPresent()) { | 1283 if (!IsPresent()) { |
| 1270 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); | 1284 error_callback.Run(UMABluetoothDiscoverySessionOutcome::ADAPTER_REMOVED); |
| 1271 return; | 1285 return; |
| 1272 } | 1286 } |
| 1273 | 1287 |
| 1274 // If old and new filter are equal (null) then don't make request, just call | 1288 // If old and new filter are equal (null) then don't make request, just call |
| 1275 // succes callback | 1289 // succes callback |
| 1276 if (!current_filter_ && !discovery_filter.get()) { | 1290 if (!current_filter_ && !discovery_filter.get()) { |
| 1277 callback.Run(); | 1291 callback.Run(); |
| 1278 return; | 1292 return; |
| 1279 } | 1293 } |
| 1280 | 1294 |
| 1281 // If old and new filter are not null and equal then don't make request, just | 1295 // If old and new filter are not null and equal then don't make request, just |
| 1282 // call succes callback | 1296 // call succes callback |
| 1283 if (current_filter_ && discovery_filter && | 1297 if (current_filter_ && discovery_filter && |
| 1284 current_filter_->Equals(*discovery_filter)) { | 1298 current_filter_->Equals(*discovery_filter)) { |
| 1285 callback.Run(); | 1299 callback.Run(); |
| 1286 return; | 1300 return; |
| 1287 } | 1301 } |
| 1288 | 1302 |
| 1289 current_filter_.reset(discovery_filter.release()); | 1303 current_filter_.reset(discovery_filter.release()); |
| 1290 | 1304 |
| 1291 chromeos::BluetoothAdapterClient::DiscoveryFilter dbus_discovery_filter; | 1305 bluez::BluetoothAdapterClient::DiscoveryFilter dbus_discovery_filter; |
| 1292 | 1306 |
| 1293 if (current_filter_.get()) { | 1307 if (current_filter_.get()) { |
| 1294 uint16_t pathloss; | 1308 uint16_t pathloss; |
| 1295 int16_t rssi; | 1309 int16_t rssi; |
| 1296 uint8_t transport; | 1310 uint8_t transport; |
| 1297 std::set<device::BluetoothUUID> uuids; | 1311 std::set<device::BluetoothUUID> uuids; |
| 1298 | 1312 |
| 1299 if (current_filter_->GetPathloss(&pathloss)) | 1313 if (current_filter_->GetPathloss(&pathloss)) |
| 1300 dbus_discovery_filter.pathloss.reset(new uint16_t(pathloss)); | 1314 dbus_discovery_filter.pathloss.reset(new uint16_t(pathloss)); |
| 1301 | 1315 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1316 current_filter_->GetUUIDs(uuids); | 1330 current_filter_->GetUUIDs(uuids); |
| 1317 if (uuids.size()) { | 1331 if (uuids.size()) { |
| 1318 dbus_discovery_filter.uuids = | 1332 dbus_discovery_filter.uuids = |
| 1319 scoped_ptr<std::vector<std::string>>(new std::vector<std::string>); | 1333 scoped_ptr<std::vector<std::string>>(new std::vector<std::string>); |
| 1320 | 1334 |
| 1321 for (const auto& it : uuids) | 1335 for (const auto& it : uuids) |
| 1322 dbus_discovery_filter.uuids.get()->push_back(it.value()); | 1336 dbus_discovery_filter.uuids.get()->push_back(it.value()); |
| 1323 } | 1337 } |
| 1324 } | 1338 } |
| 1325 | 1339 |
| 1326 DBusThreadManager::Get()->GetBluetoothAdapterClient()->SetDiscoveryFilter( | 1340 bluez::BluezDBusManager::Get() |
| 1327 object_path_, dbus_discovery_filter, | 1341 ->GetBluetoothAdapterClient() |
| 1328 base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoveryFilter, | 1342 ->SetDiscoveryFilter( |
| 1329 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 1343 object_path_, dbus_discovery_filter, |
| 1330 base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoveryFilterError, | 1344 base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoveryFilter, |
| 1331 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1345 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
| 1346 base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoveryFilterError, |
| 1347 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 1332 } | 1348 } |
| 1333 | 1349 |
| 1334 void BluetoothAdapterChromeOS::OnStartDiscovery( | 1350 void BluetoothAdapterChromeOS::OnStartDiscovery( |
| 1335 const base::Closure& callback, | 1351 const base::Closure& callback, |
| 1336 const DiscoverySessionErrorCallback& error_callback) { | 1352 const DiscoverySessionErrorCallback& error_callback) { |
| 1337 // Report success on the original request and increment the count. | 1353 // Report success on the original request and increment the count. |
| 1338 VLOG(1) << __func__; | 1354 VLOG(1) << __func__; |
| 1339 DCHECK(discovery_request_pending_); | 1355 DCHECK(discovery_request_pending_); |
| 1340 DCHECK_EQ(num_discovery_sessions_, 0); | 1356 DCHECK_EQ(num_discovery_sessions_, 0); |
| 1341 discovery_request_pending_ = false; | 1357 discovery_request_pending_ = false; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1411 ProcessQueuedDiscoveryRequests(); | 1427 ProcessQueuedDiscoveryRequests(); |
| 1412 } | 1428 } |
| 1413 | 1429 |
| 1414 void BluetoothAdapterChromeOS::OnPreSetDiscoveryFilter( | 1430 void BluetoothAdapterChromeOS::OnPreSetDiscoveryFilter( |
| 1415 const base::Closure& callback, | 1431 const base::Closure& callback, |
| 1416 const DiscoverySessionErrorCallback& error_callback) { | 1432 const DiscoverySessionErrorCallback& error_callback) { |
| 1417 // This is the first request to start device discovery. | 1433 // This is the first request to start device discovery. |
| 1418 DCHECK(discovery_request_pending_); | 1434 DCHECK(discovery_request_pending_); |
| 1419 DCHECK_EQ(num_discovery_sessions_, 0); | 1435 DCHECK_EQ(num_discovery_sessions_, 0); |
| 1420 | 1436 |
| 1421 DBusThreadManager::Get()->GetBluetoothAdapterClient()->StartDiscovery( | 1437 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StartDiscovery( |
| 1422 object_path_, | 1438 object_path_, |
| 1423 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscovery, | 1439 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscovery, |
| 1424 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), | 1440 weak_ptr_factory_.GetWeakPtr(), callback, error_callback), |
| 1425 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscoveryError, | 1441 base::Bind(&BluetoothAdapterChromeOS::OnStartDiscoveryError, |
| 1426 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | 1442 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); |
| 1427 } | 1443 } |
| 1428 | 1444 |
| 1429 void BluetoothAdapterChromeOS::OnPreSetDiscoveryFilterError( | 1445 void BluetoothAdapterChromeOS::OnPreSetDiscoveryFilterError( |
| 1430 const base::Closure& callback, | 1446 const base::Closure& callback, |
| 1431 const DiscoverySessionErrorCallback& error_callback, | 1447 const DiscoverySessionErrorCallback& error_callback, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 | 1506 |
| 1491 // If the queued request resulted in a pending call, then let it | 1507 // If the queued request resulted in a pending call, then let it |
| 1492 // asynchonously process the remaining queued requests once the pending | 1508 // asynchonously process the remaining queued requests once the pending |
| 1493 // call returns. | 1509 // call returns. |
| 1494 if (discovery_request_pending_) | 1510 if (discovery_request_pending_) |
| 1495 return; | 1511 return; |
| 1496 } | 1512 } |
| 1497 } | 1513 } |
| 1498 | 1514 |
| 1499 } // namespace chromeos | 1515 } // namespace chromeos |
| OLD | NEW |