| Index: chrome/browser/chromeos/bluetooth/bluetooth_device_chromeos.cc
|
| diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_device.cc b/chrome/browser/chromeos/bluetooth/bluetooth_device_chromeos.cc
|
| similarity index 59%
|
| copy from chrome/browser/chromeos/bluetooth/bluetooth_device.cc
|
| copy to chrome/browser/chromeos/bluetooth/bluetooth_device_chromeos.cc
|
| index ba19dc58e703c48d4eca56faae4fe98529191128..7b1b076611f4012c6cf3d00141bf9388c30d268b 100644
|
| --- a/chrome/browser/chromeos/bluetooth/bluetooth_device.cc
|
| +++ b/chrome/browser/chromeos/bluetooth/bluetooth_device_chromeos.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h"
|
| +#include "chrome/browser/chromeos/bluetooth/bluetooth_device_chromeos.h"
|
|
|
| #include <map>
|
| #include <string>
|
| @@ -15,11 +15,10 @@
|
| #include "base/memory/weak_ptr.h"
|
| #include "base/string16.h"
|
| #include "base/string_util.h"
|
| -#include "base/utf_string_conversions.h"
|
| #include "base/values.h"
|
| -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h"
|
| +#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h"
|
| #include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h"
|
| -#include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h"
|
| +#include "chrome/browser/chromeos/bluetooth/bluetooth_socket_chromeos.h"
|
| #include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h"
|
| #include "chrome/common/chrome_switches.h"
|
| #include "chromeos/dbus/bluetooth_adapter_client.h"
|
| @@ -27,142 +26,33 @@
|
| #include "chromeos/dbus/bluetooth_device_client.h"
|
| #include "chromeos/dbus/bluetooth_input_client.h"
|
| #include "chromeos/dbus/bluetooth_out_of_band_client.h"
|
| +#include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h"
|
| #include "chromeos/dbus/dbus_thread_manager.h"
|
| #include "chromeos/dbus/introspectable_client.h"
|
| #include "dbus/bus.h"
|
| #include "dbus/object_path.h"
|
| -#include "grit/generated_resources.h"
|
| #include "third_party/cros_system_api/dbus/service_constants.h"
|
| -#include "ui/base/l10n/l10n_util.h"
|
|
|
| namespace chromeos {
|
|
|
| -BluetoothDevice::BluetoothDevice(BluetoothAdapter* adapter)
|
| - : adapter_(adapter),
|
| - bluetooth_class_(0),
|
| - visible_(false),
|
| - bonded_(false),
|
| - connected_(false),
|
| +BluetoothDeviceChromeOs::BluetoothDeviceChromeOs(
|
| + BluetoothAdapterChromeOs* adapter)
|
| + : BluetoothDevice(),
|
| + adapter_(adapter),
|
| pairing_delegate_(NULL),
|
| connecting_applications_counter_(0),
|
| weak_ptr_factory_(this) {
|
| }
|
|
|
| -BluetoothDevice::~BluetoothDevice() {
|
| +BluetoothDeviceChromeOs::~BluetoothDeviceChromeOs() {
|
| }
|
|
|
| -const std::string& BluetoothDevice::address() const { return address_; }
|
| -
|
| -string16 BluetoothDevice::GetName() const {
|
| - if (!name_.empty()) {
|
| - return UTF8ToUTF16(name_);
|
| - } else {
|
| - return GetAddressWithLocalizedDeviceTypeName();
|
| - }
|
| -}
|
| -
|
| -BluetoothDevice::DeviceType BluetoothDevice::GetDeviceType() const {
|
| - // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
|
| - switch ((bluetooth_class_ & 0x1f00) >> 8) {
|
| - case 0x01:
|
| - // Computer major device class.
|
| - return DEVICE_COMPUTER;
|
| - case 0x02:
|
| - // Phone major device class.
|
| - switch ((bluetooth_class_ & 0xfc) >> 2) {
|
| - case 0x01:
|
| - case 0x02:
|
| - case 0x03:
|
| - // Cellular, cordless and smart phones.
|
| - return DEVICE_PHONE;
|
| - case 0x04:
|
| - case 0x05:
|
| - // Modems: wired or voice gateway and common ISDN access.
|
| - return DEVICE_MODEM;
|
| - }
|
| - break;
|
| - case 0x05:
|
| - // Peripheral major device class.
|
| - switch ((bluetooth_class_ & 0xc0) >> 6) {
|
| - case 0x00:
|
| - // "Not a keyboard or pointing device."
|
| - switch ((bluetooth_class_ & 0x01e) >> 2) {
|
| - case 0x01:
|
| - // Joystick.
|
| - return DEVICE_JOYSTICK;
|
| - case 0x02:
|
| - // Gamepad.
|
| - return DEVICE_GAMEPAD;
|
| - default:
|
| - return DEVICE_PERIPHERAL;
|
| - }
|
| - break;
|
| - case 0x01:
|
| - // Keyboard.
|
| - return DEVICE_KEYBOARD;
|
| - case 0x02:
|
| - // Pointing device.
|
| - switch ((bluetooth_class_ & 0x01e) >> 2) {
|
| - case 0x05:
|
| - // Digitizer tablet.
|
| - return DEVICE_TABLET;
|
| - default:
|
| - // Mouse.
|
| - return DEVICE_MOUSE;
|
| - }
|
| - break;
|
| - case 0x03:
|
| - // Combo device.
|
| - return DEVICE_KEYBOARD_MOUSE_COMBO;
|
| - }
|
| - break;
|
| - }
|
| -
|
| - return DEVICE_UNKNOWN;
|
| -}
|
| -
|
| -string16 BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() const {
|
| - string16 address = UTF8ToUTF16(address_);
|
| - DeviceType device_type = GetDeviceType();
|
| - switch (device_type) {
|
| - case DEVICE_COMPUTER:
|
| - return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_COMPUTER,
|
| - address);
|
| - case DEVICE_PHONE:
|
| - return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_PHONE,
|
| - address);
|
| - case DEVICE_MODEM:
|
| - return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_MODEM,
|
| - address);
|
| - case DEVICE_JOYSTICK:
|
| - return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_JOYSTICK,
|
| - address);
|
| - case DEVICE_GAMEPAD:
|
| - return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_GAMEPAD,
|
| - address);
|
| - case DEVICE_KEYBOARD:
|
| - return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_KEYBOARD,
|
| - address);
|
| - case DEVICE_MOUSE:
|
| - return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_MOUSE,
|
| - address);
|
| - case DEVICE_TABLET:
|
| - return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_TABLET,
|
| - address);
|
| - case DEVICE_KEYBOARD_MOUSE_COMBO:
|
| - return l10n_util::GetStringFUTF16(
|
| - IDS_BLUETOOTH_DEVICE_KEYBOARD_MOUSE_COMBO, address);
|
| - default:
|
| - return l10n_util::GetStringFUTF16(IDS_BLUETOOTH_DEVICE_UNKNOWN, address);
|
| - }
|
| -}
|
| -
|
| -bool BluetoothDevice::IsSupported() const {
|
| +bool BluetoothDeviceChromeOs::IsSupported() const {
|
| if (CommandLine::ForCurrentProcess()->HasSwitch(
|
| switches::kEnableUnsupportedBluetoothDevices))
|
| return true;
|
|
|
| - DeviceType device_type = GetDeviceType();
|
| + BluetoothDevice::DeviceType device_type = GetDeviceType();
|
| return (device_type == DEVICE_JOYSTICK ||
|
| device_type == DEVICE_GAMEPAD ||
|
| device_type == DEVICE_KEYBOARD ||
|
| @@ -171,52 +61,68 @@ bool BluetoothDevice::IsSupported() const {
|
| device_type == DEVICE_KEYBOARD_MOUSE_COMBO);
|
| }
|
|
|
| -bool BluetoothDevice::IsPaired() const { return !object_path_.value().empty(); }
|
| -
|
| -bool BluetoothDevice::IsBonded() const { return bonded_; }
|
| +bool BluetoothDeviceChromeOs::IsPaired() const {
|
| + return !object_path_.value().empty();
|
| +}
|
|
|
| -bool BluetoothDevice::IsConnected() const {
|
| - // TODO(keybuk): examine protocol-specific connected state, such as Input
|
| - return connected_;
|
| +const BluetoothDevice::ServiceList&
|
| +BluetoothDeviceChromeOs::GetServices() const {
|
| + return service_uuids_;
|
| }
|
|
|
| -void BluetoothDevice::GetServiceRecords(const ServiceRecordsCallback& callback,
|
| - const ErrorCallback& error_callback) {
|
| +void BluetoothDeviceChromeOs::GetServiceRecords(
|
| + const ServiceRecordsCallback& callback,
|
| + const ErrorCallback& error_callback) {
|
| DBusThreadManager::Get()->GetBluetoothDeviceClient()->
|
| DiscoverServices(
|
| object_path_,
|
| "", // empty pattern to browse all services
|
| - base::Bind(&BluetoothDevice::CollectServiceRecordsCallback,
|
| + base::Bind(&BluetoothDeviceChromeOs::CollectServiceRecordsCallback,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| callback,
|
| error_callback));
|
| }
|
|
|
| -bool BluetoothDevice::ProvidesServiceWithUUID(const std::string& uuid) const {
|
| +bool BluetoothDeviceChromeOs::ProvidesServiceWithUUID(
|
| + const std::string& uuid) const {
|
| const BluetoothDevice::ServiceList& services = GetServices();
|
| for (BluetoothDevice::ServiceList::const_iterator iter = services.begin();
|
| - iter != services.end(); ++iter) {
|
| + iter != services.end();
|
| + ++iter) {
|
| if (bluetooth_utils::CanonicalUuid(*iter) == uuid)
|
| return true;
|
| }
|
| return false;
|
| }
|
|
|
| -void BluetoothDevice::ProvidesServiceWithName(const std::string& name,
|
| +void BluetoothDeviceChromeOs::ProvidesServiceWithName(
|
| + const std::string& name,
|
| const ProvidesServiceCallback& callback) {
|
| GetServiceRecords(
|
| - base::Bind(&BluetoothDevice::SearchServicesForNameCallback,
|
| + base::Bind(&BluetoothDeviceChromeOs::SearchServicesForNameCallback,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| name,
|
| callback),
|
| - base::Bind(&BluetoothDevice::SearchServicesForNameErrorCallback,
|
| + base::Bind(&BluetoothDeviceChromeOs::SearchServicesForNameErrorCallback,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| callback));
|
| }
|
|
|
| -void BluetoothDevice::Connect(PairingDelegate* pairing_delegate,
|
| - const base::Closure& callback,
|
| - const ErrorCallback& error_callback) {
|
| +bool BluetoothDeviceChromeOs::ExpectingPinCode() const {
|
| + return !pincode_callback_.is_null();
|
| +}
|
| +
|
| +bool BluetoothDeviceChromeOs::ExpectingPasskey() const {
|
| + return !passkey_callback_.is_null();
|
| +}
|
| +
|
| +bool BluetoothDeviceChromeOs::ExpectingConfirmation() const {
|
| + return !confirmation_callback_.is_null();
|
| +}
|
| +
|
| +void BluetoothDeviceChromeOs::Connect(PairingDelegate* pairing_delegate,
|
| + const base::Closure& callback,
|
| + const ErrorCallback& error_callback) {
|
| if (IsPaired() || IsBonded() || IsConnected()) {
|
| // Connection to already paired or connected device.
|
| ConnectApplications(callback, error_callback);
|
| @@ -226,11 +132,11 @@ void BluetoothDevice::Connect(PairingDelegate* pairing_delegate,
|
| DBusThreadManager::Get()->GetBluetoothAdapterClient()->
|
| CreateDevice(adapter_->object_path_,
|
| address_,
|
| - base::Bind(&BluetoothDevice::ConnectCallback,
|
| + base::Bind(&BluetoothDeviceChromeOs::ConnectCallback,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| callback,
|
| error_callback),
|
| - base::Bind(&BluetoothDevice::ConnectErrorCallback,
|
| + base::Bind(&BluetoothDeviceChromeOs::ConnectErrorCallback,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| error_callback));
|
| } else {
|
| @@ -259,21 +165,22 @@ void BluetoothDevice::Connect(PairingDelegate* pairing_delegate,
|
|
|
| DVLOG(1) << "Pairing: " << address_;
|
| DBusThreadManager::Get()->GetBluetoothAdapterClient()->
|
| - CreatePairedDevice(adapter_->object_path_,
|
| - address_,
|
| - agent_path,
|
| - bluetooth_agent::kDisplayYesNoCapability,
|
| - base::Bind(&BluetoothDevice::ConnectCallback,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - callback,
|
| - error_callback),
|
| - base::Bind(&BluetoothDevice::ConnectErrorCallback,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - error_callback));
|
| + CreatePairedDevice(
|
| + adapter_->object_path_,
|
| + address_,
|
| + agent_path,
|
| + bluetooth_agent::kDisplayYesNoCapability,
|
| + base::Bind(&BluetoothDeviceChromeOs::ConnectCallback,
|
| + weak_ptr_factory_.GetWeakPtr(),
|
| + callback,
|
| + error_callback),
|
| + base::Bind(&BluetoothDeviceChromeOs::ConnectErrorCallback,
|
| + weak_ptr_factory_.GetWeakPtr(),
|
| + error_callback));
|
| }
|
| }
|
|
|
| -void BluetoothDevice::SetPinCode(const std::string& pincode) {
|
| +void BluetoothDeviceChromeOs::SetPinCode(const std::string& pincode) {
|
| if (!agent_.get() || pincode_callback_.is_null())
|
| return;
|
|
|
| @@ -281,7 +188,7 @@ void BluetoothDevice::SetPinCode(const std::string& pincode) {
|
| pincode_callback_.Reset();
|
| }
|
|
|
| -void BluetoothDevice::SetPasskey(uint32 passkey) {
|
| +void BluetoothDeviceChromeOs::SetPasskey(uint32 passkey) {
|
| if (!agent_.get() || passkey_callback_.is_null())
|
| return;
|
|
|
| @@ -289,7 +196,7 @@ void BluetoothDevice::SetPasskey(uint32 passkey) {
|
| passkey_callback_.Reset();
|
| }
|
|
|
| -void BluetoothDevice::ConfirmPairing() {
|
| +void BluetoothDeviceChromeOs::ConfirmPairing() {
|
| if (!agent_.get() || confirmation_callback_.is_null())
|
| return;
|
|
|
| @@ -297,7 +204,7 @@ void BluetoothDevice::ConfirmPairing() {
|
| confirmation_callback_.Reset();
|
| }
|
|
|
| -void BluetoothDevice::RejectPairing() {
|
| +void BluetoothDeviceChromeOs::RejectPairing() {
|
| if (!agent_.get())
|
| return;
|
|
|
| @@ -315,7 +222,7 @@ void BluetoothDevice::RejectPairing() {
|
| }
|
| }
|
|
|
| -void BluetoothDevice::CancelPairing() {
|
| +void BluetoothDeviceChromeOs::CancelPairing() {
|
| if (!agent_.get())
|
| return;
|
|
|
| @@ -333,39 +240,40 @@ void BluetoothDevice::CancelPairing() {
|
| }
|
| }
|
|
|
| -void BluetoothDevice::Disconnect(const base::Closure& callback,
|
| - const ErrorCallback& error_callback) {
|
| +void BluetoothDeviceChromeOs::Disconnect(const base::Closure& callback,
|
| + const ErrorCallback& error_callback) {
|
| DBusThreadManager::Get()->GetBluetoothDeviceClient()->
|
| Disconnect(object_path_,
|
| - base::Bind(&BluetoothDevice::DisconnectCallback,
|
| + base::Bind(&BluetoothDeviceChromeOs::DisconnectCallback,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| callback,
|
| error_callback));
|
|
|
| }
|
|
|
| -void BluetoothDevice::Forget(const ErrorCallback& error_callback) {
|
| +void BluetoothDeviceChromeOs::Forget(const ErrorCallback& error_callback) {
|
| DBusThreadManager::Get()->GetBluetoothAdapterClient()->
|
| RemoveDevice(adapter_->object_path_,
|
| object_path_,
|
| - base::Bind(&BluetoothDevice::ForgetCallback,
|
| + base::Bind(&BluetoothDeviceChromeOs::ForgetCallback,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| error_callback));
|
| }
|
|
|
| -void BluetoothDevice::ConnectToService(const std::string& service_uuid,
|
| - const SocketCallback& callback) {
|
| +void BluetoothDeviceChromeOs::ConnectToService(const std::string& service_uuid,
|
| + const SocketCallback& callback) {
|
| GetServiceRecords(
|
| - base::Bind(&BluetoothDevice::GetServiceRecordsForConnectCallback,
|
| + base::Bind(&BluetoothDeviceChromeOs::GetServiceRecordsForConnectCallback,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| service_uuid,
|
| callback),
|
| - base::Bind(&BluetoothDevice::GetServiceRecordsForConnectErrorCallback,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - callback));
|
| + base::Bind(
|
| + &BluetoothDeviceChromeOs::GetServiceRecordsForConnectErrorCallback,
|
| + weak_ptr_factory_.GetWeakPtr(),
|
| + callback));
|
| }
|
|
|
| -void BluetoothDevice::SetOutOfBandPairingData(
|
| +void BluetoothDeviceChromeOs::SetOutOfBandPairingData(
|
| const chromeos::BluetoothOutOfBandPairingData& data,
|
| const base::Closure& callback,
|
| const ErrorCallback& error_callback) {
|
| @@ -374,36 +282,37 @@ void BluetoothDevice::SetOutOfBandPairingData(
|
| object_path_,
|
| address(),
|
| data,
|
| - base::Bind(&BluetoothDevice::OnRemoteDataCallback,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - callback,
|
| - error_callback));
|
| + base::Bind(&BluetoothDeviceChromeOs::OnRemoteDataCallback,
|
| + weak_ptr_factory_.GetWeakPtr(),
|
| + callback,
|
| + error_callback));
|
| }
|
|
|
| -void BluetoothDevice::ClearOutOfBandPairingData(
|
| +void BluetoothDeviceChromeOs::ClearOutOfBandPairingData(
|
| const base::Closure& callback,
|
| const ErrorCallback& error_callback) {
|
| DBusThreadManager::Get()->GetBluetoothOutOfBandClient()->
|
| RemoveRemoteData(
|
| object_path_,
|
| address(),
|
| - base::Bind(&BluetoothDevice::OnRemoteDataCallback,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - callback,
|
| - error_callback));
|
| + base::Bind(&BluetoothDeviceChromeOs::OnRemoteDataCallback,
|
| + weak_ptr_factory_.GetWeakPtr(),
|
| + callback,
|
| + error_callback));
|
| }
|
|
|
| -void BluetoothDevice::SetObjectPath(const dbus::ObjectPath& object_path) {
|
| +void BluetoothDeviceChromeOs::SetObjectPath(
|
| + const dbus::ObjectPath& object_path) {
|
| DCHECK(object_path_ == dbus::ObjectPath(""));
|
| object_path_ = object_path;
|
| }
|
|
|
| -void BluetoothDevice::RemoveObjectPath() {
|
| +void BluetoothDeviceChromeOs::RemoveObjectPath() {
|
| DCHECK(object_path_ != dbus::ObjectPath(""));
|
| object_path_ = dbus::ObjectPath("");
|
| }
|
|
|
| -void BluetoothDevice::Update(
|
| +void BluetoothDeviceChromeOs::Update(
|
| const BluetoothDeviceClient::Properties* properties,
|
| bool update_state) {
|
| std::string address = properties->address.value();
|
| @@ -430,9 +339,10 @@ void BluetoothDevice::Update(
|
| }
|
| }
|
|
|
| -void BluetoothDevice::ConnectCallback(const base::Closure& callback,
|
| - const ErrorCallback& error_callback,
|
| - const dbus::ObjectPath& device_path) {
|
| +void BluetoothDeviceChromeOs::ConnectCallback(
|
| + const base::Closure& callback,
|
| + const ErrorCallback& error_callback,
|
| + const dbus::ObjectPath& device_path) {
|
| DVLOG(1) << "Connection successful: " << device_path.value();
|
| if (object_path_.value().empty()) {
|
| object_path_ = device_path;
|
| @@ -451,7 +361,7 @@ void BluetoothDevice::ConnectCallback(const base::Closure& callback,
|
| DBusThreadManager::Get()->GetBluetoothDeviceClient()->
|
| GetProperties(object_path_)->trusted.Set(
|
| true,
|
| - base::Bind(&BluetoothDevice::OnSetTrusted,
|
| + base::Bind(&BluetoothDeviceChromeOs::OnSetTrusted,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| callback,
|
| error_callback));
|
| @@ -460,15 +370,16 @@ void BluetoothDevice::ConnectCallback(const base::Closure& callback,
|
| ConnectApplications(callback, error_callback);
|
| }
|
|
|
| -void BluetoothDevice::ConnectErrorCallback(const ErrorCallback& error_callback,
|
| - const std::string& error_name,
|
| - const std::string& error_message) {
|
| +void BluetoothDeviceChromeOs::ConnectErrorCallback(
|
| + const ErrorCallback& error_callback,
|
| + const std::string& error_name,
|
| + const std::string& error_message) {
|
| LOG(WARNING) << "Connection failed: " << address_
|
| << ": " << error_name << ": " << error_message;
|
| error_callback.Run();
|
| }
|
|
|
| -void BluetoothDevice::CollectServiceRecordsCallback(
|
| +void BluetoothDeviceChromeOs::CollectServiceRecordsCallback(
|
| const ServiceRecordsCallback& callback,
|
| const ErrorCallback& error_callback,
|
| const dbus::ObjectPath& device_path,
|
| @@ -488,9 +399,9 @@ void BluetoothDevice::CollectServiceRecordsCallback(
|
| callback.Run(records);
|
| }
|
|
|
| -void BluetoothDevice::OnSetTrusted(const base::Closure& callback,
|
| - const ErrorCallback& error_callback,
|
| - bool success) {
|
| +void BluetoothDeviceChromeOs::OnSetTrusted(const base::Closure& callback,
|
| + const ErrorCallback& error_callback,
|
| + bool success) {
|
| if (success) {
|
| callback.Run();
|
| } else {
|
| @@ -499,24 +410,25 @@ void BluetoothDevice::OnSetTrusted(const base::Closure& callback,
|
| }
|
| }
|
|
|
| -void BluetoothDevice::ConnectApplications(const base::Closure& callback,
|
| - const ErrorCallback& error_callback) {
|
| +void BluetoothDeviceChromeOs::ConnectApplications(
|
| + const base::Closure& callback,
|
| + const ErrorCallback& error_callback) {
|
| // Introspect the device object to determine supported applications.
|
| DBusThreadManager::Get()->GetIntrospectableClient()->
|
| Introspect(bluetooth_device::kBluetoothDeviceServiceName,
|
| object_path_,
|
| - base::Bind(&BluetoothDevice::OnIntrospect,
|
| + base::Bind(&BluetoothDeviceChromeOs::OnIntrospect,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| callback,
|
| error_callback));
|
| }
|
|
|
| -void BluetoothDevice::OnIntrospect(const base::Closure& callback,
|
| - const ErrorCallback& error_callback,
|
| - const std::string& service_name,
|
| - const dbus::ObjectPath& device_path,
|
| - const std::string& xml_data,
|
| - bool success) {
|
| +void BluetoothDeviceChromeOs::OnIntrospect(const base::Closure& callback,
|
| + const ErrorCallback& error_callback,
|
| + const std::string& service_name,
|
| + const dbus::ObjectPath& device_path,
|
| + const std::string& xml_data,
|
| + bool success) {
|
| if (!success) {
|
| LOG(WARNING) << "Failed to determine supported applications: " << address_;
|
| error_callback.Run();
|
| @@ -539,11 +451,11 @@ void BluetoothDevice::OnIntrospect(const base::Closure& callback,
|
| // Supports Input interface.
|
| DBusThreadManager::Get()->GetBluetoothInputClient()->
|
| Connect(object_path_,
|
| - base::Bind(&BluetoothDevice::OnConnect,
|
| + base::Bind(&BluetoothDeviceChromeOs::OnConnect,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| callback,
|
| *iter),
|
| - base::Bind(&BluetoothDevice::OnConnectError,
|
| + base::Bind(&BluetoothDeviceChromeOs::OnConnectError,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| error_callback, *iter));
|
| }
|
| @@ -558,9 +470,9 @@ void BluetoothDevice::OnIntrospect(const base::Closure& callback,
|
| callback.Run();
|
| }
|
|
|
| -void BluetoothDevice::OnConnect(const base::Closure& callback,
|
| - const std::string& interface_name,
|
| - const dbus::ObjectPath& device_path) {
|
| +void BluetoothDeviceChromeOs::OnConnect(const base::Closure& callback,
|
| + const std::string& interface_name,
|
| + const dbus::ObjectPath& device_path) {
|
| DVLOG(1) << "Application connection successful: " << device_path.value()
|
| << ": " << interface_name;
|
|
|
| @@ -576,20 +488,22 @@ void BluetoothDevice::OnConnect(const base::Closure& callback,
|
| }
|
| }
|
|
|
| -void BluetoothDevice::OnConnectError(const ErrorCallback& error_callback,
|
| - const std::string& interface_name,
|
| - const dbus::ObjectPath& device_path,
|
| - const std::string& error_name,
|
| - const std::string& error_message) {
|
| +void BluetoothDeviceChromeOs::OnConnectError(
|
| + const ErrorCallback& error_callback,
|
| + const std::string& interface_name,
|
| + const dbus::ObjectPath& device_path,
|
| + const std::string& error_name,
|
| + const std::string& error_message) {
|
| LOG(WARNING) << "Connection failed: " << address_ << ": " << interface_name
|
| << ": " << error_name << ": " << error_message;
|
| error_callback.Run();
|
| }
|
|
|
| -void BluetoothDevice::DisconnectCallback(const base::Closure& callback,
|
| - const ErrorCallback& error_callback,
|
| - const dbus::ObjectPath& device_path,
|
| - bool success) {
|
| +void BluetoothDeviceChromeOs::DisconnectCallback(
|
| + const base::Closure& callback,
|
| + const ErrorCallback& error_callback,
|
| + const dbus::ObjectPath& device_path,
|
| + bool success) {
|
| DCHECK(device_path == object_path_);
|
| if (success) {
|
| DVLOG(1) << "Disconnection successful: " << address_;
|
| @@ -600,9 +514,10 @@ void BluetoothDevice::DisconnectCallback(const base::Closure& callback,
|
| }
|
| }
|
|
|
| -void BluetoothDevice::ForgetCallback(const ErrorCallback& error_callback,
|
| - const dbus::ObjectPath& adapter_path,
|
| - bool success) {
|
| +void BluetoothDeviceChromeOs::ForgetCallback(
|
| + const ErrorCallback& error_callback,
|
| + const dbus::ObjectPath& adapter_path,
|
| + bool success) {
|
| // It's quite normal that this path never gets called on success; we use a
|
| // weak pointer, and bluetoothd might send the DeviceRemoved signal before
|
| // the method reply, in which case this object is deleted and the
|
| @@ -614,12 +529,12 @@ void BluetoothDevice::ForgetCallback(const ErrorCallback& error_callback,
|
| }
|
| }
|
|
|
| -void BluetoothDevice::SearchServicesForNameErrorCallback(
|
| +void BluetoothDeviceChromeOs::SearchServicesForNameErrorCallback(
|
| const ProvidesServiceCallback& callback) {
|
| callback.Run(false);
|
| }
|
|
|
| -void BluetoothDevice::SearchServicesForNameCallback(
|
| +void BluetoothDeviceChromeOs::SearchServicesForNameCallback(
|
| const std::string& name,
|
| const ProvidesServiceCallback& callback,
|
| const ServiceRecordList& list) {
|
| @@ -633,12 +548,12 @@ void BluetoothDevice::SearchServicesForNameCallback(
|
| callback.Run(false);
|
| }
|
|
|
| -void BluetoothDevice::GetServiceRecordsForConnectErrorCallback(
|
| +void BluetoothDeviceChromeOs::GetServiceRecordsForConnectErrorCallback(
|
| const SocketCallback& callback) {
|
| callback.Run(NULL);
|
| }
|
|
|
| -void BluetoothDevice::GetServiceRecordsForConnectCallback(
|
| +void BluetoothDeviceChromeOs::GetServiceRecordsForConnectCallback(
|
| const std::string& service_uuid,
|
| const SocketCallback& callback,
|
| const ServiceRecordList& list) {
|
| @@ -647,7 +562,7 @@ void BluetoothDevice::GetServiceRecordsForConnectCallback(
|
| if ((*i)->uuid() == service_uuid) {
|
| // If multiple service records are found, use the first one that works.
|
| scoped_refptr<BluetoothSocket> socket(
|
| - BluetoothSocket::CreateBluetoothSocket(**i));
|
| + BluetoothSocketChromeOs::CreateBluetoothSocket(**i));
|
| if (socket.get() != NULL) {
|
| callback.Run(socket);
|
| return;
|
| @@ -657,20 +572,22 @@ void BluetoothDevice::GetServiceRecordsForConnectCallback(
|
| callback.Run(NULL);
|
| }
|
|
|
| -void BluetoothDevice::OnRemoteDataCallback(const base::Closure& callback,
|
| - const ErrorCallback& error_callback,
|
| - bool success) {
|
| +void BluetoothDeviceChromeOs::OnRemoteDataCallback(
|
| + const base::Closure& callback,
|
| + const ErrorCallback& error_callback,
|
| + bool success) {
|
| if (success)
|
| callback.Run();
|
| else
|
| error_callback.Run();
|
| }
|
|
|
| -void BluetoothDevice::DisconnectRequested(const dbus::ObjectPath& object_path) {
|
| +void BluetoothDeviceChromeOs::DisconnectRequested(
|
| + const dbus::ObjectPath& object_path) {
|
| DCHECK(object_path == object_path_);
|
| }
|
|
|
| -void BluetoothDevice::Release() {
|
| +void BluetoothDeviceChromeOs::Release() {
|
| DCHECK(agent_.get());
|
| DVLOG(1) << "Release: " << address_;
|
|
|
| @@ -685,8 +602,9 @@ void BluetoothDevice::Release() {
|
| agent_.reset();
|
| }
|
|
|
| -void BluetoothDevice::RequestPinCode(const dbus::ObjectPath& device_path,
|
| - const PinCodeCallback& callback) {
|
| +void BluetoothDeviceChromeOs::RequestPinCode(
|
| + const dbus::ObjectPath& device_path,
|
| + const PinCodeCallback& callback) {
|
| DCHECK(agent_.get());
|
| DVLOG(1) << "RequestPinCode: " << device_path.value();
|
|
|
| @@ -696,8 +614,9 @@ void BluetoothDevice::RequestPinCode(const dbus::ObjectPath& device_path,
|
| pairing_delegate_->RequestPinCode(this);
|
| }
|
|
|
| -void BluetoothDevice::RequestPasskey(const dbus::ObjectPath& device_path,
|
| - const PasskeyCallback& callback) {
|
| +void BluetoothDeviceChromeOs::RequestPasskey(
|
| + const dbus::ObjectPath& device_path,
|
| + const PasskeyCallback& callback) {
|
| DCHECK(agent_.get());
|
| DCHECK(device_path == object_path_);
|
| DVLOG(1) << "RequestPasskey: " << device_path.value();
|
| @@ -708,8 +627,9 @@ void BluetoothDevice::RequestPasskey(const dbus::ObjectPath& device_path,
|
| pairing_delegate_->RequestPasskey(this);
|
| }
|
|
|
| -void BluetoothDevice::DisplayPinCode(const dbus::ObjectPath& device_path,
|
| - const std::string& pincode) {
|
| +void BluetoothDeviceChromeOs::DisplayPinCode(
|
| + const dbus::ObjectPath& device_path,
|
| + const std::string& pincode) {
|
| DCHECK(agent_.get());
|
| DCHECK(device_path == object_path_);
|
| DVLOG(1) << "DisplayPinCode: " << device_path.value() << " " << pincode;
|
| @@ -718,8 +638,9 @@ void BluetoothDevice::DisplayPinCode(const dbus::ObjectPath& device_path,
|
| pairing_delegate_->DisplayPinCode(this, pincode);
|
| }
|
|
|
| -void BluetoothDevice::DisplayPasskey(const dbus::ObjectPath& device_path,
|
| - uint32 passkey) {
|
| +void BluetoothDeviceChromeOs::DisplayPasskey(
|
| + const dbus::ObjectPath& device_path,
|
| + uint32 passkey) {
|
| DCHECK(agent_.get());
|
| DCHECK(device_path == object_path_);
|
| DVLOG(1) << "DisplayPasskey: " << device_path.value() << " " << passkey;
|
| @@ -728,7 +649,7 @@ void BluetoothDevice::DisplayPasskey(const dbus::ObjectPath& device_path,
|
| pairing_delegate_->DisplayPasskey(this, passkey);
|
| }
|
|
|
| -void BluetoothDevice::RequestConfirmation(
|
| +void BluetoothDeviceChromeOs::RequestConfirmation(
|
| const dbus::ObjectPath& device_path,
|
| uint32 passkey,
|
| const ConfirmationCallback& callback) {
|
| @@ -742,9 +663,9 @@ void BluetoothDevice::RequestConfirmation(
|
| pairing_delegate_->ConfirmPasskey(this, passkey);
|
| }
|
|
|
| -void BluetoothDevice::Authorize(const dbus::ObjectPath& device_path,
|
| - const std::string& uuid,
|
| - const ConfirmationCallback& callback) {
|
| +void BluetoothDeviceChromeOs::Authorize(const dbus::ObjectPath& device_path,
|
| + const std::string& uuid,
|
| + const ConfirmationCallback& callback) {
|
| DCHECK(agent_.get());
|
| DCHECK(device_path == object_path_);
|
| LOG(WARNING) << "Rejected authorization for service: " << uuid
|
| @@ -752,15 +673,16 @@ void BluetoothDevice::Authorize(const dbus::ObjectPath& device_path,
|
| callback.Run(REJECTED);
|
| }
|
|
|
| -void BluetoothDevice::ConfirmModeChange(Mode mode,
|
| - const ConfirmationCallback& callback) {
|
| +void BluetoothDeviceChromeOs::ConfirmModeChange(
|
| + Mode mode,
|
| + const ConfirmationCallback& callback) {
|
| DCHECK(agent_.get());
|
| LOG(WARNING) << "Rejected adapter-level mode change: " << mode
|
| << " made on agent for device: " << address_;
|
| callback.Run(REJECTED);
|
| }
|
|
|
| -void BluetoothDevice::Cancel() {
|
| +void BluetoothDeviceChromeOs::Cancel() {
|
| DCHECK(agent_.get());
|
| DVLOG(1) << "Cancel: " << address_;
|
|
|
| @@ -770,8 +692,9 @@ void BluetoothDevice::Cancel() {
|
|
|
|
|
| // static
|
| -BluetoothDevice* BluetoothDevice::Create(BluetoothAdapter* adapter) {
|
| - return new BluetoothDevice(adapter);
|
| +BluetoothDeviceChromeOs* BluetoothDeviceChromeOs::Create(
|
| + BluetoothAdapterChromeOs* adapter) {
|
| + return new BluetoothDeviceChromeOs(adapter);
|
| }
|
|
|
| } // namespace chromeos
|
|
|