Jan Wilken Doerrie | d5832e6 | 2018-08-28 16:39:50 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADVERTISEMENT_WINRT_H_ |
| 6 | #define DEVICE_BLUETOOTH_BLUETOOTH_ADVERTISEMENT_WINRT_H_ |
| 7 | |
| 8 | #include <windows.devices.bluetooth.advertisement.h> |
| 9 | #include <wrl/client.h> |
| 10 | |
| 11 | #include <memory> |
| 12 | |
| 13 | #include "base/macros.h" |
| 14 | #include "base/memory/scoped_refptr.h" |
| 15 | #include "base/memory/weak_ptr.h" |
| 16 | #include "base/optional.h" |
| 17 | #include "device/bluetooth/bluetooth_adapter.h" |
| 18 | #include "device/bluetooth/bluetooth_advertisement.h" |
| 19 | #include "device/bluetooth/bluetooth_export.h" |
| 20 | |
| 21 | namespace device { |
| 22 | |
| 23 | class DEVICE_BLUETOOTH_EXPORT BluetoothAdvertisementWinrt |
| 24 | : public BluetoothAdvertisement { |
| 25 | public: |
| 26 | BluetoothAdvertisementWinrt(); |
| 27 | bool Initialize( |
| 28 | std::unique_ptr<BluetoothAdvertisement::Data> advertisement_data); |
| 29 | void Register(SuccessCallback callback, ErrorCallback error_callback); |
| 30 | |
| 31 | // BluetoothAdvertisement: |
| 32 | void Unregister(const SuccessCallback& success_callback, |
| 33 | const ErrorCallback& error_callback) override; |
| 34 | |
| 35 | ABI::Windows::Devices::Bluetooth::Advertisement:: |
| 36 | IBluetoothLEAdvertisementPublisher* |
| 37 | GetPublisherForTesting(); |
| 38 | |
| 39 | protected: |
| 40 | ~BluetoothAdvertisementWinrt() override; |
| 41 | |
| 42 | // These are declared virtual so that they can be overridden by tests. |
| 43 | virtual HRESULT GetBluetoothLEAdvertisementPublisherActivationFactory( |
| 44 | ABI::Windows::Devices::Bluetooth::Advertisement:: |
| 45 | IBluetoothLEAdvertisementPublisherFactory** factory) const; |
| 46 | |
| 47 | virtual HRESULT ActivateBluetoothLEAdvertisementInstance( |
| 48 | ABI::Windows::Devices::Bluetooth::Advertisement:: |
| 49 | IBluetoothLEAdvertisement** instance) const; |
| 50 | |
| 51 | virtual HRESULT GetBluetoothLEManufacturerDataFactory( |
| 52 | ABI::Windows::Devices::Bluetooth::Advertisement:: |
| 53 | IBluetoothLEManufacturerDataFactory** factory) const; |
| 54 | |
| 55 | private: |
| 56 | struct PendingCallbacks { |
| 57 | PendingCallbacks(SuccessCallback callback, ErrorCallback error_callback); |
| 58 | ~PendingCallbacks(); |
| 59 | |
| 60 | SuccessCallback callback; |
| 61 | ErrorCallback error_callback; |
| 62 | }; |
| 63 | |
| 64 | void OnStatusChanged( |
| 65 | ABI::Windows::Devices::Bluetooth::Advertisement:: |
| 66 | IBluetoothLEAdvertisementPublisher* publisher, |
| 67 | ABI::Windows::Devices::Bluetooth::Advertisement:: |
| 68 | IBluetoothLEAdvertisementPublisherStatusChangedEventArgs* changed); |
| 69 | |
| 70 | Microsoft::WRL::ComPtr<ABI::Windows::Devices::Bluetooth::Advertisement:: |
| 71 | IBluetoothLEAdvertisementPublisher> |
| 72 | publisher_; |
| 73 | base::Optional<EventRegistrationToken> status_changed_token_; |
| 74 | std::unique_ptr<PendingCallbacks> pending_register_callbacks_; |
| 75 | std::unique_ptr<PendingCallbacks> pending_unregister_callbacks_; |
| 76 | |
Jeremy Roman | 2b7c950 | 2019-08-21 22:34:08 | [diff] [blame] | 77 | base::WeakPtrFactory<BluetoothAdvertisementWinrt> weak_ptr_factory_{this}; |
Jan Wilken Doerrie | d5832e6 | 2018-08-28 16:39:50 | [diff] [blame] | 78 | |
| 79 | DISALLOW_COPY_AND_ASSIGN(BluetoothAdvertisementWinrt); |
| 80 | }; |
| 81 | |
| 82 | } // namespace device |
| 83 | |
| 84 | #endif // DEVICE_BLUETOOTH_BLUETOOTH_ADVERTISEMENT_WINRT_H_ |