| Index: chrome/browser/chromeos/bluetooth/bluetooth_device_dbus.h
|
| diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_device.h b/chrome/browser/chromeos/bluetooth/bluetooth_device_dbus.h
|
| similarity index 87%
|
| rename from chrome/browser/chromeos/bluetooth/bluetooth_device.h
|
| rename to chrome/browser/chromeos/bluetooth/bluetooth_device_dbus.h
|
| index 0064f48e11565148e3d5491f3308e11d00c1ceae..9efd00478f0317074f36f45bdc93e67c45b62604 100644
|
| --- a/chrome/browser/chromeos/bluetooth/bluetooth_device.h
|
| +++ b/chrome/browser/chromeos/bluetooth/bluetooth_device_dbus.h
|
| @@ -2,18 +2,18 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_
|
| -#define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_
|
| +#ifndef CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_DBUS_H_
|
| +#define CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_DBUS_H_
|
|
|
| #include <string>
|
| #include <vector>
|
|
|
| #include "base/basictypes.h"
|
| -#include "base/callback.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/memory/scoped_vector.h"
|
| #include "base/memory/weak_ptr.h"
|
| #include "base/string16.h"
|
| +#include "chrome/browser/chromeos/bluetooth/bluetooth_device_interface.h"
|
| #include "chromeos/dbus/bluetooth_agent_service_provider.h"
|
| #include "chromeos/dbus/bluetooth_device_client.h"
|
| #include "chromeos/dbus/bluetooth_out_of_band_client.h"
|
| @@ -21,42 +21,27 @@
|
|
|
| namespace chromeos {
|
|
|
| -class BluetoothAdapter;
|
| -class BluetoothServiceRecord;
|
| -class BluetoothSocket;
|
| +class BluetoothAdapterDBus;
|
| +class BluetoothServiceRecordDBus;
|
| +class BluetoothSocketPosix;
|
|
|
| -// The BluetoothDevice class represents a remote Bluetooth device, both
|
| -// its properties and capabilities as discovered by a local adapter and
|
| -// actions that may be performed on the remove device such as pairing,
|
| -// connection and disconnection.
|
| +struct BluetoothOutOfBandPairingData;
|
| +
|
| +// The BluetoothDeviceDBus class is an implementation of
|
| +// BluetoothDeviceInterface using DBus for Linux/ChromeOS platform.
|
| //
|
| -// The class is instantiated and managed by the BluetoothAdapter class
|
| -// and pointers should only be obtained from that class and not cached,
|
| +// The class is instantiated and managed by the BluetoothAdapterDBus class
|
| +// and pointers should only be obtained from the BluetoothAdapterInterface and
|
| +// not cached,
|
| // instead use the address() method as a unique key for a device.
|
| //
|
| -// Since the lifecycle of BluetoothDevice instances is managed by
|
| -// BluetoothAdapter, that class rather than this provides observer methods
|
| +// Since the lifecycle of BluetoothDeviceDBus instances is managed by
|
| +// BluetoothAdapterDBus, that class rather than this provides observer methods
|
| // for devices coming and going, as well as properties being updated.
|
| -class BluetoothDevice : public BluetoothDeviceClient::Observer,
|
| - public BluetoothAgentServiceProvider::Delegate {
|
| +class BluetoothDeviceDBus : public BluetoothDeviceClient::Observer,
|
| + public BluetoothDeviceInterface,
|
| + public BluetoothAgentServiceProvider::Delegate {
|
| public:
|
| - // Possible values that may be returned by GetDeviceType(), representing
|
| - // different types of bluetooth device that we support or are aware of
|
| - // decoded from the bluetooth class information.
|
| - enum DeviceType {
|
| - DEVICE_UNKNOWN,
|
| - DEVICE_COMPUTER,
|
| - DEVICE_PHONE,
|
| - DEVICE_MODEM,
|
| - DEVICE_PERIPHERAL,
|
| - DEVICE_JOYSTICK,
|
| - DEVICE_GAMEPAD,
|
| - DEVICE_KEYBOARD,
|
| - DEVICE_MOUSE,
|
| - DEVICE_TABLET,
|
| - DEVICE_KEYBOARD_MOUSE_COMBO
|
| - };
|
| -
|
| // Interface for observing changes from bluetooth devices.
|
| class Observer {
|
| public:
|
| @@ -78,7 +63,7 @@ class BluetoothDevice : public BluetoothDeviceClient::Observer,
|
| //
|
| // PIN Codes are generally required for Bluetooth 2.0 and earlier devices
|
| // for which there is no automatic pairing or special handling.
|
| - virtual void RequestPinCode(BluetoothDevice* device) = 0;
|
| + virtual void RequestPinCode(BluetoothDeviceDBus* device) = 0;
|
|
|
| // This method will be called when the Bluetooth daemon requires a
|
| // Passkey for authentication of the device |device|, the delegate should
|
| @@ -89,7 +74,7 @@ class BluetoothDevice : public BluetoothDeviceClient::Observer,
|
| // Passkeys are generally required for Bluetooth 2.1 and later devices
|
| // which cannot provide input or display on their own, and don't accept
|
| // passkey-less pairing.
|
| - virtual void RequestPasskey(BluetoothDevice* device) = 0;
|
| + virtual void RequestPasskey(BluetoothDeviceDBus* device) = 0;
|
|
|
| // This method will be called when the Bluetooth daemon requires that the
|
| // user enter the PIN code |pincode| into the device |device| so that it
|
| @@ -100,7 +85,7 @@ class BluetoothDevice : public BluetoothDeviceClient::Observer,
|
| // This is used for Bluetooth 2.0 and earlier keyboard devices, the
|
| // |pincode| will always be a six-digit numeric in the range 000000-999999
|
| // for compatibilty with later specifications.
|
| - virtual void DisplayPinCode(BluetoothDevice* device,
|
| + virtual void DisplayPinCode(BluetoothDeviceDBus* device,
|
| const std::string& pincode) = 0;
|
|
|
| // This method will be called when the Bluetooth daemon requires that the
|
| @@ -112,7 +97,7 @@ class BluetoothDevice : public BluetoothDeviceClient::Observer,
|
| // but not display, such as keyboards. The Passkey is a numeric in the
|
| // range 0-999999 and should be always presented zero-padded to six
|
| // digits.
|
| - virtual void DisplayPasskey(BluetoothDevice* device,
|
| + virtual void DisplayPasskey(BluetoothDeviceDBus* device,
|
| uint32 passkey) = 0;
|
|
|
| // This method will be called when the Bluetooth daemon requires that the
|
| @@ -127,7 +112,7 @@ class BluetoothDevice : public BluetoothDeviceClient::Observer,
|
| // such as other computers or phones. The Passkey is a numeric in the
|
| // range 0-999999 and should be always present zero-padded to six
|
| // digits.
|
| - virtual void ConfirmPasskey(BluetoothDevice* device,
|
| + virtual void ConfirmPasskey(BluetoothDeviceDBus* device,
|
| uint32 passkey) = 0;
|
|
|
| // This method will be called when any previous DisplayPinCode(),
|
| @@ -136,7 +121,7 @@ class BluetoothDevice : public BluetoothDeviceClient::Observer,
|
| virtual void DismissDisplayOrConfirm() = 0;
|
| };
|
|
|
| - virtual ~BluetoothDevice();
|
| + virtual ~BluetoothDeviceDBus();
|
|
|
| // Returns the Bluetooth of address the device. This should be used as
|
| // a unique key to identify the device and copied where needed.
|
| @@ -147,12 +132,6 @@ class BluetoothDevice : public BluetoothDeviceClient::Observer,
|
| // if the device has no obtained name.
|
| virtual string16 GetName() const;
|
|
|
| - // Returns the type of the device, limited to those we support or are
|
| - // aware of, by decoding the bluetooth class information. The returned
|
| - // values are unique, and do not overlap, so DEVICE_KEYBOARD is not also
|
| - // DEVICE_PERIPHERAL.
|
| - DeviceType GetDeviceType() const;
|
| -
|
| // Returns a localized string containing the device's bluetooth address and
|
| // a device type for display when |name_| is empty.
|
| string16 GetAddressWithLocalizedDeviceTypeName() const;
|
| @@ -181,28 +160,18 @@ class BluetoothDevice : public BluetoothDeviceClient::Observer,
|
| typedef std::vector<std::string> ServiceList;
|
| const ServiceList& GetServices() const { return service_uuids_; }
|
|
|
| - // The ErrorCallback is used for methods that can fail in which case it
|
| - // is called, in the success case the callback is simply not called.
|
| - typedef base::Callback<void()> ErrorCallback;
|
| -
|
| - // Returns the services (as BluetoothServiceRecord objects) that this device
|
| - // provides.
|
| - typedef ScopedVector<BluetoothServiceRecord> ServiceRecordList;
|
| - typedef base::Callback<void(const ServiceRecordList&)> ServiceRecordsCallback;
|
| - void GetServiceRecords(const ServiceRecordsCallback& callback,
|
| - const ErrorCallback& error_callback);
|
| + // Returns the services (as BluetoothServiceRecordDBus objects) that this
|
| + // device provides.
|
| + virtual void GetServiceRecords(const ServiceRecordsCallback& callback,
|
| + const ErrorCallback& error_callback);
|
|
|
| // Indicates whether this device provides the given service. |uuid| should
|
| // be in canonical form (see bluetooth_utils::CanonicalUuid).
|
| virtual bool ProvidesServiceWithUUID(const std::string& uuid) const;
|
|
|
| - // The ProvidesServiceCallback is used by ProvidesServiceWithName to indicate
|
| - // whether or not a matching service was found.
|
| - typedef base::Callback<void(bool)> ProvidesServiceCallback;
|
| -
|
| // Indicates whether this device provides the given service.
|
| - void ProvidesServiceWithName(const std::string& name,
|
| - const ProvidesServiceCallback& callback);
|
| + virtual void ProvidesServiceWithName(const std::string& name,
|
| + const ProvidesServiceCallback& callback);
|
|
|
| // Indicates whether the device is currently pairing and expecting a
|
| // PIN Code to be returned.
|
| @@ -273,19 +242,15 @@ class BluetoothDevice : public BluetoothDeviceClient::Observer,
|
| // before that callback would be called.
|
| void Forget(const ErrorCallback& error_callback);
|
|
|
| - // SocketCallback is used by ConnectToService to return a BluetoothSocket
|
| - // to the caller, or NULL if there was an error. The socket will remain open
|
| - // until the last reference to the returned BluetoothSocket is released.
|
| - typedef base::Callback<void(scoped_refptr<BluetoothSocket>)> SocketCallback;
|
| -
|
| // Attempts to open a socket to a service matching |uuid| on this device. If
|
| - // the connection is successful, |callback| is called with a BluetoothSocket.
|
| + // the connection is successful, |callback| is called with a
|
| + // BluetoothSocketPosix.
|
| // Otherwise |callback| is called with NULL. The socket is closed as soon as
|
| - // all references to the BluetoothSocket are released. Note that the
|
| - // BluetoothSocket object can outlive both this BluetoothDevice and the
|
| - // BluetoothAdapter for this device.
|
| - void ConnectToService(const std::string& service_uuid,
|
| - const SocketCallback& callback);
|
| + // all references to the BluetoothSocketPosix are released. Note that the
|
| + // BluetoothSocketPosix object can outlive both this BluetoothDeviceDBus and
|
| + // the BluetoothAdapterDBus for this device.
|
| + virtual void ConnectToService(const std::string& service_uuid,
|
| + const SocketCallback& callback);
|
|
|
| // Sets the Out Of Band pairing data for this device to |data|. Exactly one
|
| // of |callback| or |error_callback| will be run.
|
| @@ -301,10 +266,33 @@ class BluetoothDevice : public BluetoothDeviceClient::Observer,
|
| const ErrorCallback& error_callback);
|
|
|
| private:
|
| - friend class BluetoothAdapter;
|
| - friend class MockBluetoothDevice;
|
| + // Possible values that may be returned by GetDeviceType(), representing
|
| + // different types of bluetooth device that we support or are aware of
|
| + // decoded from the bluetooth class information.
|
| + enum DeviceType {
|
| + DEVICE_UNKNOWN,
|
| + DEVICE_COMPUTER,
|
| + DEVICE_PHONE,
|
| + DEVICE_MODEM,
|
| + DEVICE_PERIPHERAL,
|
| + DEVICE_JOYSTICK,
|
| + DEVICE_GAMEPAD,
|
| + DEVICE_KEYBOARD,
|
| + DEVICE_MOUSE,
|
| + DEVICE_TABLET,
|
| + DEVICE_KEYBOARD_MOUSE_COMBO
|
| + };
|
| +
|
| + friend class BluetoothAdapterDBus;
|
| + friend class MockBluetoothDeviceDBus;
|
|
|
| - explicit BluetoothDevice(BluetoothAdapter* adapter);
|
| + explicit BluetoothDeviceDBus(BluetoothAdapterDBus* adapter);
|
| +
|
| + // Returns the type of the device, limited to those we support or are
|
| + // aware of, by decoding the bluetooth class information. The returned
|
| + // values are unique, and do not overlap, so DEVICE_KEYBOARD is not also
|
| + // DEVICE_PERIPHERAL.
|
| + DeviceType GetDeviceType() const;
|
|
|
| // Sets the dbus object path for the device to |object_path|, indicating
|
| // that the device has gone from being discovered to paired or bonded.
|
| @@ -402,10 +390,10 @@ class BluetoothDevice : public BluetoothDeviceClient::Observer,
|
| const ErrorCallback& error_callback,
|
| const dbus::ObjectPath& device_path, bool success);
|
|
|
| - // Called by BluetoothAdapterClient when a call to RemoveDevice() completes,
|
| - // |success| indicates whether or not the request succeeded, |error_callback|
|
| - // is the callback provided to Forget() and |adapter_path| is the d-bus
|
| - // object path of the adapter that performed the removal.
|
| + // Called by BluetoothAdapterClient when a call to RemoveDevice()
|
| + // completes, |success| indicates whether or not the request succeeded,
|
| + // |error_callback| is the callback provided to Forget() and |adapter_path| is
|
| + // the d-bus object path of the adapter that performed the removal.
|
| void ForgetCallback(const ErrorCallback& error_callback,
|
| const dbus::ObjectPath& adapter_path, bool success);
|
|
|
| @@ -554,15 +542,15 @@ class BluetoothDevice : public BluetoothDeviceClient::Observer,
|
| // the request failed before a reply was returned from the device.
|
| virtual void Cancel() OVERRIDE;
|
|
|
| - // Creates a new BluetoothDevice object bound to the adapter |adapter|.
|
| - static BluetoothDevice* Create(BluetoothAdapter* adapter);
|
| + // Creates a new BluetoothDeviceDBus object bound to the adapter |adapter|.
|
| + static BluetoothDeviceDBus* Create(BluetoothAdapterDBus* adapter);
|
|
|
| // Weak pointer factory for generating 'this' pointers that might live longer
|
| // than we do.
|
| - base::WeakPtrFactory<BluetoothDevice> weak_ptr_factory_;
|
| + base::WeakPtrFactory<BluetoothDeviceDBus> weak_ptr_factory_;
|
|
|
| // The adapter that owns this device instance.
|
| - BluetoothAdapter* adapter_;
|
| + BluetoothAdapterDBus* adapter_;
|
|
|
| // The dbus object path of the device, will be empty if the device has only
|
| // been discovered and not yet paired with.
|
| @@ -606,9 +594,9 @@ class BluetoothDevice : public BluetoothDeviceClient::Observer,
|
| // Used to keep track of pending application connection requests.
|
| int connecting_applications_counter_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(BluetoothDevice);
|
| + DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceDBus);
|
| };
|
|
|
| } // namespace chromeos
|
|
|
| -#endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_H_
|
| +#endif // CHROME_BROWSER_CHROMEOS_BLUETOOTH_BLUETOOTH_DEVICE_DBUS_H_
|
|
|