Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: device/bluetooth/bluetooth_adapter_chromeos.cc

Issue 188163003: Bluetooth: register agent when we have an adapter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/bluetooth_adapter_chromeos.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_adapter_chromeos.cc
diff --git a/device/bluetooth/bluetooth_adapter_chromeos.cc b/device/bluetooth/bluetooth_adapter_chromeos.cc
index 942f9ae7389c9f02346361cfdcd99fb6048443bb..075b40f9284e6a39d44ea97dd489954c01ded174 100644
--- a/device/bluetooth/bluetooth_adapter_chromeos.cc
+++ b/device/bluetooth/bluetooth_adapter_chromeos.cc
@@ -32,6 +32,10 @@ const char kAgentPath[] = "/org/chromium/bluetooth_agent";
void OnUnregisterAgentError(const std::string& error_name,
const std::string& error_message) {
+ // It's okay if the agent didn't exist, it means we never saw an adapter.
+ if (error_name == bluetooth_agent_manager::kErrorDoesNotExist)
+ return;
+
LOG(WARNING) << "Failed to unregister pairing agent: "
<< error_name << ": " << error_message;
}
@@ -48,6 +52,12 @@ BluetoothAdapterChromeOS::BluetoothAdapterChromeOS()
DBusThreadManager::Get()->GetBluetoothDeviceClient()->AddObserver(this);
DBusThreadManager::Get()->GetBluetoothInputClient()->AddObserver(this);
+ // Register the pairing agent.
+ dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus();
+ agent_.reset(BluetoothAgentServiceProvider::Create(
+ system_bus, dbus::ObjectPath(kAgentPath), this));
+ DCHECK(agent_.get());
+
std::vector<dbus::ObjectPath> object_paths =
DBusThreadManager::Get()->GetBluetoothAdapterClient()->GetAdapters();
@@ -55,22 +65,6 @@ BluetoothAdapterChromeOS::BluetoothAdapterChromeOS()
VLOG(1) << object_paths.size() << " Bluetooth adapter(s) available.";
SetAdapter(object_paths[0]);
}
-
- // Register the pairing agent.
- dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus();
- agent_.reset(BluetoothAgentServiceProvider::Create(
- system_bus, dbus::ObjectPath(kAgentPath), this));
- DCHECK(agent_.get());
-
- 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()));
}
BluetoothAdapterChromeOS::~BluetoothAdapterChromeOS() {
@@ -474,10 +468,12 @@ void BluetoothAdapterChromeOS::OnRegisterAgent() {
void BluetoothAdapterChromeOS::OnRegisterAgentError(
const std::string& error_name,
const std::string& error_message) {
+ // Our agent being already registered isn't an error.
+ if (error_name == bluetooth_agent_manager::kErrorAlreadyExists)
+ return;
+
LOG(WARNING) << ": Failed to register pairing agent: "
<< error_name << ": " << error_message;
-
- agent_.reset();
}
void BluetoothAdapterChromeOS::OnRequestDefaultAgent() {
@@ -534,6 +530,16 @@ 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()));
+
SetDefaultAdapterName();
BluetoothAdapterClient::Properties* properties =
« no previous file with comments | « device/bluetooth/bluetooth_adapter_chromeos.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698