base_enabled_provider.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2021 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. #ifndef ASH_QUICK_PAIR_FEATURE_STATUS_TRACKER_BASE_ENABLED_PROVIDER_H_
  5. #define ASH_QUICK_PAIR_FEATURE_STATUS_TRACKER_BASE_ENABLED_PROVIDER_H_
  6. #include "base/callback.h"
  7. namespace ash {
  8. namespace quick_pair {
  9. // Common Base class to expose whether or not a feature is enabled.
  10. // Provides a |is_enabled()| method and a callback pattern to observe changes.
  11. //
  12. // Subclasses can focus on implementing the logic to determine the state of
  13. // |is_enabled()|, and this base class provides common functionality for
  14. // querying and observing that state.
  15. //
  16. // Example subclass: BluetoothEnabledProvider - Changes |is_enabled()| based on
  17. // the Bluetooth state on the device.
  18. class BaseEnabledProvider {
  19. public:
  20. BaseEnabledProvider();
  21. BaseEnabledProvider(const BaseEnabledProvider&) = delete;
  22. BaseEnabledProvider& operator=(const BaseEnabledProvider&) = delete;
  23. virtual ~BaseEnabledProvider();
  24. virtual bool is_enabled();
  25. virtual void SetCallback(base::RepeatingCallback<void(bool)> callback);
  26. protected:
  27. void SetEnabledAndInvokeCallback(bool new_value);
  28. private:
  29. bool is_enabled_ = false;
  30. base::RepeatingCallback<void(bool)> callback_;
  31. };
  32. } // namespace quick_pair
  33. } // namespace ash
  34. #endif // ASH_QUICK_PAIR_FEATURE_STATUS_TRACKER_BASE_ENABLED_PROVIDER_H_