autozoom_controller_impl.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2022 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_SYSTEM_CAMERA_AUTOZOOM_CONTROLLER_IMPL_H_
  5. #define ASH_SYSTEM_CAMERA_AUTOZOOM_CONTROLLER_IMPL_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/public/cpp/session/session_observer.h"
  8. #include "ash/system/camera/autozoom_nudge_controller.h"
  9. #include "ash/system/camera/autozoom_observer.h"
  10. #include "base/observer_list.h"
  11. #include "components/prefs/pref_change_registrar.h"
  12. #include "components/prefs/pref_registry_simple.h"
  13. #include "components/prefs/pref_service.h"
  14. #include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h"
  15. #include "media/capture/video/chromeos/mojom/cros_camera_service.mojom.h"
  16. namespace ash {
  17. // Controls the Autozoom feature that, when enabled, intelligently
  18. // pans/tilts/zooms the camera to frame a set of regions of interest captured
  19. // by the camera.
  20. class ASH_EXPORT AutozoomControllerImpl
  21. : public SessionObserver,
  22. public media::CameraActiveClientObserver {
  23. public:
  24. AutozoomControllerImpl();
  25. AutozoomControllerImpl(const AutozoomControllerImpl&) = delete;
  26. AutozoomControllerImpl& operator=(const AutozoomControllerImpl&) = delete;
  27. ~AutozoomControllerImpl() override;
  28. static void RegisterProfilePrefs(PrefRegistrySimple* registry);
  29. void SetState(cros::mojom::CameraAutoFramingState state);
  30. cros::mojom::CameraAutoFramingState GetState();
  31. void Toggle();
  32. void AddObserver(AutozoomObserver* observer);
  33. void RemoveObserver(AutozoomObserver* observer);
  34. bool IsAutozoomControlEnabled();
  35. // SessionObserver:
  36. void OnActiveUserPrefServiceChanged(PrefService* pref_service) override;
  37. private:
  38. void InitFromUserPrefs();
  39. void Refresh();
  40. void StartWatchingPrefsChanges();
  41. // Called when the user pref for the enabled status of Autozoom is changed.
  42. void OnStatePrefChanged();
  43. void SetAutozoomSupported(bool autozoom_supported);
  44. // CameraActiveClientObserver
  45. void OnActiveClientChange(cros::mojom::CameraClientType type,
  46. bool is_active) override;
  47. // The pref service of the currently active user. Can be null in
  48. // ash_unittests.
  49. PrefService* active_user_pref_service_ = nullptr;
  50. // The registrar used to watch Autozoom prefs changes in the above
  51. // |active_user_pref_service_| from outside ash.
  52. // NOTE: Prefs are how Chrome communicates changes to the Autozoom settings
  53. // controlled by this class.
  54. std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
  55. cros::mojom::CameraAutoFramingState state_ =
  56. cros::mojom::CameraAutoFramingState::OFF;
  57. base::ObserverList<AutozoomObserver> observers_;
  58. std::unique_ptr<AutozoomNudgeController> nudge_controller_;
  59. bool autozoom_supported_ = false;
  60. // The number of current active camera clients. Autozoom control should only
  61. // be shown when there's at least one active camera client.
  62. int active_camera_client_count_ = 0;
  63. // All methods of this class should be run on the same sequence.
  64. SEQUENCE_CHECKER(sequence_checker_);
  65. base::WeakPtrFactory<AutozoomControllerImpl> weak_ptr_factory_{this};
  66. };
  67. } // namespace ash
  68. #endif // ASH_SYSTEM_CAMERA_AUTOZOOM_CONTROLLER_IMPL_H_