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

Unified Diff: components/pairing/bluetooth_host_pairing_controller.cc

Issue 1942883003: [Chrome OS Bootstrapping]: Do not always power off the Bluetooth adapter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing deps Created 4 years, 8 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
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 98f85b731e3a648dc7614a0314b48fea446a4155..d7fea5d30ff6acc10b1a72075c35e5fb97194235 100644
--- a/components/pairing/bluetooth_host_pairing_controller.cc
+++ b/components/pairing/bluetooth_host_pairing_controller.cc
@@ -12,6 +12,7 @@
#include "components/pairing/bluetooth_pairing_constants.h"
#include "components/pairing/pairing_api.pb.h"
#include "components/pairing/proto_decoder.h"
+#include "content/public/browser/browser_thread.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "net/base/io_buffer.h"
@@ -88,6 +89,13 @@ pairing_api::HostStatusParameters::EnrollmentStatus PairingApiEnrollmentStatus(
}
}
+std::vector<BluetoothHostPairingController::InputDeviceInfo> GetDevices() {
+ std::vector<BluetoothHostPairingController::InputDeviceInfo> devices;
+ if (device::InputServiceLinux::HasInstance())
+ device::InputServiceLinux::GetInstance()->GetDevices(&devices);
+ return devices;
+}
+
} // namespace
BluetoothHostPairingController::BluetoothHostPairingController()
@@ -158,12 +166,11 @@ void BluetoothHostPairingController::Reset() {
adapter_->SetDiscoverable(false, base::Bind(&base::DoNothing),
base::Bind(&base::DoNothing));
}
- if (!was_powered_) {
- adapter_->SetPowered(false, base::Bind(&base::DoNothing),
- base::Bind(&base::DoNothing));
- }
- adapter_->RemoveObserver(this);
- adapter_ = NULL;
+
+ content::BrowserThread::PostTaskAndReplyWithResult(
+ content::BrowserThread::FILE, FROM_HERE, base::Bind(&GetDevices),
achuithb 2016/05/02 23:02:40 BrowserThread::FILE is deprecated, please use Bloc
xdai1 2016/05/03 00:30:26 I'm not sure I should do that.. In https://code.go
+ base::Bind(&BluetoothHostPairingController::PowerOffAdapterIfApplicable,
+ ptr_factory_.GetWeakPtr()));
}
ChangeStage(STAGE_NONE);
}
@@ -322,6 +329,23 @@ void BluetoothHostPairingController::OnSendError(
}
}
+void BluetoothHostPairingController::PowerOffAdapterIfApplicable(
+ const std::vector<InputDeviceInfo>& devices) {
+ bool use_bluetooth = false;
+ for (auto& iter : devices) {
achuithb 2016/05/02 23:02:40 const auto& device The iterator should be const,
xdai1 2016/05/03 00:30:26 Done.
+ if (iter.type == InputDeviceInfo::TYPE_BLUETOOTH) {
+ use_bluetooth = true;
+ break;
+ }
+ }
+ if (!was_powered_ && !use_bluetooth) {
+ adapter_->SetPowered(false, base::Bind(&base::DoNothing),
+ base::Bind(&base::DoNothing));
+ }
+ adapter_->RemoveObserver(this);
+ adapter_ = NULL;
achuithb 2016/05/02 23:02:40 nullptr here and everywhere in this file please
xdai1 2016/05/03 00:30:26 Done.
+}
+
void BluetoothHostPairingController::OnReceiveError(
device::BluetoothSocket::ErrorReason reason,
const std::string& error_message) {

Powered by Google App Engine
This is Rietveld 408576698