account_status_change_delegate_notifier_impl.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright 2018 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_ACCOUNT_STATUS_CHANGE_DELEGATE_NOTIFIER_IMPL_H_
  5. #define ASH_SERVICES_MULTIDEVICE_SETUP_ACCOUNT_STATUS_CHANGE_DELEGATE_NOTIFIER_IMPL_H_
  6. #include <memory>
  7. #include <string>
  8. #include "ash/services/multidevice_setup/account_status_change_delegate_notifier.h"
  9. #include "ash/services/multidevice_setup/host_status_provider.h"
  10. #include "ash/services/multidevice_setup/public/cpp/oobe_completion_tracker.h"
  11. #include "ash/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h"
  12. #include "mojo/public/cpp/bindings/pending_remote.h"
  13. #include "mojo/public/cpp/bindings/remote.h"
  14. class PrefRegistrySimple;
  15. class PrefService;
  16. namespace base {
  17. class Clock;
  18. } // namespace base
  19. namespace ash {
  20. namespace multidevice_setup {
  21. class HostDeviceTimestampManager;
  22. // Concrete AccountStatusChangeDelegateNotifier implementation, which uses
  23. // HostStatusProvider to check for account changes and PrefStore to track
  24. // previous notifications.
  25. class AccountStatusChangeDelegateNotifierImpl
  26. : public AccountStatusChangeDelegateNotifier,
  27. public HostStatusProvider::Observer,
  28. public OobeCompletionTracker::Observer {
  29. public:
  30. class Factory {
  31. public:
  32. static std::unique_ptr<AccountStatusChangeDelegateNotifier> Create(
  33. HostStatusProvider* host_status_provider,
  34. PrefService* pref_service,
  35. HostDeviceTimestampManager* host_device_timestamp_manager,
  36. OobeCompletionTracker* oobe_completion_tracker,
  37. base::Clock* clock);
  38. static void SetFactoryForTesting(Factory* test_factory);
  39. protected:
  40. virtual ~Factory();
  41. virtual std::unique_ptr<AccountStatusChangeDelegateNotifier> CreateInstance(
  42. HostStatusProvider* host_status_provider,
  43. PrefService* pref_service,
  44. HostDeviceTimestampManager* host_device_timestamp_manager,
  45. OobeCompletionTracker* oobe_completion_tracker,
  46. base::Clock* clock) = 0;
  47. private:
  48. static Factory* test_factory_;
  49. };
  50. static void RegisterPrefs(PrefRegistrySimple* registry);
  51. AccountStatusChangeDelegateNotifierImpl(
  52. const AccountStatusChangeDelegateNotifierImpl&) = delete;
  53. AccountStatusChangeDelegateNotifierImpl& operator=(
  54. const AccountStatusChangeDelegateNotifierImpl&) = delete;
  55. ~AccountStatusChangeDelegateNotifierImpl() override;
  56. void SetAccountStatusChangeDelegateRemote(
  57. mojo::PendingRemote<mojom::AccountStatusChangeDelegate> delegate_remote);
  58. private:
  59. friend class MultiDeviceSetupAccountStatusChangeDelegateNotifierTest;
  60. static const char kNewUserPotentialHostExistsPrefName[];
  61. static const char kExistingUserHostSwitchedPrefName[];
  62. static const char kExistingUserChromebookAddedPrefName[];
  63. static const char kOobeSetupFlowTimestampPrefName[];
  64. static const char
  65. kVerifiedHostDeviceIdFromMostRecentHostStatusUpdatePrefName[];
  66. AccountStatusChangeDelegateNotifierImpl(
  67. HostStatusProvider* host_status_provider,
  68. PrefService* pref_service,
  69. HostDeviceTimestampManager* host_device_timestamp_manager,
  70. OobeCompletionTracker* oobe_completion_tracker,
  71. base::Clock* clock);
  72. // AccountStatusChangeDelegateNotifier:
  73. void OnDelegateSet() override;
  74. // HostStatusProvider::Observer:
  75. void OnHostStatusChange(const HostStatusProvider::HostStatusWithDevice&
  76. host_status_with_device) override;
  77. // OobeCompletionTracker::Observer:
  78. void OnOobeCompleted() override;
  79. void CheckForMultiDeviceEvents(
  80. const HostStatusProvider::HostStatusWithDevice& host_status_with_device);
  81. void CheckForNewUserPotentialHostExistsEvent(
  82. const HostStatusProvider::HostStatusWithDevice& host_status_with_device);
  83. void CheckForNoLongerNewUserEvent(
  84. const HostStatusProvider::HostStatusWithDevice& host_status_with_device,
  85. const absl::optional<mojom::HostStatus> host_status_before_update);
  86. void CheckForExistingUserHostSwitchedEvent(
  87. const HostStatusProvider::HostStatusWithDevice& host_status_with_device,
  88. const absl::optional<std::string>& verified_host_device_id_before_update);
  89. void CheckForExistingUserChromebookAddedEvent(
  90. const HostStatusProvider::HostStatusWithDevice& host_status_with_device,
  91. const absl::optional<std::string>& verified_host_device_id_before_update);
  92. // Loads data from previous session using PrefService.
  93. absl::optional<std::string> LoadHostDeviceIdFromEndOfPreviousSession();
  94. // Set to absl::nullopt if there was no enabled host in the most recent
  95. // host status update.
  96. absl::optional<std::string> verified_host_device_id_from_most_recent_update_;
  97. // Set to absl::nullopt until the first host status update.
  98. absl::optional<mojom::HostStatus> host_status_from_most_recent_update_;
  99. mojo::Remote<mojom::AccountStatusChangeDelegate> delegate_remote_;
  100. HostStatusProvider* host_status_provider_;
  101. PrefService* pref_service_;
  102. HostDeviceTimestampManager* host_device_timestamp_manager_;
  103. OobeCompletionTracker* oobe_completion_tracker_;
  104. base::Clock* clock_;
  105. };
  106. } // namespace multidevice_setup
  107. } // namespace ash
  108. #endif // ASH_SERVICES_MULTIDEVICE_SETUP_ACCOUNT_STATUS_CHANGE_DELEGATE_NOTIFIER_IMPL_H_