wifi_sync_notification_controller.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_SERVICES_MULTIDEVICE_SETUP_WIFI_SYNC_NOTIFICATION_CONTROLLER_H_
  5. #define ASH_SERVICES_MULTIDEVICE_SETUP_WIFI_SYNC_NOTIFICATION_CONTROLLER_H_
  6. #include <memory>
  7. #include "ash/services/device_sync/public/cpp/device_sync_client.h"
  8. #include "base/memory/weak_ptr.h"
  9. #include "base/power_monitor/power_observer.h"
  10. #include "components/session_manager/core/session_manager_observer.h"
  11. class PrefRegistrySimple;
  12. class PrefService;
  13. namespace ash {
  14. namespace multidevice_setup {
  15. // Pref to track whether the announcement notification can be shown the next
  16. // time the device is unlocked with a verified host and wi-fi sync supported but
  17. // disabled.
  18. extern const char kCanShowWifiSyncAnnouncementPrefName[];
  19. class AccountStatusChangeDelegateNotifier;
  20. class GlobalStateFeatureManager;
  21. class HostStatusProvider;
  22. // Controls the setup notification for Wifi Sync.
  23. class WifiSyncNotificationController
  24. : public base::PowerSuspendObserver,
  25. public session_manager::SessionManagerObserver {
  26. public:
  27. class Factory {
  28. public:
  29. static std::unique_ptr<WifiSyncNotificationController> Create(
  30. GlobalStateFeatureManager* wifi_sync_feature_manager,
  31. HostStatusProvider* host_status_provider,
  32. PrefService* pref_service,
  33. device_sync::DeviceSyncClient* device_sync_client,
  34. AccountStatusChangeDelegateNotifier* delegate_notifier);
  35. static void SetFactoryForTesting(Factory* test_factory);
  36. protected:
  37. virtual ~Factory();
  38. virtual std::unique_ptr<WifiSyncNotificationController> CreateInstance(
  39. GlobalStateFeatureManager* wifi_sync_feature_manager,
  40. HostStatusProvider* host_status_provider,
  41. PrefService* pref_service,
  42. device_sync::DeviceSyncClient* device_sync_client,
  43. AccountStatusChangeDelegateNotifier* delegate_notifier) = 0;
  44. private:
  45. static Factory* test_factory_;
  46. };
  47. static void RegisterPrefs(PrefRegistrySimple* registry);
  48. ~WifiSyncNotificationController() override;
  49. WifiSyncNotificationController(const WifiSyncNotificationController&) =
  50. delete;
  51. WifiSyncNotificationController& operator=(
  52. const WifiSyncNotificationController&) = delete;
  53. private:
  54. WifiSyncNotificationController(
  55. GlobalStateFeatureManager* wifi_sync_feature_manager,
  56. HostStatusProvider* host_status_provider,
  57. PrefService* pref_service,
  58. device_sync::DeviceSyncClient* device_sync_client,
  59. AccountStatusChangeDelegateNotifier* delegate_notifier);
  60. // SessionManagerObserver:
  61. void OnSessionStateChanged() override;
  62. // PowerSuspendObserver:
  63. void OnResume() override;
  64. void ShowAnnouncementNotificationIfEligible();
  65. bool IsWifiSyncSupported();
  66. GlobalStateFeatureManager* wifi_sync_feature_manager_;
  67. HostStatusProvider* host_status_provider_;
  68. PrefService* pref_service_;
  69. device_sync::DeviceSyncClient* device_sync_client_;
  70. AccountStatusChangeDelegateNotifier* delegate_notifier_;
  71. bool did_register_session_observers_ = false;
  72. base::WeakPtrFactory<WifiSyncNotificationController> weak_ptr_factory_{this};
  73. };
  74. } // namespace multidevice_setup
  75. } // namespace ash
  76. #endif // ASH_SERVICES_MULTIDEVICE_SETUP_WIFI_SYNC_NOTIFICATION_CONTROLLER_H_