eche_presence_manager.h 2.9 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_WEBUI_ECHE_APP_UI_ECHE_PRESENCE_MANAGER_H_
  5. #define ASH_WEBUI_ECHE_APP_UI_ECHE_PRESENCE_MANAGER_H_
  6. #include <memory>
  7. // TODO(https://crbug.com/1164001): move to forward declaration.
  8. #include "ash/services/secure_channel/public/cpp/client/presence_monitor_client.h"
  9. #include "ash/webui/eche_app_ui/eche_feature_status_provider.h"
  10. #include "ash/webui/eche_app_ui/eche_message_receiver.h"
  11. #include "ash/webui/eche_app_ui/feature_status_provider.h"
  12. #include "base/memory/weak_ptr.h"
  13. #include "base/time/time.h"
  14. #include "base/timer/timer.h"
  15. namespace ash {
  16. namespace device_sync {
  17. class DeviceSyncClient;
  18. }
  19. namespace multidevice_setup {
  20. class MultiDeviceSetupClient;
  21. }
  22. namespace eche_app {
  23. class EcheConnector;
  24. // Control presence monitoring and the sending of keepalives.
  25. class EchePresenceManager : public FeatureStatusProvider::Observer,
  26. public EcheMessageReceiver::Observer {
  27. public:
  28. EchePresenceManager(
  29. FeatureStatusProvider* eche_feature_status_provider,
  30. device_sync::DeviceSyncClient* device_sync_client,
  31. multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client,
  32. std::unique_ptr<secure_channel::PresenceMonitorClient>
  33. presence_monitor_client,
  34. EcheConnector* eche_connector,
  35. EcheMessageReceiver* eche_message_receiver);
  36. ~EchePresenceManager() override;
  37. EchePresenceManager(const EchePresenceManager&) = delete;
  38. EchePresenceManager& operator=(const EchePresenceManager&) = delete;
  39. private:
  40. // FeatureStatusProvider::Observer:
  41. void OnFeatureStatusChanged() override;
  42. // EcheMessageReceiver::Observer:
  43. void OnStatusChange(proto::StatusChangeType status_change_type) override;
  44. void OnSendAppsSetupResponseReceived(
  45. proto::SendAppsSetupResponse apps_setup_response) override {}
  46. void OnGetAppsAccessStateResponseReceived(
  47. proto::GetAppsAccessStateResponse apps_access_state_response) override {}
  48. void OnAppPolicyStateChange(
  49. proto::AppStreamingPolicy app_policy_state) override {}
  50. void OnReady();
  51. void OnDeviceSeen();
  52. void UpdateMonitoringStatus();
  53. void StartMonitoring();
  54. void StopMonitoring();
  55. void OnTimerExpired();
  56. FeatureStatusProvider* eche_feature_status_provider_;
  57. device_sync::DeviceSyncClient* device_sync_client_;
  58. multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client_;
  59. std::unique_ptr<secure_channel::PresenceMonitorClient>
  60. presence_monitor_client_;
  61. EcheConnector* eche_connector_;
  62. EcheMessageReceiver* eche_message_receiver_;
  63. base::RepeatingTimer timer_;
  64. bool stream_running_ = false;
  65. bool is_monitoring_ = false;
  66. base::TimeTicks device_last_seen_time_;
  67. base::WeakPtrFactory<EchePresenceManager> weak_ptr_factory_{this};
  68. };
  69. } // namespace eche_app
  70. } // namespace ash
  71. #endif // ASH_WEBUI_ECHE_APP_UI_ECHE_PRESENCE_MANAGER_H_