Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..93da1786de044dfb2e01da1455967c892a96e6bc |
| --- /dev/null |
| +++ b/device/bluetooth/bluetooth_device_experimental_chromeos.cc |
| @@ -0,0 +1,625 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "device/bluetooth/bluetooth_device_experimental_chromeos.h" |
| + |
| +#include "base/bind.h" |
| +#include "chromeos/dbus/dbus_thread_manager.h" |
| +#include "chromeos/dbus/experimental_bluetooth_adapter_client.h" |
| +#include "chromeos/dbus/experimental_bluetooth_agent_manager_client.h" |
| +#include "chromeos/dbus/experimental_bluetooth_agent_service_provider.h" |
| +#include "chromeos/dbus/experimental_bluetooth_device_client.h" |
| +#include "dbus/bus.h" |
| +#include "device/bluetooth/bluetooth_adapter_experimental_chromeos.h" |
| +#include "device/bluetooth/bluetooth_socket.h" |
| +#include "third_party/cros_system_api/dbus/service_constants.h" |
| + |
| +using device::BluetoothDevice; |
| + |
| +namespace { |
| + |
| +// The agent path is relativel meaningless since BlueZ only supports one |
|
youngki
2013/04/16 15:26:56
s/relativel/relatively/
keybuk
2013/04/16 23:19:13
Done.
|
| +// at time and will fail an attempt to register another with "Already Exists" |
|
youngki
2013/04/16 15:26:56
s/fail an attempt/fail in an attempt/
keybuk
2013/04/16 23:19:13
Done.
|
| +// (which we fail in OnRegisterAgentError with ERROR_INPROGRESS). |
| +const dbus::ObjectPath kAgentPath("/org/chromium/bluetooth_agent"); |
|
satorux1
2013/04/16 06:30:45
like haruki mentioned, please use const char
keybuk
2013/04/16 23:19:13
Done.
|
| + |
| +// The capability of our agents. |
| +const char* kAgentCapability = |
|
satorux1
2013/04/16 06:30:45
Can this be defined at a compilation time? otherwi
keybuk
2013/04/16 23:19:13
No
I'll drop this variable entirely and use the o
|
| + bluetooth_agent_manager::kKeyboardDisplayCapability; |
| + |
| +} // namespace |
| + |
| +namespace chromeos { |
| + |
| +BluetoothDeviceExperimentalChromeOS::BluetoothDeviceExperimentalChromeOS( |
| + BluetoothAdapterExperimentalChromeOS* adapter, |
| + const dbus::ObjectPath& object_path) |
| + : adapter_(adapter), |
| + object_path_(object_path), |
| + connecting_calls_(0), |
| + pairing_delegate_(NULL), |
| + weak_ptr_factory_(this) { |
| +} |
| + |
| +BluetoothDeviceExperimentalChromeOS::~BluetoothDeviceExperimentalChromeOS() { |
| +} |
| + |
| +uint32 BluetoothDeviceExperimentalChromeOS::GetBluetoothClass() const { |
| + ExperimentalBluetoothDeviceClient::Properties* properties = |
| + DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> |
| + GetProperties(object_path_); |
| + DCHECK(properties); |
| + |
| + return properties->bluetooth_class.value(); |
| +} |
| + |
| +std::string BluetoothDeviceExperimentalChromeOS::GetDeviceName() const { |
| + ExperimentalBluetoothDeviceClient::Properties* properties = |
| + DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> |
| + GetProperties(object_path_); |
| + DCHECK(properties); |
| + |
| + return properties->alias.value(); |
| +} |
| + |
| +std::string BluetoothDeviceExperimentalChromeOS::GetAddress() const { |
| + ExperimentalBluetoothDeviceClient::Properties* properties = |
| + DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> |
| + GetProperties(object_path_); |
| + DCHECK(properties); |
| + |
| + return properties->address.value(); |
| +} |
| + |
| +bool BluetoothDeviceExperimentalChromeOS::IsPaired() const { |
| + ExperimentalBluetoothDeviceClient::Properties* properties = |
| + DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> |
| + GetProperties(object_path_); |
| + DCHECK(properties); |
| + |
| + return properties->paired.value(); |
| +} |
| + |
| +bool BluetoothDeviceExperimentalChromeOS::IsConnected() const { |
| + ExperimentalBluetoothDeviceClient::Properties* properties = |
| + DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> |
| + GetProperties(object_path_); |
| + DCHECK(properties); |
| + |
| + return properties->connected.value(); |
| +} |
| + |
| +bool BluetoothDeviceExperimentalChromeOS::IsConnectable() const { |
| + // TODO(deymo): implement |
| + return false; |
| +} |
| + |
| +bool BluetoothDeviceExperimentalChromeOS::IsConnecting() const { |
| + return connecting_calls_ > 0; |
| +} |
| + |
| +BluetoothDeviceExperimentalChromeOS::ServiceList |
| +BluetoothDeviceExperimentalChromeOS::GetServices() const { |
| + ExperimentalBluetoothDeviceClient::Properties* properties = |
| + DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> |
| + GetProperties(object_path_); |
| + DCHECK(properties); |
| + |
| + return properties->uuids.value(); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::GetServiceRecords( |
| + const ServiceRecordsCallback& callback, |
| + const ErrorCallback& error_callback) { |
| + // TODO(keybuk): not implemented; remove |
| + error_callback.Run(); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::ProvidesServiceWithName( |
| + const std::string& name, |
| + const ProvidesServiceCallback& callback) { |
| + // TODO(keybuk): not implemented; remove |
| + callback.Run(false); |
| +} |
| + |
| +bool BluetoothDeviceExperimentalChromeOS::ExpectingPinCode() const { |
| + return !pincode_callback_.is_null(); |
| +} |
| + |
| +bool BluetoothDeviceExperimentalChromeOS::ExpectingPasskey() const { |
| + return !passkey_callback_.is_null(); |
| +} |
| + |
| +bool BluetoothDeviceExperimentalChromeOS::ExpectingConfirmation() const { |
| + return !confirmation_callback_.is_null(); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::Connect( |
| + BluetoothDevice::PairingDelegate* pairing_delegate, |
| + const base::Closure& callback, |
| + const ConnectErrorCallback& error_callback) { |
| + ++connecting_calls_; |
| + VLOG(1) << object_path_.value() << ": Connecting, " << connecting_calls_ |
| + << " in progress"; |
| + |
| + if (IsPaired() || IsConnected() || !pairing_delegate) { |
| + // No need to pair, skip straight to connection. |
| + ConnectInternal(callback, error_callback); |
| + |
|
youngki
2013/04/16 15:26:56
Remove the extra line. Or, we could early-return h
keybuk
2013/04/16 23:19:13
Done.
Leaving the if/else because we've had three
|
| + } else { |
| + // Initiate high-security connection with pairing. |
| + DCHECK(!pairing_delegate_); |
| + DCHECK(agent_.get() == NULL); |
| + |
| + pairing_delegate_ = pairing_delegate; |
| + |
| + // The agent path is relatively meaningless since BlueZ only supports |
| + // one per application at a time. |
| + dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); |
| + agent_.reset(ExperimentalBluetoothAgentServiceProvider::Create( |
| + system_bus, kAgentPath, this)); |
| + DCHECK(agent_.get()); |
| + |
| + VLOG(1) << object_path_.value() << ": Registering agent for pairing"; |
| + DBusThreadManager::Get()->GetExperimentalBluetoothAgentManagerClient()-> |
| + RegisterAgent( |
| + kAgentPath, |
| + kAgentCapability, |
| + base::Bind( |
| + &BluetoothDeviceExperimentalChromeOS::OnRegisterAgent, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + callback, error_callback), |
|
youngki
2013/04/16 15:26:56
one argument per line: http://dev.chromium.org/dev
keybuk
2013/04/16 23:19:13
Done.
|
| + base::Bind( |
| + &BluetoothDeviceExperimentalChromeOS::OnRegisterAgentError, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + error_callback)); |
| + } |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::SetPinCode( |
| + const std::string& pincode) { |
| + if (!agent_.get() || pincode_callback_.is_null()) |
| + return; |
| + |
| + pincode_callback_.Run(SUCCESS, pincode); |
| + pincode_callback_.Reset(); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::SetPasskey(uint32 passkey) { |
| + if (!agent_.get() || passkey_callback_.is_null()) |
| + return; |
| + |
| + passkey_callback_.Run(SUCCESS, passkey); |
| + passkey_callback_.Reset(); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::ConfirmPairing() { |
| + if (!agent_.get() || confirmation_callback_.is_null()) |
| + return; |
| + |
| + confirmation_callback_.Run(SUCCESS); |
| + confirmation_callback_.Reset(); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::RejectPairing() { |
| + if (!agent_.get()) |
| + return; |
| + |
| + if (!pincode_callback_.is_null()) { |
| + pincode_callback_.Run(REJECTED, ""); |
| + pincode_callback_.Reset(); |
| + } |
| + if (!passkey_callback_.is_null()) { |
| + passkey_callback_.Run(REJECTED, 0); |
| + passkey_callback_.Reset(); |
| + } |
| + if (!confirmation_callback_.is_null()) { |
| + confirmation_callback_.Run(REJECTED); |
| + confirmation_callback_.Reset(); |
| + } |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::CancelPairing() { |
| + bool have_callback = false; |
| + if (agent_.get()) { |
|
youngki
2013/04/16 15:26:56
The next 15 lines look very similar to RejectPairi
keybuk
2013/04/16 23:19:13
Done.
|
| + if (!pincode_callback_.is_null()) { |
| + pincode_callback_.Run(CANCELLED, ""); |
| + pincode_callback_.Reset(); |
| + have_callback = true; |
| + } |
| + if (!passkey_callback_.is_null()) { |
| + passkey_callback_.Run(CANCELLED, 0); |
| + passkey_callback_.Reset(); |
| + have_callback = true; |
| + } |
| + if (!confirmation_callback_.is_null()) { |
| + confirmation_callback_.Run(CANCELLED); |
| + confirmation_callback_.Reset(); |
| + have_callback = true; |
| + } |
| + } |
| + |
| + // If there wasn't a callback in progress that we can reply to then we |
| + // have to send a CancelPairing() to the device instead. |
| + if (!have_callback) { |
| + DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> |
| + CancelPairing( |
| + object_path_, |
| + base::Bind(&base::DoNothing), |
| + base::Bind( |
| + &BluetoothDeviceExperimentalChromeOS::OnCancelPairingError, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + } |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::Disconnect( |
| + const base::Closure& callback, |
| + const ErrorCallback& error_callback) { |
| + VLOG(1) << object_path_.value() << ": Disconnecting"; |
| + DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> |
| + Disconnect( |
| + object_path_, |
| + base::Bind( |
| + &BluetoothDeviceExperimentalChromeOS::OnDisconnect, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + callback), |
| + base::Bind( |
| + &BluetoothDeviceExperimentalChromeOS::OnDisconnectError, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + error_callback)); |
| +} |
| + |
| +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)); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::ConnectToService( |
| + const std::string& service_uuid, |
| + const SocketCallback& callback) { |
| + // TODO(keybuk): implement |
| + callback.Run(scoped_refptr<device::BluetoothSocket>()); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::ConnectToProfile( |
| + device::BluetoothProfile* profile, |
| + const ErrorCallback& error_callback) { |
| + // TODO(keybuk): implement |
| + error_callback.Run(); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::SetOutOfBandPairingData( |
| + const device::BluetoothOutOfBandPairingData& data, |
| + const base::Closure& callback, |
| + const ErrorCallback& error_callback) { |
| + // TODO(keybuk): implement |
| + error_callback.Run(); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::ClearOutOfBandPairingData( |
| + const base::Closure& callback, |
| + const ErrorCallback& error_callback) { |
| + // TODO(keybuk): implement |
| + error_callback.Run(); |
| +} |
| + |
| + |
| +void BluetoothDeviceExperimentalChromeOS::Release() { |
| + DCHECK(agent_.get()); |
| + DCHECK(pairing_delegate_); |
| + VLOG(1) << object_path_.value() << ": Release"; |
| + |
| + pincode_callback_.Reset(); |
| + passkey_callback_.Reset(); |
| + confirmation_callback_.Reset(); |
| + |
| + UnregisterAgent(); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::RequestPinCode( |
| + const dbus::ObjectPath& device_path, |
| + const PinCodeCallback& callback) { |
| + DCHECK(agent_.get()); |
| + DCHECK(device_path == object_path_); |
| + VLOG(1) << object_path_.value() << ": RequestPinCode"; |
| + |
| + DCHECK(pairing_delegate_); |
| + DCHECK(pincode_callback_.is_null()); |
| + pincode_callback_ = callback; |
| + pairing_delegate_->RequestPinCode(this); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::DisplayPinCode( |
| + const dbus::ObjectPath& device_path, |
| + const std::string& pincode) { |
| + DCHECK(agent_.get()); |
| + DCHECK(device_path == object_path_); |
| + VLOG(1) << object_path_.value() << ": DisplayPinCode: " << pincode; |
| + |
| + DCHECK(pairing_delegate_); |
| + pairing_delegate_->DisplayPinCode(this, pincode); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::RequestPasskey( |
| + const dbus::ObjectPath& device_path, |
| + const PasskeyCallback& callback) { |
| + DCHECK(agent_.get()); |
| + DCHECK(device_path == object_path_); |
| + VLOG(1) << object_path_.value() << ": RequestPasskey"; |
| + |
| + DCHECK(pairing_delegate_); |
| + DCHECK(passkey_callback_.is_null()); |
| + passkey_callback_ = callback; |
| + pairing_delegate_->RequestPasskey(this); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::DisplayPasskey( |
| + const dbus::ObjectPath& device_path, |
| + uint32 passkey, int16 entered) { |
| + DCHECK(agent_.get()); |
| + DCHECK(device_path == object_path_); |
| + VLOG(1) << object_path_.value() << ": DisplayPasskey: " << passkey |
| + << " (" << entered << " entered)"; |
| + |
| + // TODO(keybuk): disambiguate entered vs display |
| + if (entered > 0) |
| + return; |
| + |
| + DCHECK(pairing_delegate_); |
| + pairing_delegate_->DisplayPasskey(this, passkey); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::RequestConfirmation( |
| + const dbus::ObjectPath& device_path, |
| + uint32 passkey, |
| + const ConfirmationCallback& callback) { |
| + DCHECK(agent_.get()); |
| + DCHECK(device_path == object_path_); |
| + VLOG(1) << object_path_.value() << ": RequestConfirmation: " << passkey; |
| + |
| + DCHECK(pairing_delegate_); |
| + DCHECK(confirmation_callback_.is_null()); |
| + confirmation_callback_ = callback; |
| + pairing_delegate_->ConfirmPasskey(this, passkey); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::RequestAuthorization( |
| + const dbus::ObjectPath& device_path, |
| + const ConfirmationCallback& callback) { |
| + // TODO(keybuk): implement |
| + callback.Run(CANCELLED); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::AuthorizeService( |
| + const dbus::ObjectPath& device_path, |
| + const std::string& uuid, |
| + const ConfirmationCallback& callback) { |
| + // TODO(keybuk): implement |
| + callback.Run(CANCELLED); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::Cancel() { |
| + DCHECK(agent_.get()); |
| + VLOG(1) << object_path_.value() << ": Cancel"; |
| + |
| + DCHECK(pairing_delegate_); |
| + pairing_delegate_->DismissDisplayOrConfirm(); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::ConnectInternal( |
| + const base::Closure& callback, |
| + const ConnectErrorCallback& error_callback) { |
| + VLOG(1) << object_path_.value() << ": Connecting"; |
| + DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> |
| + Connect( |
| + object_path_, |
| + base::Bind( |
| + &BluetoothDeviceExperimentalChromeOS::OnConnect, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + callback), |
| + base::Bind( |
| + &BluetoothDeviceExperimentalChromeOS::OnConnectError, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + error_callback)); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::OnConnect( |
| + const base::Closure& callback) { |
| + --connecting_calls_; |
|
youngki
2013/04/16 15:26:56
Can we put DCHECK(connecting_calls >= 0)?
keybuk
2013/04/16 23:19:13
Done.
|
| + VLOG(1) << object_path_.value() << ": Connected, " << connecting_calls_ |
| + << " still in progress"; |
| + |
| + callback.Run(); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::OnConnectError( |
| + const ConnectErrorCallback& error_callback, |
| + const std::string& error_name, |
| + const std::string& error_message) { |
| + --connecting_calls_; |
|
youngki
2013/04/16 15:26:56
Can we put DCHECK(connecting_calls >= 0)?
keybuk
2013/04/16 23:19:13
Done.
|
| + LOG(WARNING) << object_path_.value() << ": Failed to connect device: " |
| + << error_name << ": " << error_message; |
| + VLOG(1) << object_path_.value() << ": " << connecting_calls_ |
| + << " still in progress"; |
| + |
| + // Determine the error code from error_name. |
| + ConnectErrorCode error_code = ERROR_UNKNOWN; |
| + if (error_name == bluetooth_adapter::kErrorFailed) { |
| + error_code = ERROR_FAILED; |
| + } else if (error_name == bluetooth_adapter::kErrorInProgress) { |
| + error_code = ERROR_INPROGRESS; |
| + } else if (error_name == bluetooth_adapter::kErrorNotSupported) { |
| + error_code = ERROR_UNSUPPORTED_DEVICE; |
| + } |
| + |
| + error_callback.Run(error_code); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::OnRegisterAgent( |
| + const base::Closure& callback, |
| + const ConnectErrorCallback& error_callback) { |
| + VLOG(1) << object_path_.value() << ": Agent registered, now pairing"; |
| + |
| + DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()-> |
| + Pair( |
| + object_path_, |
|
youngki
2013/04/16 15:26:56
I think it still fits to put this into the above l
keybuk
2013/04/16 23:19:13
Done.
|
| + base::Bind( |
| + &BluetoothDeviceExperimentalChromeOS::OnPair, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + callback, error_callback), |
| + base::Bind( |
| + &BluetoothDeviceExperimentalChromeOS::OnPairError, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + error_callback)); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::OnRegisterAgentError( |
| + const ConnectErrorCallback& error_callback, |
| + const std::string& error_name, |
| + const std::string& error_message) { |
| + --connecting_calls_; |
|
youngki
2013/04/16 15:26:56
Can we put DCHECK(connecting_calls >= 0)?
keybuk
2013/04/16 23:19:13
Done.
|
| + LOG(WARNING) << object_path_.value() << ": Failed to register agent: " |
| + << error_name << ": " << error_message; |
| + VLOG(1) << object_path_.value() << ": " << connecting_calls_ |
| + << " still in progress"; |
| + |
| + UnregisterAgent(); |
| + |
| + // Determine the error code from error_name. |
| + ConnectErrorCode error_code = ERROR_UNKNOWN; |
| + if (error_name == bluetooth_adapter::kErrorAlreadyExists) { |
|
youngki
2013/04/16 15:26:56
Remove the braces since this is one-liner if block
keybuk
2013/04/16 23:19:13
Done.
|
| + error_code = ERROR_INPROGRESS; |
| + } |
| + |
| + error_callback.Run(error_code); |
| +} |
| + |
| +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! |
| + ConnectInternal(callback, error_callback); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::OnPairError( |
| + const ConnectErrorCallback& error_callback, |
| + const std::string& error_name, |
| + const std::string& error_message) { |
| + --connecting_calls_; |
|
youngki
2013/04/16 15:26:56
Can we put DCHECK(connecting_calls >= 0)?
keybuk
2013/04/16 23:19:13
Done.
|
| + LOG(WARNING) << object_path_.value() << ": Failed to pair device: " |
| + << error_name << ": " << error_message; |
| + VLOG(1) << object_path_.value() << ": " << connecting_calls_ |
| + << " still in progress"; |
| + |
| + UnregisterAgent(); |
| + |
| + // Determine the error code from error_name. |
| + ConnectErrorCode error_code = ERROR_UNKNOWN; |
| + if (error_name == bluetooth_adapter::kErrorConnectionAttemptFailed) { |
| + error_code = ERROR_FAILED; |
| + } else if (error_name == bluetooth_adapter::kErrorAuthenticationFailed) { |
| + error_code = ERROR_AUTH_FAILED; |
| + } else if (error_name == bluetooth_adapter::kErrorAuthenticationCanceled) { |
| + error_code = ERROR_AUTH_CANCELED; |
| + } else if (error_name == bluetooth_adapter::kErrorAuthenticationRejected) { |
| + error_code = ERROR_AUTH_REJECTED; |
| + } else if (error_name == bluetooth_adapter::kErrorAuthenticationTimeout) { |
| + error_code = ERROR_AUTH_TIMEOUT; |
| + } |
| + |
| + error_callback.Run(error_code); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::OnCancelPairingError( |
| + const std::string& error_name, |
| + const std::string& error_message) { |
| + LOG(WARNING) << object_path_.value() << ": Failed to cancel pairing: " |
| + << error_name << ": " << error_message; |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::OnSetTrusted(bool success) { |
| + LOG_IF(WARNING, !success) << object_path_.value() |
| + << ": Failed to set device as trusted"; |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::UnregisterAgent() { |
| + DCHECK(agent_.get()); |
| + DCHECK(pairing_delegate_); |
| + |
| + DCHECK(pincode_callback_.is_null()); |
| + DCHECK(passkey_callback_.is_null()); |
| + DCHECK(confirmation_callback_.is_null()); |
| + |
| + pairing_delegate_->DismissDisplayOrConfirm(); |
| + pairing_delegate_ = NULL; |
| + |
| + agent_.reset(); |
| + |
| + // Clean up after ourselves. |
| + VLOG(1) << object_path_.value() << ": Unregistering pairing agent"; |
| + DBusThreadManager::Get()->GetExperimentalBluetoothAgentManagerClient()-> |
| + UnregisterAgent( |
| + kAgentPath, |
| + base::Bind(&base::DoNothing), |
| + base::Bind( |
| + &BluetoothDeviceExperimentalChromeOS::OnUnregisterAgentError, |
| + weak_ptr_factory_.GetWeakPtr())); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::OnUnregisterAgentError( |
| + const std::string& error_name, |
| + const std::string& error_message) { |
| + LOG(WARNING) << object_path_.value() << ": Failed to unregister agent: " |
| + << error_name << ": " << error_message; |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::OnDisconnect( |
| + const base::Closure& callback) { |
| + VLOG(1) << object_path_.value() << ": Disconnected"; |
| + callback.Run(); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::OnDisconnectError( |
| + const ErrorCallback& error_callback, |
| + const std::string& error_name, |
| + const std::string& error_message) { |
| + LOG(WARNING) << object_path_.value() << ": Failed to disconnect device: " |
| + << error_name << ": " << error_message; |
| + error_callback.Run(); |
| +} |
| + |
| +void BluetoothDeviceExperimentalChromeOS::OnForgetError( |
| + const ErrorCallback& error_callback, |
| + const std::string& error_name, |
| + const std::string& error_message) { |
| + LOG(WARNING) << object_path_.value() << ": Failed to remove device: " |
| + << error_name << ": " << error_message; |
| + error_callback.Run(); |
| +} |
| + |
| +} // namespace chromeos |