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

Unified Diff: components/pairing/bluetooth_host_pairing_controller.cc

Issue 552983003: Wait for the Bluetooth adapter to be present before starting pairing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing OVERRIDE Created 6 years, 3 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 | « components/pairing/bluetooth_host_pairing_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/pairing/bluetooth_host_pairing_controller.cc
diff --git a/components/pairing/bluetooth_host_pairing_controller.cc b/components/pairing/bluetooth_host_pairing_controller.cc
index 53a6187eb072ec6058607cc09d48ab2570cd7920..3d62c3ace401f0eafd34b146eb00e1dc0c04e8c1 100644
--- a/components/pairing/bluetooth_host_pairing_controller.cc
+++ b/components/pairing/bluetooth_host_pairing_controller.cc
@@ -26,7 +26,10 @@ BluetoothHostPairingController::BluetoothHostPairingController()
ptr_factory_(this) {
}
-BluetoothHostPairingController::~BluetoothHostPairingController() {}
+BluetoothHostPairingController::~BluetoothHostPairingController() {
+ if (adapter_.get())
+ adapter_->RemoveObserver(this);
+}
void BluetoothHostPairingController::ChangeStage(Stage new_stage) {
if (current_stage_ == new_stage)
@@ -106,9 +109,19 @@ void BluetoothHostPairingController::OnGetAdapter(
DCHECK(!adapter_.get());
adapter_ = adapter;
+ if (adapter_->IsPresent()) {
+ SetName();
+ } else {
+ // Set the name once the adapter is present.
+ adapter_->AddObserver(this);
+ }
+}
+
+void BluetoothHostPairingController::SetName() {
// TODO(zork): Make the device name prettier. (http://crbug.com/405774)
device_name_ = base::StringPrintf("%s%s", kDeviceNamePrefix,
adapter_->GetAddress().c_str());
+
adapter_->SetName(
device_name_,
base::Bind(&BluetoothHostPairingController::OnSetName,
@@ -298,6 +311,16 @@ void BluetoothHostPairingController::OnErrorMessage(
NOTREACHED();
}
+void BluetoothHostPairingController::AdapterPresentChanged(
+ device::BluetoothAdapter* adapter,
+ bool present) {
+ DCHECK_EQ(adapter, adapter_.get());
+ if (present) {
+ adapter_->RemoveObserver(this);
+ SetName();
+ }
+}
+
void BluetoothHostPairingController::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
« no previous file with comments | « components/pairing/bluetooth_host_pairing_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698