multidevice_setup_impl.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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_MULTIDEVICE_SETUP_IMPL_H_
  5. #define ASH_SERVICES_MULTIDEVICE_SETUP_MULTIDEVICE_SETUP_IMPL_H_
  6. #include <memory>
  7. #include <string>
  8. #include "ash/services/multidevice_setup/feature_state_manager.h"
  9. #include "ash/services/multidevice_setup/global_state_feature_manager.h"
  10. #include "ash/services/multidevice_setup/host_status_provider.h"
  11. #include "ash/services/multidevice_setup/multidevice_setup_base.h"
  12. #include "ash/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h"
  13. #include "ash/services/multidevice_setup/wifi_sync_notification_controller.h"
  14. #include "mojo/public/cpp/bindings/pending_remote.h"
  15. #include "mojo/public/cpp/bindings/remote_set.h"
  16. #include "url/gurl.h"
  17. class PrefService;
  18. namespace ash {
  19. namespace device_sync {
  20. class DeviceSyncClient;
  21. class GcmDeviceInfoProvider;
  22. } // namespace device_sync
  23. namespace multidevice_setup {
  24. class AccountStatusChangeDelegateNotifier;
  25. class AndroidSmsAppHelperDelegate;
  26. class AndroidSmsPairingStateTracker;
  27. class AndroidSmsAppInstallingStatusObserver;
  28. class AuthTokenValidator;
  29. class EligibleHostDevicesProvider;
  30. class GrandfatheredEasyUnlockHostDisabler;
  31. class HostBackendDelegate;
  32. class HostDeviceTimestampManager;
  33. class HostStatusProvider;
  34. class HostVerifier;
  35. class OobeCompletionTracker;
  36. // Concrete MultiDeviceSetup implementation.
  37. class MultiDeviceSetupImpl : public MultiDeviceSetupBase,
  38. public HostStatusProvider::Observer,
  39. public FeatureStateManager::Observer {
  40. public:
  41. class Factory {
  42. public:
  43. static std::unique_ptr<MultiDeviceSetupBase> Create(
  44. PrefService* pref_service,
  45. device_sync::DeviceSyncClient* device_sync_client,
  46. AuthTokenValidator* auth_token_validator,
  47. OobeCompletionTracker* oobe_completion_tracker,
  48. AndroidSmsAppHelperDelegate* android_sms_app_helper_delegate,
  49. AndroidSmsPairingStateTracker* android_sms_pairing_state_tracker,
  50. const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider,
  51. bool is_secondary_user);
  52. static void SetFactoryForTesting(Factory* test_factory);
  53. protected:
  54. virtual ~Factory();
  55. virtual std::unique_ptr<MultiDeviceSetupBase> CreateInstance(
  56. PrefService* pref_service,
  57. device_sync::DeviceSyncClient* device_sync_client,
  58. AuthTokenValidator* auth_token_validator,
  59. OobeCompletionTracker* oobe_completion_tracker,
  60. AndroidSmsAppHelperDelegate* android_sms_app_helper_delegate,
  61. AndroidSmsPairingStateTracker* android_sms_pairing_state_tracker,
  62. const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider,
  63. bool is_secondary_user) = 0;
  64. private:
  65. static Factory* test_factory_;
  66. };
  67. MultiDeviceSetupImpl(const MultiDeviceSetupImpl&) = delete;
  68. MultiDeviceSetupImpl& operator=(const MultiDeviceSetupImpl&) = delete;
  69. ~MultiDeviceSetupImpl() override;
  70. private:
  71. friend class MultiDeviceSetupImplTest;
  72. MultiDeviceSetupImpl(
  73. PrefService* pref_service,
  74. device_sync::DeviceSyncClient* device_sync_client,
  75. AuthTokenValidator* auth_token_validator,
  76. OobeCompletionTracker* oobe_completion_tracker,
  77. AndroidSmsAppHelperDelegate* android_sms_app_helper_delegate,
  78. AndroidSmsPairingStateTracker* android_sms_pairing_state_tracker,
  79. const device_sync::GcmDeviceInfoProvider* gcm_device_info_provider,
  80. bool is_secondary_user);
  81. // mojom::MultiDeviceSetup:
  82. void SetAccountStatusChangeDelegate(
  83. mojo::PendingRemote<mojom::AccountStatusChangeDelegate> delegate)
  84. override;
  85. void AddHostStatusObserver(
  86. mojo::PendingRemote<mojom::HostStatusObserver> observer) override;
  87. void AddFeatureStateObserver(
  88. mojo::PendingRemote<mojom::FeatureStateObserver> observer) override;
  89. void GetEligibleHostDevices(GetEligibleHostDevicesCallback callback) override;
  90. void GetEligibleActiveHostDevices(
  91. GetEligibleActiveHostDevicesCallback callback) override;
  92. void SetHostDevice(const std::string& host_instance_id_or_legacy_device_id,
  93. const std::string& auth_token,
  94. SetHostDeviceCallback callback) override;
  95. void RemoveHostDevice() override;
  96. void GetHostStatus(GetHostStatusCallback callback) override;
  97. void SetFeatureEnabledState(mojom::Feature feature,
  98. bool enabled,
  99. const absl::optional<std::string>& auth_token,
  100. SetFeatureEnabledStateCallback callback) override;
  101. void GetFeatureStates(GetFeatureStatesCallback callback) override;
  102. void RetrySetHostNow(RetrySetHostNowCallback callback) override;
  103. void TriggerEventForDebugging(
  104. mojom::EventTypeForDebugging type,
  105. TriggerEventForDebuggingCallback callback) override;
  106. // MultiDeviceSetupBase:
  107. void SetHostDeviceWithoutAuthToken(
  108. const std::string& host_instance_id_or_legacy_device_id,
  109. mojom::PrivilegedHostDeviceSetter::SetHostDeviceCallback callback)
  110. override;
  111. // HostStatusProvider::Observer:
  112. void OnHostStatusChange(const HostStatusProvider::HostStatusWithDevice&
  113. host_status_with_device) override;
  114. // FeatureStateManager::Observer:
  115. void OnFeatureStatesChange(
  116. const FeatureStateManager::FeatureStatesMap& feature_states_map) override;
  117. // Attempts to set the host device, returning a boolean of whether the attempt
  118. // was successful.
  119. bool AttemptSetHost(const std::string& host_instance_id_or_legacy_device_id);
  120. bool IsAuthTokenRequiredForFeatureStateChange(mojom::Feature feature,
  121. bool enabled);
  122. void FlushForTesting();
  123. std::unique_ptr<EligibleHostDevicesProvider> eligible_host_devices_provider_;
  124. std::unique_ptr<HostBackendDelegate> host_backend_delegate_;
  125. std::unique_ptr<HostVerifier> host_verifier_;
  126. std::unique_ptr<HostStatusProvider> host_status_provider_;
  127. std::unique_ptr<GrandfatheredEasyUnlockHostDisabler>
  128. grandfathered_easy_unlock_host_disabler_;
  129. std::unique_ptr<HostDeviceTimestampManager> host_device_timestamp_manager_;
  130. std::unique_ptr<AccountStatusChangeDelegateNotifier> delegate_notifier_;
  131. std::unique_ptr<GlobalStateFeatureManager> wifi_sync_feature_manager_;
  132. std::unique_ptr<WifiSyncNotificationController>
  133. wifi_sync_notification_controller_;
  134. std::unique_ptr<FeatureStateManager> feature_state_manager_;
  135. std::unique_ptr<AndroidSmsAppInstallingStatusObserver>
  136. android_sms_app_installing_host_observer_;
  137. AuthTokenValidator* auth_token_validator_;
  138. mojo::RemoteSet<mojom::HostStatusObserver> host_status_observers_;
  139. mojo::RemoteSet<mojom::FeatureStateObserver> feature_state_observers_;
  140. };
  141. } // namespace multidevice_setup
  142. } // namespace ash
  143. #endif // ASH_SERVICES_MULTIDEVICE_SETUP_MULTIDEVICE_SETUP_IMPL_H_