summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/bluetooth_adapter_chromeos.cc
diff options
context:
space:
mode:
Diffstat (limited to 'device/bluetooth/bluetooth_adapter_chromeos.cc')
-rw-r--r--device/bluetooth/bluetooth_adapter_chromeos.cc179
1 files changed, 99 insertions, 80 deletions
diff --git a/device/bluetooth/bluetooth_adapter_chromeos.cc b/device/bluetooth/bluetooth_adapter_chromeos.cc
index 70ec7fb..55d0bef 100644
--- a/device/bluetooth/bluetooth_adapter_chromeos.cc
+++ b/device/bluetooth/bluetooth_adapter_chromeos.cc
@@ -13,12 +13,6 @@
#include "base/sequenced_task_runner.h"
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
-#include "chromeos/dbus/bluetooth_adapter_client.h"
-#include "chromeos/dbus/bluetooth_agent_manager_client.h"
-#include "chromeos/dbus/bluetooth_agent_service_provider.h"
-#include "chromeos/dbus/bluetooth_device_client.h"
-#include "chromeos/dbus/bluetooth_input_client.h"
-#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/system/devicetype.h"
#include "device/bluetooth/bluetooth_adapter_profile_chromeos.h"
#include "device/bluetooth/bluetooth_advertisement_chromeos.h"
@@ -33,6 +27,12 @@
#include "device/bluetooth/bluetooth_socket_chromeos.h"
#include "device/bluetooth/bluetooth_socket_thread.h"
#include "device/bluetooth/bluetooth_uuid.h"
+#include "device/bluetooth/dbus/bluetooth_adapter_client.h"
+#include "device/bluetooth/dbus/bluetooth_agent_manager_client.h"
+#include "device/bluetooth/dbus/bluetooth_agent_service_provider.h"
+#include "device/bluetooth/dbus/bluetooth_device_client.h"
+#include "device/bluetooth/dbus/bluetooth_input_client.h"
+#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
using device::BluetoothAdapter;
@@ -61,9 +61,9 @@ void OnUnregisterAgentError(const std::string& error_name,
UMABluetoothDiscoverySessionOutcome TranslateDiscoveryErrorToUMA(
const std::string& error_name) {
- if (error_name == chromeos::BluetoothAdapterClient::kUnknownAdapterError) {
+ if (error_name == bluez::BluetoothAdapterClient::kUnknownAdapterError) {
return UMABluetoothDiscoverySessionOutcome::CHROMEOS_DBUS_UNKNOWN_ADAPTER;
- } else if (error_name == chromeos::BluetoothAdapterClient::kNoResponseError) {
+ } else if (error_name == bluez::BluetoothAdapterClient::kNoResponseError) {
return UMABluetoothDiscoverySessionOutcome::CHROMEOS_DBUS_NO_RESPONSE;
} else if (error_name == bluetooth_device::kErrorInProgress) {
return UMABluetoothDiscoverySessionOutcome::CHROMEOS_DBUS_IN_PROGRESS;
@@ -100,9 +100,9 @@ base::WeakPtr<BluetoothAdapter> BluetoothAdapterChromeOS::CreateAdapter() {
void BluetoothAdapterChromeOS::Shutdown() {
if (dbus_is_shutdown_)
return;
- DCHECK(DBusThreadManager::IsInitialized())
+ DCHECK(bluez::BluezDBusManager::IsInitialized())
<< "Call BluetoothAdapterFactory::Shutdown() before "
- "DBusThreadManager::Shutdown().";
+ "BluezDBusManager::Shutdown().";
if (IsPresent())
RemoveAdapter(); // Also deletes devices_.
@@ -115,14 +115,19 @@ void BluetoothAdapterChromeOS::Shutdown() {
delete it.second;
profile_queues_.clear();
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->RemoveObserver(this);
- DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this);
- DBusThreadManager::Get()->GetBluetoothInputClient()->RemoveObserver(this);
+ bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->RemoveObserver(
+ this);
+ bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(
+ this);
+ bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->RemoveObserver(
+ this);
VLOG(1) << "Unregistering pairing agent";
- DBusThreadManager::Get()->GetBluetoothAgentManagerClient()->UnregisterAgent(
- dbus::ObjectPath(kAgentPath), base::Bind(&base::DoNothing),
- base::Bind(&OnUnregisterAgentError));
+ bluez::BluezDBusManager::Get()
+ ->GetBluetoothAgentManagerClient()
+ ->UnregisterAgent(dbus::ObjectPath(kAgentPath),
+ base::Bind(&base::DoNothing),
+ base::Bind(&OnUnregisterAgentError));
agent_.reset();
dbus_is_shutdown_ = true;
@@ -136,18 +141,20 @@ BluetoothAdapterChromeOS::BluetoothAdapterChromeOS()
ui_task_runner_ = base::ThreadTaskRunnerHandle::Get();
socket_thread_ = device::BluetoothSocketThread::Get();
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->AddObserver(this);
- DBusThreadManager::Get()->GetBluetoothDeviceClient()->AddObserver(this);
- DBusThreadManager::Get()->GetBluetoothInputClient()->AddObserver(this);
+ bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->AddObserver(
+ this);
+ bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->AddObserver(this);
+ bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->AddObserver(this);
// Register the pairing agent.
- dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus();
- agent_.reset(BluetoothAgentServiceProvider::Create(
+ dbus::Bus* system_bus = bluez::BluezDBusManager::Get()->GetSystemBus();
+ agent_.reset(bluez::BluetoothAgentServiceProvider::Create(
system_bus, dbus::ObjectPath(kAgentPath), this));
DCHECK(agent_.get());
- std::vector<dbus::ObjectPath> object_paths =
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->GetAdapters();
+ std::vector<dbus::ObjectPath> object_paths = bluez::BluezDBusManager::Get()
+ ->GetBluetoothAdapterClient()
+ ->GetAdapters();
if (!object_paths.empty()) {
VLOG(1) << object_paths.size() << " Bluetooth adapter(s) available.";
@@ -163,9 +170,10 @@ std::string BluetoothAdapterChromeOS::GetAddress() const {
if (!IsPresent())
return std::string();
- BluetoothAdapterClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->GetProperties(
- object_path_);
+ bluez::BluetoothAdapterClient::Properties* properties =
+ bluez::BluezDBusManager::Get()
+ ->GetBluetoothAdapterClient()
+ ->GetProperties(object_path_);
DCHECK(properties);
return BluetoothDevice::CanonicalizeAddress(properties->address.value());
@@ -175,9 +183,10 @@ std::string BluetoothAdapterChromeOS::GetName() const {
if (!IsPresent())
return std::string();
- BluetoothAdapterClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->GetProperties(
- object_path_);
+ bluez::BluetoothAdapterClient::Properties* properties =
+ bluez::BluezDBusManager::Get()
+ ->GetBluetoothAdapterClient()
+ ->GetProperties(object_path_);
DCHECK(properties);
return properties->alias.value();
@@ -191,7 +200,7 @@ void BluetoothAdapterChromeOS::SetName(const std::string& name,
return;
}
- DBusThreadManager::Get()
+ bluez::BluezDBusManager::Get()
->GetBluetoothAdapterClient()
->GetProperties(object_path_)
->alias.Set(
@@ -212,9 +221,10 @@ bool BluetoothAdapterChromeOS::IsPowered() const {
if (!IsPresent())
return false;
- BluetoothAdapterClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->GetProperties(
- object_path_);
+ bluez::BluetoothAdapterClient::Properties* properties =
+ bluez::BluezDBusManager::Get()
+ ->GetBluetoothAdapterClient()
+ ->GetProperties(object_path_);
return properties->powered.value();
}
@@ -228,7 +238,7 @@ void BluetoothAdapterChromeOS::SetPowered(
return;
}
- DBusThreadManager::Get()
+ bluez::BluezDBusManager::Get()
->GetBluetoothAdapterClient()
->GetProperties(object_path_)
->powered.Set(
@@ -241,9 +251,10 @@ bool BluetoothAdapterChromeOS::IsDiscoverable() const {
if (!IsPresent())
return false;
- BluetoothAdapterClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->GetProperties(
- object_path_);
+ bluez::BluetoothAdapterClient::Properties* properties =
+ bluez::BluezDBusManager::Get()
+ ->GetBluetoothAdapterClient()
+ ->GetProperties(object_path_);
return properties->discoverable.value();
}
@@ -257,7 +268,7 @@ void BluetoothAdapterChromeOS::SetDiscoverable(
return;
}
- DBusThreadManager::Get()
+ bluez::BluezDBusManager::Get()
->GetBluetoothAdapterClient()
->GetProperties(object_path_)
->discoverable.Set(
@@ -270,9 +281,10 @@ bool BluetoothAdapterChromeOS::IsDiscovering() const {
if (!IsPresent())
return false;
- BluetoothAdapterClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->GetProperties(
- object_path_);
+ bluez::BluetoothAdapterClient::Properties* properties =
+ bluez::BluezDBusManager::Get()
+ ->GetBluetoothAdapterClient()
+ ->GetProperties(object_path_);
return properties->discovering.value();
}
@@ -377,9 +389,10 @@ void BluetoothAdapterChromeOS::AdapterPropertyChanged(
return;
DCHECK(IsPresent());
- BluetoothAdapterClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->GetProperties(
- object_path_);
+ bluez::BluetoothAdapterClient::Properties* properties =
+ bluez::BluezDBusManager::Get()
+ ->GetBluetoothAdapterClient()
+ ->GetProperties(object_path_);
if (property_name == properties->powered.name()) {
PoweredChanged(properties->powered.value());
@@ -392,9 +405,9 @@ void BluetoothAdapterChromeOS::AdapterPropertyChanged(
void BluetoothAdapterChromeOS::DeviceAdded(
const dbus::ObjectPath& object_path) {
- DCHECK(DBusThreadManager::Get());
- BluetoothDeviceClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties(
+ DCHECK(bluez::BluezDBusManager::Get());
+ bluez::BluetoothDeviceClient::Properties* properties =
+ bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
object_path);
if (!properties || properties->adapter.value() != object_path_)
return;
@@ -438,8 +451,8 @@ void BluetoothAdapterChromeOS::DevicePropertyChanged(
if (!device_chromeos)
return;
- BluetoothDeviceClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothDeviceClient()->GetProperties(
+ bluez::BluetoothDeviceClient::Properties* properties =
+ bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
object_path);
if (property_name == properties->address.name()) {
@@ -513,8 +526,8 @@ void BluetoothAdapterChromeOS::InputPropertyChanged(
if (!device_chromeos)
return;
- BluetoothInputClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothInputClient()->GetProperties(
+ bluez::BluetoothInputClient::Properties* properties =
+ bluez::BluezDBusManager::Get()->GetBluetoothInputClient()->GetProperties(
object_path);
// Properties structure can be removed, which triggers a change in the
@@ -672,7 +685,7 @@ void BluetoothAdapterChromeOS::Cancel() {
void BluetoothAdapterChromeOS::OnRegisterAgent() {
VLOG(1) << "Pairing agent registered, requesting to be made default";
- DBusThreadManager::Get()
+ bluez::BluezDBusManager::Get()
->GetBluetoothAgentManagerClient()
->RequestDefaultAgent(
dbus::ObjectPath(kAgentPath),
@@ -765,19 +778,22 @@ void BluetoothAdapterChromeOS::SetAdapter(const dbus::ObjectPath& object_path) {
VLOG(1) << object_path_.value() << ": using adapter.";
VLOG(1) << "Registering pairing agent";
- DBusThreadManager::Get()->GetBluetoothAgentManagerClient()->RegisterAgent(
- dbus::ObjectPath(kAgentPath),
- bluetooth_agent_manager::kKeyboardDisplayCapability,
- base::Bind(&BluetoothAdapterChromeOS::OnRegisterAgent,
- weak_ptr_factory_.GetWeakPtr()),
- base::Bind(&BluetoothAdapterChromeOS::OnRegisterAgentError,
- weak_ptr_factory_.GetWeakPtr()));
+ bluez::BluezDBusManager::Get()
+ ->GetBluetoothAgentManagerClient()
+ ->RegisterAgent(
+ dbus::ObjectPath(kAgentPath),
+ bluetooth_agent_manager::kKeyboardDisplayCapability,
+ base::Bind(&BluetoothAdapterChromeOS::OnRegisterAgent,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(&BluetoothAdapterChromeOS::OnRegisterAgentError,
+ weak_ptr_factory_.GetWeakPtr()));
SetDefaultAdapterName();
- BluetoothAdapterClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->GetProperties(
- object_path_);
+ bluez::BluetoothAdapterClient::Properties* properties =
+ bluez::BluezDBusManager::Get()
+ ->GetBluetoothAdapterClient()
+ ->GetProperties(object_path_);
PresentChanged(true);
@@ -789,7 +805,7 @@ void BluetoothAdapterChromeOS::SetAdapter(const dbus::ObjectPath& object_path) {
DiscoveringChanged(true);
std::vector<dbus::ObjectPath> device_paths =
- DBusThreadManager::Get()
+ bluez::BluezDBusManager::Get()
->GetBluetoothDeviceClient()
->GetDevicesForAdapter(object_path_);
@@ -828,9 +844,10 @@ void BluetoothAdapterChromeOS::RemoveAdapter() {
DCHECK(IsPresent());
VLOG(1) << object_path_.value() << ": adapter removed.";
- BluetoothAdapterClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->GetProperties(
- object_path_);
+ bluez::BluetoothAdapterClient::Properties* properties =
+ bluez::BluezDBusManager::Get()
+ ->GetBluetoothAdapterClient()
+ ->GetProperties(object_path_);
object_path_ = dbus::ObjectPath("");
@@ -1025,8 +1042,8 @@ void BluetoothAdapterChromeOS::NotifyGattDescriptorValueChanged(
void BluetoothAdapterChromeOS::UseProfile(
const BluetoothUUID& uuid,
const dbus::ObjectPath& device_path,
- const BluetoothProfileManagerClient::Options& options,
- BluetoothProfileServiceProvider::Delegate* delegate,
+ const bluez::BluetoothProfileManagerClient::Options& options,
+ bluez::BluetoothProfileServiceProvider::Delegate* delegate,
const ProfileRegisteredCallback& success_callback,
const ErrorCompletionCallback& error_callback) {
DCHECK(delegate);
@@ -1097,7 +1114,7 @@ void BluetoothAdapterChromeOS::OnRegisterProfile(
void BluetoothAdapterChromeOS::SetProfileDelegate(
const BluetoothUUID& uuid,
const dbus::ObjectPath& device_path,
- BluetoothProfileServiceProvider::Delegate* delegate,
+ bluez::BluetoothProfileServiceProvider::Delegate* delegate,
const ProfileRegisteredCallback& success_callback,
const ErrorCompletionCallback& error_callback) {
if (profiles_.find(uuid) == profiles_.end()) {
@@ -1140,7 +1157,7 @@ void BluetoothAdapterChromeOS::OnSetDiscoverable(
// Set the discoverable_timeout property to zero so the adapter remains
// discoverable forever.
- DBusThreadManager::Get()
+ bluez::BluezDBusManager::Get()
->GetBluetoothAdapterClient()
->GetProperties(object_path_)
->discoverable_timeout.Set(
@@ -1214,7 +1231,7 @@ void BluetoothAdapterChromeOS::AddDiscoverySession(
// This is the first request to start device discovery.
discovery_request_pending_ = true;
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->StartDiscovery(
+ bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StartDiscovery(
object_path_,
base::Bind(&BluetoothAdapterChromeOS::OnStartDiscovery,
weak_ptr_factory_.GetWeakPtr(), callback, error_callback),
@@ -1268,7 +1285,7 @@ void BluetoothAdapterChromeOS::RemoveDiscoverySession(
// discovery.
DCHECK_EQ(num_discovery_sessions_, 1);
discovery_request_pending_ = true;
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->StopDiscovery(
+ bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StopDiscovery(
object_path_, base::Bind(&BluetoothAdapterChromeOS::OnStopDiscovery,
weak_ptr_factory_.GetWeakPtr(), callback),
base::Bind(&BluetoothAdapterChromeOS::OnStopDiscoveryError,
@@ -1301,7 +1318,7 @@ void BluetoothAdapterChromeOS::SetDiscoveryFilter(
current_filter_.reset(discovery_filter.release());
- chromeos::BluetoothAdapterClient::DiscoveryFilter dbus_discovery_filter;
+ bluez::BluetoothAdapterClient::DiscoveryFilter dbus_discovery_filter;
if (current_filter_.get()) {
uint16_t pathloss;
@@ -1336,12 +1353,14 @@ void BluetoothAdapterChromeOS::SetDiscoveryFilter(
}
}
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->SetDiscoveryFilter(
- object_path_, dbus_discovery_filter,
- base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoveryFilter,
- weak_ptr_factory_.GetWeakPtr(), callback, error_callback),
- base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoveryFilterError,
- weak_ptr_factory_.GetWeakPtr(), callback, error_callback));
+ bluez::BluezDBusManager::Get()
+ ->GetBluetoothAdapterClient()
+ ->SetDiscoveryFilter(
+ object_path_, dbus_discovery_filter,
+ base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoveryFilter,
+ weak_ptr_factory_.GetWeakPtr(), callback, error_callback),
+ base::Bind(&BluetoothAdapterChromeOS::OnSetDiscoveryFilterError,
+ weak_ptr_factory_.GetWeakPtr(), callback, error_callback));
}
void BluetoothAdapterChromeOS::OnStartDiscovery(
@@ -1431,7 +1450,7 @@ void BluetoothAdapterChromeOS::OnPreSetDiscoveryFilter(
DCHECK(discovery_request_pending_);
DCHECK_EQ(num_discovery_sessions_, 0);
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->StartDiscovery(
+ bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()->StartDiscovery(
object_path_,
base::Bind(&BluetoothAdapterChromeOS::OnStartDiscovery,
weak_ptr_factory_.GetWeakPtr(), callback, error_callback),