quick_pair_feature_status_tracker_impl.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #include "ash/quick_pair/feature_status_tracker/quick_pair_feature_status_tracker_impl.h"
  5. #include <memory>
  6. #include "ash/quick_pair/feature_status_tracker/bluetooth_enabled_provider.h"
  7. #include "ash/quick_pair/feature_status_tracker/fast_pair_enabled_provider.h"
  8. #include "ash/quick_pair/feature_status_tracker/fast_pair_pref_enabled_provider.h"
  9. #include "ash/quick_pair/feature_status_tracker/google_api_key_availability_provider.h"
  10. #include "ash/quick_pair/feature_status_tracker/logged_in_user_enabled_provider.h"
  11. #include "ash/quick_pair/feature_status_tracker/screen_state_enabled_provider.h"
  12. #include "base/bind.h"
  13. namespace ash {
  14. namespace quick_pair {
  15. FeatureStatusTrackerImpl::FeatureStatusTrackerImpl()
  16. : fast_pair_enabled_provider_(std::make_unique<FastPairEnabledProvider>(
  17. std::make_unique<BluetoothEnabledProvider>(),
  18. std::make_unique<FastPairPrefEnabledProvider>(),
  19. std::make_unique<LoggedInUserEnabledProvider>(),
  20. std::make_unique<ScreenStateEnabledProvider>(),
  21. std::make_unique<GoogleApiKeyAvailabilityProvider>())) {
  22. fast_pair_enabled_provider_->SetCallback(
  23. base::BindRepeating(&FeatureStatusTrackerImpl::OnFastPairEnabledChanged,
  24. weak_factory_.GetWeakPtr()));
  25. }
  26. FeatureStatusTrackerImpl::~FeatureStatusTrackerImpl() = default;
  27. void FeatureStatusTrackerImpl::AddObserver(Observer* observer) {
  28. observers_.AddObserver(observer);
  29. }
  30. void FeatureStatusTrackerImpl::RemoveObserver(Observer* observer) {
  31. observers_.RemoveObserver(observer);
  32. }
  33. bool FeatureStatusTrackerImpl::IsFastPairEnabled() {
  34. return fast_pair_enabled_provider_->is_enabled();
  35. }
  36. void FeatureStatusTrackerImpl::OnFastPairEnabledChanged(bool is_enabled) {
  37. for (auto& observer : observers_) {
  38. observer.OnFastPairEnabledChanged(is_enabled);
  39. }
  40. }
  41. } // namespace quick_pair
  42. } // namespace ash