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

Unified Diff: device/bluetooth/bluetooth_device_experimental_chromeos.cc

Issue 14225017: Bluetooth: treat unpairable devices as Trusted/Paired (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Forget() change was unneeded, keep the unit test though Created 7 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: device/bluetooth/bluetooth_device_experimental_chromeos.cc
diff --git a/device/bluetooth/bluetooth_device_experimental_chromeos.cc b/device/bluetooth/bluetooth_device_experimental_chromeos.cc
index fb36c8450c43312e928c254f5a19fdd1135a32ea..ce28e0a077cf127867ebf57a93e102796c7ad8e0 100644
--- a/device/bluetooth/bluetooth_device_experimental_chromeos.cc
+++ b/device/bluetooth/bluetooth_device_experimental_chromeos.cc
@@ -74,7 +74,10 @@ bool BluetoothDeviceExperimentalChromeOS::IsPaired() const {
GetProperties(object_path_);
DCHECK(properties);
- return properties->paired.value();
+ // Trusted devices are devices that don't support pairing but that the
+ // user has explicitly connected; it makes no sense for UI purposes to
+ // treat them differently from each other.
+ return properties->paired.value() || properties->trusted.value();
}
bool BluetoothDeviceExperimentalChromeOS::IsConnected() const {
@@ -139,8 +142,8 @@ void BluetoothDeviceExperimentalChromeOS::Connect(
VLOG(1) << object_path_.value() << ": Connecting, " << num_connecting_calls_
<< " in progress";
- if (IsPaired() || IsConnected() || !pairing_delegate) {
- // No need to pair, skip straight to connection.
+ if (IsPaired() || IsConnected() || !pairing_delegate || !IsPairable()) {
+ // No need to pair, or unable to, skip straight to connection.
ConnectInternal(callback, error_callback);
} else {
// Initiate high-security connection with pairing.
@@ -237,14 +240,14 @@ void BluetoothDeviceExperimentalChromeOS::Forget(
const ErrorCallback& error_callback) {
VLOG(1) << object_path_.value() << ": Removing device";
DBusThreadManager::Get()->GetExperimentalBluetoothAdapterClient()->
- RemoveDevice(
- adapter_->object_path_,
- object_path_,
- base::Bind(&base::DoNothing),
- base::Bind(
- &BluetoothDeviceExperimentalChromeOS::OnForgetError,
- weak_ptr_factory_.GetWeakPtr(),
- error_callback));
+ RemoveDevice(
deymo 2013/04/18 18:41:11 This block should have 4-space indentation instead
+ adapter_->object_path_,
+ object_path_,
+ base::Bind(&base::DoNothing),
+ base::Bind(
+ &BluetoothDeviceExperimentalChromeOS::OnForgetError,
+ weak_ptr_factory_.GetWeakPtr(),
+ error_callback));
}
void BluetoothDeviceExperimentalChromeOS::ConnectToService(
@@ -396,6 +399,8 @@ void BluetoothDeviceExperimentalChromeOS::OnConnect(
VLOG(1) << object_path_.value() << ": Connected, " << num_connecting_calls_
<< " still in progress";
+ SetTrusted();
+
callback.Run();
}
@@ -465,21 +470,8 @@ void BluetoothDeviceExperimentalChromeOS::OnPair(
const base::Closure& callback,
const ConnectErrorCallback& error_callback) {
VLOG(1) << object_path_.value() << ": Paired";
-
- // Now that we're paired, we need to set the device as trusted so that
- // incoming connections will be accepted. This should only ever fail if
- // the device is removed mid-pairing, so do it in the background while
- // we connect and don't worry about errors.
- DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()->
- GetProperties(object_path_)->trusted.Set(
- true,
- base::Bind(
- &BluetoothDeviceExperimentalChromeOS::OnSetTrusted,
- weak_ptr_factory_.GetWeakPtr()));
-
UnregisterAgent();
-
- // Now we can connect to the device!
+ SetTrusted();
ConnectInternal(callback, error_callback);
}
@@ -520,9 +512,22 @@ void BluetoothDeviceExperimentalChromeOS::OnCancelPairingError(
<< error_name << ": " << error_message;
}
+void BluetoothDeviceExperimentalChromeOS::SetTrusted() {
+ // Unconditionally send the property change, rather than checking the value
+ // first; there's no harm in doing this and it solves any race conditions
+ // with the property becoming true or false and this call happening before
+ // we get the D-Bus signal about the earlier change.
+ DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()->
+ GetProperties(object_path_)->trusted.Set(
+ true,
+ base::Bind(
+ &BluetoothDeviceExperimentalChromeOS::OnSetTrusted,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
void BluetoothDeviceExperimentalChromeOS::OnSetTrusted(bool success) {
LOG_IF(WARNING, !success) << object_path_.value()
- << ": Failed to set device as trusted";
+ << "Failed to set device as trusted";
deymo 2013/04/18 18:41:11 Please insert a space before "Failed ..." in the o
}
void BluetoothDeviceExperimentalChromeOS::UnregisterAgent() {

Powered by Google App Engine
This is Rietveld 408576698