host_status_provider_impl.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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_HOST_STATUS_PROVIDER_IMPL_H_
  5. #define ASH_SERVICES_MULTIDEVICE_SETUP_HOST_STATUS_PROVIDER_IMPL_H_
  6. #include "ash/components/multidevice/remote_device_ref.h"
  7. #include "ash/services/device_sync/public/cpp/device_sync_client.h"
  8. #include "ash/services/multidevice_setup/host_backend_delegate.h"
  9. #include "ash/services/multidevice_setup/host_status_provider.h"
  10. #include "ash/services/multidevice_setup/host_verifier.h"
  11. #include "base/timer/timer.h"
  12. namespace ash {
  13. namespace multidevice_setup {
  14. class EligibleHostDevicesProvider;
  15. // Concrete HostStatusProvider implementation. This class listens for events
  16. // from HostBackendDelegate, HostVerifier, and DeviceSyncClient to determine
  17. // when the status of the host has changed.
  18. class HostStatusProviderImpl : public HostStatusProvider,
  19. public HostBackendDelegate::Observer,
  20. public HostVerifier::Observer,
  21. public device_sync::DeviceSyncClient::Observer {
  22. public:
  23. class Factory {
  24. public:
  25. static std::unique_ptr<HostStatusProvider> Create(
  26. EligibleHostDevicesProvider* eligible_host_devices_provider,
  27. HostBackendDelegate* host_backend_delegate,
  28. HostVerifier* host_verifier,
  29. device_sync::DeviceSyncClient* device_sync_client);
  30. static void SetFactoryForTesting(Factory* test_factory);
  31. protected:
  32. virtual ~Factory();
  33. virtual std::unique_ptr<HostStatusProvider> CreateInstance(
  34. EligibleHostDevicesProvider* eligible_host_devices_provider,
  35. HostBackendDelegate* host_backend_delegate,
  36. HostVerifier* host_verifier,
  37. device_sync::DeviceSyncClient* device_sync_client) = 0;
  38. private:
  39. static Factory* test_factory_;
  40. };
  41. HostStatusProviderImpl(const HostStatusProviderImpl&) = delete;
  42. HostStatusProviderImpl& operator=(const HostStatusProviderImpl&) = delete;
  43. ~HostStatusProviderImpl() override;
  44. private:
  45. HostStatusProviderImpl(
  46. EligibleHostDevicesProvider* eligible_host_devices_provider,
  47. HostBackendDelegate* host_backend_delegate,
  48. HostVerifier* host_verifier,
  49. device_sync::DeviceSyncClient* device_sync_client);
  50. // HostStatusProvider:
  51. HostStatusWithDevice GetHostWithStatus() const override;
  52. // HostBackendDelegate::Observer:
  53. void OnHostChangedOnBackend() override;
  54. void OnPendingHostRequestChange() override;
  55. // HostVerifier::Observer:
  56. void OnHostVerified() override;
  57. // device_sync::DeviceSyncClient::Observer:
  58. void OnNewDevicesSynced() override;
  59. void CheckForUpdatedStatusAndNotifyIfChanged(
  60. bool force_notify_host_status_change);
  61. HostStatusWithDevice GetCurrentStatus();
  62. // Record the host status on sign-in, on status change, and every 30 minutes.
  63. // The latter is necessary to capture users who stay logged in for days.
  64. void RecordMultiDeviceHostStatus();
  65. EligibleHostDevicesProvider* eligible_host_devices_provider_;
  66. HostBackendDelegate* host_backend_delegate_;
  67. HostVerifier* host_verifier_;
  68. device_sync::DeviceSyncClient* device_sync_client_;
  69. HostStatusWithDevice current_status_and_device_;
  70. base::RepeatingTimer host_status_metric_timer_;
  71. };
  72. } // namespace multidevice_setup
  73. } // namespace ash
  74. #endif // ASH_SERVICES_MULTIDEVICE_SETUP_HOST_STATUS_PROVIDER_IMPL_H_