holding_space_animation_registry.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_SYSTEM_HOLDING_SPACE_HOLDING_SPACE_ANIMATION_REGISTRY_H_
  5. #define ASH_SYSTEM_HOLDING_SPACE_HOLDING_SPACE_ANIMATION_REGISTRY_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/shell.h"
  8. #include "ash/shell_observer.h"
  9. #include "ash/system/progress_indicator/progress_indicator_animation_registry.h"
  10. #include "base/callback.h"
  11. #include "base/callback_list.h"
  12. #include "base/scoped_observation.h"
  13. namespace ash {
  14. // A lazily initialized singleton registry for holding space animations.
  15. //
  16. // Since registered animations are owned by the singleton, they can be shared
  17. // across different UI components as well have a lifetime which is decoupled
  18. // from UI component lifetime. Note that the singleton may only exist while
  19. // `Shell` is alive and will automatically delete itself when `Shell` is being
  20. // destroyed.
  21. //
  22. // Supported animation types:
  23. // * Progress icon animation - see `ProgressIndicatorAnimationRegistry`.
  24. // * Progress ring animation - see `ProgressIndicatorAnimationRegistry`.
  25. class ASH_EXPORT HoldingSpaceAnimationRegistry
  26. : public ProgressIndicatorAnimationRegistry,
  27. public ShellObserver {
  28. public:
  29. HoldingSpaceAnimationRegistry(const HoldingSpaceAnimationRegistry&) = delete;
  30. HoldingSpaceAnimationRegistry& operator=(
  31. const HoldingSpaceAnimationRegistry&) = delete;
  32. ~HoldingSpaceAnimationRegistry() override;
  33. // Returns the lazily initialized singleton registry instance. The singleton
  34. // may only exist while `Shell` is alive and will automatically delete itself
  35. // when `Shell` is being destroyed.
  36. static HoldingSpaceAnimationRegistry* GetInstance();
  37. private:
  38. HoldingSpaceAnimationRegistry();
  39. // ShellObserver:
  40. void OnShellDestroying() override;
  41. // The delegate responsible for creating and curating progress indicator
  42. // animations based on holding space model state.
  43. class ProgressIndicatorAnimationDelegate;
  44. std::unique_ptr<ProgressIndicatorAnimationDelegate>
  45. progress_indicator_animation_delegate_;
  46. base::ScopedObservation<Shell,
  47. ShellObserver,
  48. &Shell::AddShellObserver,
  49. &Shell::RemoveShellObserver>
  50. shell_observation_{this};
  51. };
  52. } // namespace ash
  53. #endif // ASH_SYSTEM_HOLDING_SPACE_HOLDING_SPACE_ANIMATION_REGISTRY_H_