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

Unified Diff: chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc

Issue 184953002: Migrate Chrome OS Bluetooth UI to the new discovery API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
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
Index: chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc
diff --git a/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc
index 0be4fc9d14de566cb30d67e0fdbac47926a83358..c61d3bb6554c8a57d4860175c0b5e745b23378f3 100644
--- a/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc
+++ b/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc
@@ -55,20 +55,13 @@ const int kInvalidEntered = 0xFFFF;
namespace chromeos {
namespace options {
-BluetoothOptionsHandler::BluetoothOptionsHandler() :
- discovering_(false),
- pairing_device_passkey_(1000000),
- pairing_device_entered_(kInvalidEntered),
- weak_ptr_factory_(this) {
+BluetoothOptionsHandler::BluetoothOptionsHandler()
+ : pairing_device_passkey_(1000000),
+ pairing_device_entered_(kInvalidEntered),
+ weak_ptr_factory_(this) {
}
BluetoothOptionsHandler::~BluetoothOptionsHandler() {
- if (discovering_) {
- adapter_->StopDiscovering(
- base::Bind(&base::DoNothing),
- base::Bind(&base::DoNothing));
- discovering_ = false;
- }
if (adapter_.get())
adapter_->RemoveObserver(this);
}
@@ -235,13 +228,20 @@ void BluetoothOptionsHandler::EnableChangeError() {
void BluetoothOptionsHandler::FindDevicesCallback(
const base::ListValue* args) {
- if (!discovering_) {
- discovering_ = true;
- adapter_->StartDiscovering(
- base::Bind(&base::DoNothing),
- base::Bind(&BluetoothOptionsHandler::FindDevicesError,
- weak_ptr_factory_.GetWeakPtr()));
+ if (discovery_session_.get() && discovery_session_->IsActive()) {
+ VLOG(1) << "Already have an active discovery session.";
+ return;
}
+ adapter_->StartDiscoverySession(
+ base::Bind(&BluetoothOptionsHandler::OnStartDiscoverySession,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(&BluetoothOptionsHandler::FindDevicesError,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void BluetoothOptionsHandler::OnStartDiscoverySession(
+ scoped_ptr<device::BluetoothDiscoverySession> discovery_session) {
+ discovery_session_ = discovery_session.Pass();
keybuk 2014/02/28 21:29:28 Doesn't this need the same logic as Aura, what if
armansito 2014/02/28 22:52:02 It certainly does. Done.
}
void BluetoothOptionsHandler::FindDevicesError() {
@@ -402,13 +402,14 @@ void BluetoothOptionsHandler::ForgetError(const std::string& address) {
void BluetoothOptionsHandler::StopDiscoveryCallback(
const base::ListValue* args) {
- if (discovering_) {
- adapter_->StopDiscovering(
- base::Bind(&base::DoNothing),
- base::Bind(&BluetoothOptionsHandler::StopDiscoveryError,
- weak_ptr_factory_.GetWeakPtr()));
- discovering_ = false;
+ if (!discovery_session_.get() || !discovery_session_->IsActive()) {
+ VLOG(1) << "No active discovery session.";
+ return;
}
+ discovery_session_->Stop(
+ base::Bind(&base::DoNothing),
+ base::Bind(&BluetoothOptionsHandler::StopDiscoveryError,
+ weak_ptr_factory_.GetWeakPtr()));
}
void BluetoothOptionsHandler::StopDiscoveryError() {

Powered by Google App Engine
This is Rietveld 408576698