1 // Copyright 2020 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_ADVERTISEMENT_H_ 6 #define DEVICE_BLUETOOTH_ADVERTISEMENT_H_ 7 8 #include "base/memory/ref_counted.h" 9 #include "device/bluetooth/bluetooth_advertisement.h" 10 #include "device/bluetooth/public/mojom/adapter.mojom.h" 11 12 namespace bluetooth { 13 14 // Implementation of Mojo Advertisement in 15 // device/bluetooth/public/mojom/adapter.mojom. 16 // Uses the platform abstraction of //device/bluetooth. 17 // An instance of this class is constructed by Adapter and strongly bound to its 18 // MessagePipe. When the instance is destroyed, the underlying 19 // BluetoothAdvertisement is destroyed. 20 class Advertisement : public mojom::Advertisement { 21 public: 22 explicit Advertisement( 23 scoped_refptr<device::BluetoothAdvertisement> bluetooth_advertisement); 24 ~Advertisement() override; 25 Advertisement(const Advertisement&) = delete; 26 Advertisement& operator=(const Advertisement&) = delete; 27 28 // mojom::Advertisement: 29 void Unregister(UnregisterCallback callback) override; 30 31 private: 32 void OnUnregister(UnregisterCallback callback); 33 void OnUnregisterError(UnregisterCallback callback, 34 device::BluetoothAdvertisement::ErrorCode error_code); 35 36 scoped_refptr<device::BluetoothAdvertisement> bluetooth_advertisement_; 37 38 base::WeakPtrFactory<Advertisement> weak_ptr_factory_{this}; 39 }; 40 41 } // namespace bluetooth 42 43 #endif // DEVICE_BLUETOOTH_ADVERTISEMENT_H_ 44