diff options
author | yoichio <yoichio@chromium.org> | 2015-09-29 00:39:22 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-29 07:39:59 +0000 |
commit | 500c6dbb7438f38c5bb28c529d4bd43e6d1b1f9e (patch) | |
tree | 43fd774d2c09ad46db949e824bce328e158ba57d /device/bluetooth/bluetooth_socket_chromeos.h | |
parent | a543d12194462ac37a25d150dcbb0077ccd72b73 (diff) | |
download | chromium_src-500c6dbb7438f38c5bb28c529d4bd43e6d1b1f9e.zip chromium_src-500c6dbb7438f38c5bb28c529d4bd43e6d1b1f9e.tar.gz chromium_src-500c6dbb7438f38c5bb28c529d4bd43e6d1b1f9e.tar.bz2 |
Revert of Add Linux support for the Bluetooth API. (patchset #10 id:90001 of
https://codereview.chromium.org/1367663002/ )
Reason for revert:
perf regression.
http://build.chromium.org/p/chromium/builders/Linux%20x64/builds/10130
Original issue's description:
> Add Linux support for the Bluetooth API.
>
> This refactors all the code in //device/bluetooth to be non-ChromeOS specific
> and adds code to enable all of it to run on Linux through the linux specific
> DBusThreadManager that is added.
>
> This CL depends on https://codereview.chromium.org/1347193004/
>
> Owners reviews requested,
> //device - armansito@
> //extensions - rockot@
> //chrome/browser/chrome_browser_main_linux.* - jhawkins@
>
> R=armansito@chromium.org, jhawkins@chromium.org, rockot@chromium.org
> BUG=522633
>
> Committed: https://crrev.com/17fcdab015a073437404f35e7e63c1464280d36b
> Cr-Commit-Position: refs/heads/master@{#351237}
TBR=armansito@chromium.org,jhawkins@chromium.org,rockot@chromium.org,jdeokule@chromi
um.org,scheib@chromium.org,rkc@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=522633
Review URL: https://codereview.chromium.org/1380463003
Cr-Commit-Position: refs/heads/master@{#351266}
Diffstat (limited to 'device/bluetooth/bluetooth_socket_chromeos.h')
-rw-r--r-- | device/bluetooth/bluetooth_socket_chromeos.h | 203 |
1 files changed, 203 insertions, 0 deletions
diff --git a/device/bluetooth/bluetooth_socket_chromeos.h b/device/bluetooth/bluetooth_socket_chromeos.h new file mode 100644 index 0000000..a1c76ee2 --- /dev/null +++ b/device/bluetooth/bluetooth_socket_chromeos.h @@ -0,0 +1,203 @@ +// Copyright 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. + +#ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ +#define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ + +#include <queue> +#include <string> + +#include "base/memory/linked_ptr.h" +#include "base/memory/scoped_ptr.h" +#include "dbus/object_path.h" +#include "device/bluetooth/bluetooth_adapter.h" +#include "device/bluetooth/bluetooth_export.h" +#include "device/bluetooth/bluetooth_socket.h" +#include "device/bluetooth/bluetooth_socket_net.h" +#include "device/bluetooth/bluetooth_uuid.h" +#include "device/bluetooth/dbus/bluetooth_profile_manager_client.h" +#include "device/bluetooth/dbus/bluetooth_profile_service_provider.h" + +namespace dbus { +class FileDescriptor; +} // namespace dbus + +namespace chromeos { + +class BluetoothDeviceChromeOS; +class BluetoothAdapterChromeOS; +class BluetoothAdapterProfileChromeOS; + +// The BluetoothSocketChromeOS class implements BluetoothSocket for the +// Chrome OS platform. +// +// This class is not thread-safe, but is only called from the UI thread. +class DEVICE_BLUETOOTH_EXPORT BluetoothSocketChromeOS + : public device::BluetoothSocketNet, + public device::BluetoothAdapter::Observer, + public bluez::BluetoothProfileServiceProvider::Delegate { + public: + enum SecurityLevel { + SECURITY_LEVEL_LOW, + SECURITY_LEVEL_MEDIUM + }; + + static scoped_refptr<BluetoothSocketChromeOS> CreateBluetoothSocket( + scoped_refptr<base::SequencedTaskRunner> ui_task_runner, + scoped_refptr<device::BluetoothSocketThread> socket_thread); + + // Connects this socket to the service on |device| published as UUID |uuid|, + // the underlying protocol and PSM or Channel is obtained through service + // discovery. On a successful connection the socket properties will be updated + // and |success_callback| called. On failure |error_callback| will be called + // with a message explaining the cause of the failure. + virtual void Connect(const BluetoothDeviceChromeOS* device, + const device::BluetoothUUID& uuid, + SecurityLevel security_level, + const base::Closure& success_callback, + const ErrorCompletionCallback& error_callback); + + // Listens using this socket using a service published on |adapter|. The + // service is either RFCOMM or L2CAP depending on |socket_type| and published + // as UUID |uuid|. The |service_options| argument is interpreted according to + // |socket_type|. |success_callback| will be called if the service is + // successfully registered, |error_callback| on failure with a message + // explaining the cause. + enum SocketType { kRfcomm, kL2cap }; + virtual void Listen( + scoped_refptr<device::BluetoothAdapter> adapter, + SocketType socket_type, + const device::BluetoothUUID& uuid, + const device::BluetoothAdapter::ServiceOptions& service_options, + const base::Closure& success_callback, + const ErrorCompletionCallback& error_callback); + + // BluetoothSocket: + void Close() override; + void Disconnect(const base::Closure& callback) override; + void Accept(const AcceptCompletionCallback& success_callback, + const ErrorCompletionCallback& error_callback) override; + + protected: + ~BluetoothSocketChromeOS() override; + + private: + BluetoothSocketChromeOS( + scoped_refptr<base::SequencedTaskRunner> ui_task_runner, + scoped_refptr<device::BluetoothSocketThread> socket_thread); + + // Register the underlying profile client object with the Bluetooth Daemon. + void RegisterProfile(BluetoothAdapterChromeOS* adapter, + const base::Closure& success_callback, + const ErrorCompletionCallback& error_callback); + void OnRegisterProfile(const base::Closure& success_callback, + const ErrorCompletionCallback& error_callback, + BluetoothAdapterProfileChromeOS* profile); + void OnRegisterProfileError(const ErrorCompletionCallback& error_callback, + const std::string& error_message); + + // Called by dbus:: on completion of the ConnectProfile() method. + void OnConnectProfile(const base::Closure& success_callback); + void OnConnectProfileError(const ErrorCompletionCallback& error_callback, + const std::string& error_name, + const std::string& error_message); + + // BluetoothAdapter::Observer: + void AdapterPresentChanged(device::BluetoothAdapter* adapter, + bool present) override; + + // Called by dbus:: on completion of the RegisterProfile() method call + // triggered as a result of the adapter becoming present again. + void OnInternalRegisterProfile(BluetoothAdapterProfileChromeOS* profile); + void OnInternalRegisterProfileError(const std::string& error_message); + + // bluez::BluetoothProfileServiceProvider::Delegate: + void Released() override; + void NewConnection( + const dbus::ObjectPath& device_path, + scoped_ptr<dbus::FileDescriptor> fd, + const bluez::BluetoothProfileServiceProvider::Delegate::Options& options, + const ConfirmationCallback& callback) override; + void RequestDisconnection(const dbus::ObjectPath& device_path, + const ConfirmationCallback& callback) override; + void Cancel() override; + + // Method run to accept a single incoming connection. + void AcceptConnectionRequest(); + + // Method run on the socket thread to validate the file descriptor of a new + // connection and set up the underlying net::TCPSocket() for it. + void DoNewConnection( + const dbus::ObjectPath& device_path, + scoped_ptr<dbus::FileDescriptor> fd, + const bluez::BluetoothProfileServiceProvider::Delegate::Options& options, + const ConfirmationCallback& callback); + + // Method run on the UI thread after a new connection has been accepted and + // a socket allocated in |socket|. Takes care of calling the Accept() + // callback and |callback| with the right arguments based on |status|. + void OnNewConnection(scoped_refptr<BluetoothSocket> socket, + const ConfirmationCallback& callback, + Status status); + + // Method run on the socket thread with a valid file descriptor |fd|, once + // complete calls |callback| on the UI thread with an appropriate argument + // indicating success or failure. + void DoConnect(scoped_ptr<dbus::FileDescriptor> fd, + const ConfirmationCallback& callback); + + // Method run to clean-up a listening socket. + void DoCloseListening(); + + // Unregisters this socket's usage of the Bluetooth profile which cleans up + // the profile if no one is using it. + void UnregisterProfile(); + + // Adapter the profile is registered against + scoped_refptr<device::BluetoothAdapter> adapter_; + + // Address and D-Bus object path of the device being connected to, empty and + // ignored if the socket is listening. + std::string device_address_; + dbus::ObjectPath device_path_; + + // UUID of the profile being connected to, or listening on. + device::BluetoothUUID uuid_; + + // Copy of the profile options used for registering the profile. + scoped_ptr<bluez::BluetoothProfileManagerClient::Options> options_; + + // The profile registered with the adapter for this socket. + BluetoothAdapterProfileChromeOS* profile_; + + // Pending request to an Accept() call. + struct AcceptRequest { + AcceptRequest(); + ~AcceptRequest(); + + AcceptCompletionCallback success_callback; + ErrorCompletionCallback error_callback; + }; + scoped_ptr<AcceptRequest> accept_request_; + + // Queue of incoming connection requests. + struct ConnectionRequest { + ConnectionRequest(); + ~ConnectionRequest(); + + dbus::ObjectPath device_path; + scoped_ptr<dbus::FileDescriptor> fd; + bluez::BluetoothProfileServiceProvider::Delegate::Options options; + ConfirmationCallback callback; + bool accepting; + bool cancelled; + }; + std::queue<linked_ptr<ConnectionRequest> > connection_request_queue_; + + DISALLOW_COPY_AND_ASSIGN(BluetoothSocketChromeOS); +}; + +} // namespace chromeos + +#endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_ |