shelf_controller.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2016 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_SHELF_SHELF_CONTROLLER_H_
  5. #define ASH_SHELF_SHELF_CONTROLLER_H_
  6. #include <memory>
  7. #include <string>
  8. #include "ash/ash_export.h"
  9. #include "ash/display/window_tree_host_manager.h"
  10. #include "ash/public/cpp/session/session_observer.h"
  11. #include "ash/public/cpp/shelf_model.h"
  12. #include "ash/public/cpp/shelf_model_observer.h"
  13. #include "ash/public/cpp/tablet_mode_observer.h"
  14. #include "components/services/app_service/public/cpp/app_registry_cache.h"
  15. #include "components/services/app_service/public/cpp/app_update.h"
  16. class PrefChangeRegistrar;
  17. class PrefRegistrySimple;
  18. namespace ash {
  19. class LauncherNudgeController;
  20. // ShelfController owns the ShelfModel and manages shelf preferences.
  21. // ChromeShelfController and related classes largely manage the ShelfModel.
  22. class ASH_EXPORT ShelfController : public SessionObserver,
  23. public TabletModeObserver,
  24. public WindowTreeHostManager::Observer,
  25. public apps::AppRegistryCache::Observer,
  26. public ShelfModelObserver {
  27. public:
  28. ShelfController();
  29. ShelfController(const ShelfController&) = delete;
  30. ShelfController& operator=(const ShelfController&) = delete;
  31. ~ShelfController() override;
  32. // Creates `launcher_nudge_controller_` instance which needs AppListController
  33. // instance to construct.
  34. void Init();
  35. // Removes observers from this object's dependencies.
  36. void Shutdown();
  37. static void RegisterProfilePrefs(PrefRegistrySimple* registry);
  38. ShelfModel* model() { return &model_; }
  39. LauncherNudgeController* launcher_nudge_controller() const {
  40. return launcher_nudge_controller_.get();
  41. }
  42. private:
  43. // SessionObserver:
  44. void OnActiveUserSessionChanged(const AccountId& account_id) override;
  45. void OnSessionStateChanged(session_manager::SessionState state) override;
  46. void OnActiveUserPrefServiceChanged(PrefService* pref_service) override;
  47. // TabletModeObserver:
  48. void OnTabletModeStarted() override;
  49. void OnTabletModeEnded() override;
  50. // WindowTreeHostManager::Observer:
  51. void OnDisplayConfigurationChanged() override;
  52. // apps::AppRegistryCache::Observer:
  53. void OnAppUpdate(const apps::AppUpdate& update) override;
  54. void OnAppRegistryCacheWillBeDestroyed(
  55. apps::AppRegistryCache* cache) override;
  56. // ShelfModelObserver:
  57. void ShelfItemAdded(int index) override;
  58. // Updates whether an app notification badge is shown for the shelf items in
  59. // the model.
  60. void UpdateAppNotificationBadging();
  61. // The shelf model shared by all shelf instances.
  62. ShelfModel model_;
  63. // The controller of the launcher nudge that animates the home button.
  64. std::unique_ptr<LauncherNudgeController> launcher_nudge_controller_;
  65. // Whether the pref for notification badging is enabled.
  66. absl::optional<bool> notification_badging_pref_enabled_;
  67. // Observes user profile prefs for the shelf.
  68. std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
  69. // Observed to update notification badging on shelf items. Also used to get
  70. // initial notification badge information when shelf items are added.
  71. apps::AppRegistryCache* cache_ = nullptr;
  72. };
  73. } // namespace ash
  74. #endif // ASH_SHELF_SHELF_CONTROLLER_H_