Chromium Code Reviews| Index: components/arc/bluetooth/arc_bluetooth_bridge.h |
| diff --git a/components/arc/bluetooth/arc_bluetooth_bridge.h b/components/arc/bluetooth/arc_bluetooth_bridge.h |
| index 6a484b186eeadcade42ca5649f4ef0492579475b..229922ce3b2c8d94052fc65dbaac5a7bb326ff82 100644 |
| --- a/components/arc/bluetooth/arc_bluetooth_bridge.h |
| +++ b/components/arc/bluetooth/arc_bluetooth_bridge.h |
| @@ -21,6 +21,7 @@ |
| #include "components/arc/instance_holder.h" |
| #include "device/bluetooth/bluetooth_adapter.h" |
| #include "device/bluetooth/bluetooth_adapter_factory.h" |
| +#include "device/bluetooth/bluetooth_advertisement.h" |
| #include "device/bluetooth/bluetooth_device.h" |
| #include "device/bluetooth/bluetooth_discovery_session.h" |
| #include "device/bluetooth/bluetooth_local_gatt_service.h" |
| @@ -276,6 +277,17 @@ class ArcBluetoothBridge |
| void RemoveSdpRecord(uint32_t service_handle, |
| const RemoveSdpRecordCallback& callback) override; |
| + // Set up or disable multiple advertising. |
| + void ReserveAdvertisementHandle( |
| + const ReserveAdvertisementHandleCallback& callback) override; |
| + void BroadcastAdvertisement( |
| + int32_t adv_handle, |
| + std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement, |
| + const BroadcastAdvertisementCallback& callback) override; |
| + void ReleaseAdvertisementHandle( |
| + int32_t adv_handle, |
| + const ReleaseAdvertisementHandleCallback& callback) override; |
| + |
| // Chrome observer callbacks |
| void OnPoweredOn( |
| const base::Callback<void(mojom::BluetoothAdapterState)>& callback) const; |
| @@ -382,6 +394,42 @@ class ArcBluetoothBridge |
| const device::BluetoothUUID& target_uuid, |
| bluez::BluetoothServiceRecordBlueZ::ErrorCode error_code); |
| + // Callbacks for managing advertisements registered from the instance. |
| + |
| + // Called when we have an open slot in the advertisement map and want to |
| + // register the advertisement given by |data| for handle |adv_handle|. |
| + void OnReadyToRegisterAdvertisement( |
|
Rahul Chaturvedi
2016/09/16 22:37:22
Tests for these methods?
|
| + const BroadcastAdvertisementCallback& callback, |
| + int32_t adv_handle, |
| + std::unique_ptr<device::BluetoothAdvertisement::Data> data); |
| + // Called when we've successfully registered a new advertisement for |
| + // handle |adv_handle|. |
| + void OnRegisterAdvertisementDone( |
| + const BroadcastAdvertisementCallback& callback, |
| + int32_t adv_handle, |
| + scoped_refptr<device::BluetoothAdvertisement> advertisement); |
| + // Called when the attempt to register an advertisement for handle |
| + // |adv_handle| has failed. |adv_handle| remains reserved, but no |
| + // advertisement is associated with it. |
| + void OnRegisterAdvertisementError( |
| + const BroadcastAdvertisementCallback& callback, |
| + int32_t adv_handle, |
| + device::BluetoothAdvertisement::ErrorCode error_code); |
| + // Both of the following are called after we've tried to unregister |
| + // the advertisement for |adv_handle|. Either way, we will no |
| + // longer be broadcasting this advertisement, so in either case, the |
| + // handle can be released. |
| + void OnUnregisterAdvertisementDone( |
| + const ReleaseAdvertisementHandleCallback& callback, |
| + int32_t adv_handle); |
| + void OnUnregisterAdvertisementError( |
| + const ReleaseAdvertisementHandleCallback& callback, |
| + int32_t adv_handle, |
| + device::BluetoothAdvertisement::ErrorCode error_code); |
| + // Find the next free advertisement handle and put it in *adv_handle, |
| + // or return false if the advertisement map is full. |
| + bool GetAdvertisementHandle(int32_t* adv_handle); |
| + |
| bool CalledOnValidThread(); |
| mojo::Binding<mojom::BluetoothHost> binding_; |
| @@ -411,6 +459,21 @@ class ArcBluetoothBridge |
| // Timer to turn adapter discoverable off. |
| base::OneShotTimer discoverable_off_timer_; |
| + // Holds advertising data registered by the instance. |
| + // |
| + // When a handle is reserved, an entry is placed into the advertisements_ |
| + // map. This entry is not yet associated with a device::BluetoothAdvertisement |
| + // because the instance hasn't sent us any advertising data yet, so its |
| + // mapped value is nullptr until that happens. Thus we have three states for a |
| + // handle: |
| + // * unmapped -> free |
| + // * mapped to nullptr -> reserved, awaiting data |
| + // * mapped to a device::BluetoothAdvertisement -> in use, and the mapped |
| + // BluetoothAdvertisement is currently registered with the adapter. |
| + static constexpr uint16_t kMaxAdvertisements = 5; |
|
Rahul Chaturvedi
2016/09/16 22:37:22
Is there a requirement for this to be 5? If not, l
Rahul Chaturvedi
2016/09/16 22:37:22
Don't use static constexpr's in classes for intege
|
| + std::map<int32_t, scoped_refptr<device::BluetoothAdvertisement>> |
| + advertisements_; |
| + |
| base::ThreadChecker thread_checker_; |
| // WeakPtrFactory to use for callbacks. |