Chromium Code Reviews| Index: components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h |
| diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..65b52702409b8d6fc2a76718b77d76397864a4d6 |
| --- /dev/null |
| +++ b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h |
| @@ -0,0 +1,82 @@ |
| +// Copyright 2015 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 COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H |
| +#define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H |
| + |
| +#include <string> |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "components/proximity_auth/connection_finder.h" |
| +#include "device/bluetooth/bluetooth_adapter.h" |
| +#include "device/bluetooth/bluetooth_device.h" |
| +#include "device/bluetooth/bluetooth_discovery_session.h" |
| +#include "device/bluetooth/bluetooth_gatt_connection.h" |
| + |
| +namespace proximity_auth { |
| + |
| +// This ConnectionFinder implementation tries to find a Bluetooth connection to |
| +// a remote device. |
| +class BluetoothLowEnergyConnectionFinder |
| + : public ConnectionFinder, |
| + public device::BluetoothAdapter::Observer { |
| + public: |
| + BluetoothLowEnergyConnectionFinder(const std::string& remote_service_uuid); |
| + ~BluetoothLowEnergyConnectionFinder() override; |
| + |
| + // Finds a connection the remote device, only the first one is functional. |
| + void Find(const device::BluetoothDevice::GattConnectionCallback& |
|
msarda
2015/04/22 08:55:15
Why this method? I think we should only have a sin
sacomoto
2015/04/22 09:44:19
I agree. This is a temporary solution while BLE co
|
| + connection_callback); |
| + void Find(const ConnectionCallback& connection_callback) override; |
| + |
| + protected: |
| + // Observer for device::BluetoothAdapter::Observer |
| + void DeviceAdded(device::BluetoothAdapter* adapter, |
| + device::BluetoothDevice* device) override; |
| + |
| + private: |
| + // Callback to be called when the Bluetooth adapter is initialized. |
| + void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter); |
| + |
| + // Callback to be called when a new discovery session is started. |
| + void OnDiscoverySessionStarted( |
| + scoped_ptr<device::BluetoothDiscoverySession> discovery_session); |
| + |
| + // Starts a discovery session for |adaptor_|. |
|
msarda
2015/04/22 08:55:15
s/adaptor_/adapter_
sacomoto
2015/04/22 09:44:19
Done.
|
| + void StartDiscoverySession(); |
| + |
| + // Stops the discovery session given by |discovery_session_|. |
| + void StopDiscoverySession(); |
| + |
| + // Checks if a service with |service_uuid| is offered by |remote_device|. |
| + bool HasService(device::BluetoothDevice* remote_device); |
| + |
| + // Creates a connection with |remote_device|, the |connection_callback_| will |
| + // be called once the connection is established. |
| + void CreateConnection(device::BluetoothDevice* remote_device); |
| + |
| + // The uuid of the service it looks for to establish a GattConnection. |
| + device::BluetoothUUID remote_service_uuid_; |
| + |
| + // The Bluetooth adapter over which the Bluetooth connection will be made. |
| + scoped_refptr<device::BluetoothAdapter> adapter_; |
| + |
| + // The discovery session associated to this object. |
| + scoped_ptr<device::BluetoothDiscoverySession> discovery_session_; |
| + |
| + // Callback called when the connection is established. |
| + device::BluetoothDevice::GattConnectionCallback connection_callback_; |
| + |
| + base::WeakPtrFactory<BluetoothLowEnergyConnectionFinder> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnectionFinder); |
| +}; |
| + |
| +} // namespace proximity_auth |
| + |
| +#endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_CONNECTION_FINDER_H |