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..74b16c2f7aef17bcdb2d87fe7f46eb8cc8882a6e |
| --- /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 |
|
msarda
2015/04/22 15:58:13
This comment must be explicit about the fact that
sacomoto
2015/04/24 14:04:56
Done.
|
| +// 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 15:58:13
Please add a comment explaining that this method c
msarda
2015/04/22 15:58:13
I somehow feel we need to add an empty implementat
sacomoto
2015/04/24 14:04:56
Yes.
Actually, I think it would be better to hav
sacomoto
2015/04/24 14:04:57
My next CL already implements proximity_auth::Conn
msarda
2015/04/24 14:12:16
Ok.
|
| + 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); |
|
msarda
2015/04/22 15:58:13
Why is this private and DeviceAdded is protected?
sacomoto
2015/04/24 14:04:57
DeviceAdded is part of the BluetoothAdapter::Obser
|
| + |
| + // Callback to be called when a new discovery session is started. |
| + void OnDiscoverySessionStarted( |
| + scoped_ptr<device::BluetoothDiscoverySession> discovery_session); |
| + |
| + // Starts a discovery session for |adapter_|. |
| + 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 |
|
msarda
2015/04/22 15:58:13
s/a connection/a GATT connection
s/, the |coonnect
sacomoto
2015/04/24 14:04:57
Done.
|
| + // 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 |