cellular_setup_notifier.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_NETWORK_CELLULAR_SETUP_NOTIFIER_H_
  5. #define ASH_SYSTEM_NETWORK_CELLULAR_SETUP_NOTIFIER_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/public/cpp/session/session_observer.h"
  8. #include "base/gtest_prod_util.h"
  9. #include "chromeos/services/network_config/public/cpp/cros_network_config_observer.h"
  10. #include "components/prefs/pref_service.h"
  11. #include "mojo/public/cpp/bindings/remote.h"
  12. class PrefRegistrySimple;
  13. namespace base {
  14. class OneShotTimer;
  15. } // namespace base
  16. namespace ash {
  17. // Notifies the user after OOBE to finish setting up their cellular network if
  18. // user has a device with eSIM but no profiles have been configured, or they
  19. // inserted a cold pSIM and need to provision in-session.
  20. class ASH_EXPORT CellularSetupNotifier
  21. : public SessionObserver,
  22. public chromeos::network_config::CrosNetworkConfigObserver {
  23. public:
  24. CellularSetupNotifier();
  25. CellularSetupNotifier(const CellularSetupNotifier&) = delete;
  26. CellularSetupNotifier& operator=(const CellularSetupNotifier&) = delete;
  27. ~CellularSetupNotifier() override;
  28. static void RegisterProfilePrefs(PrefRegistrySimple* registry);
  29. private:
  30. friend class CellularSetupNotifierTest;
  31. FRIEND_TEST_ALL_PREFIXES(CellularSetupNotifierTest,
  32. DontShowNotificationUnfinishedOOBE);
  33. FRIEND_TEST_ALL_PREFIXES(CellularSetupNotifierTest,
  34. ShowNotificationUnactivatedNetwork);
  35. FRIEND_TEST_ALL_PREFIXES(CellularSetupNotifierTest,
  36. DontShowNotificationActivatedNetwork);
  37. FRIEND_TEST_ALL_PREFIXES(CellularSetupNotifierTest,
  38. ShowNotificationMultipleUnactivatedNetworks);
  39. FRIEND_TEST_ALL_PREFIXES(CellularSetupNotifierTest,
  40. LogOutBeforeNotificationShowsLogInAgain);
  41. FRIEND_TEST_ALL_PREFIXES(CellularSetupNotifierTest,
  42. LogInAgainAfterShowingNotification);
  43. FRIEND_TEST_ALL_PREFIXES(CellularSetupNotifierTest,
  44. LogInAgainAfterCheckingNonCellularDevice);
  45. // SessionObserver:
  46. void OnSessionStateChanged(session_manager::SessionState state) override;
  47. // CrosNetworkConfigObserver:
  48. void OnNetworkStateListChanged() override;
  49. void OnNetworkStateChanged(
  50. chromeos::network_config::mojom::NetworkStatePropertiesPtr network)
  51. override;
  52. void MaybeShowCellularSetupNotification();
  53. void OnTimerFired();
  54. void OnGetDeviceStateList(
  55. std::vector<chromeos::network_config::mojom::DeviceStatePropertiesPtr>
  56. devices);
  57. void OnCellularNetworksList(
  58. std::vector<chromeos::network_config::mojom::NetworkStatePropertiesPtr>
  59. networks);
  60. void ShowCellularSetupNotification();
  61. void SetTimerForTesting(std::unique_ptr<base::OneShotTimer> test_timer) {
  62. timer_ = std::move(test_timer);
  63. }
  64. static const char kCellularSetupNotificationId[];
  65. mojo::Remote<chromeos::network_config::mojom::CrosNetworkConfig>
  66. remote_cros_network_config_;
  67. mojo::Receiver<chromeos::network_config::mojom::CrosNetworkConfigObserver>
  68. cros_network_config_observer_receiver_{this};
  69. std::unique_ptr<base::OneShotTimer> timer_;
  70. bool timer_fired_{false};
  71. };
  72. } // namespace ash
  73. #endif // ASH_SYSTEM_NETWORK_CELLULAR_SETUP_NOTIFIER_H_