eche_app_manager.cc 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. #include "ash/webui/eche_app_ui/eche_app_manager.h"
  5. #include <memory>
  6. #include "ash/components/phonehub/phone_hub_manager.h"
  7. #include "ash/constants/ash_features.h"
  8. #include "ash/public/cpp/network_config_service.h"
  9. #include "ash/services/secure_channel/public/cpp/client/connection_manager_impl.h"
  10. #include "ash/webui/eche_app_ui/apps_access_manager_impl.h"
  11. #include "ash/webui/eche_app_ui/eche_alert_generator.h"
  12. #include "ash/webui/eche_app_ui/eche_connection_metrics_recorder.h"
  13. #include "ash/webui/eche_app_ui/eche_connection_scheduler_impl.h"
  14. #include "ash/webui/eche_app_ui/eche_connector_impl.h"
  15. #include "ash/webui/eche_app_ui/eche_message_receiver_impl.h"
  16. #include "ash/webui/eche_app_ui/eche_presence_manager.h"
  17. #include "ash/webui/eche_app_ui/eche_signaler.h"
  18. #include "ash/webui/eche_app_ui/eche_stream_status_change_handler.h"
  19. #include "ash/webui/eche_app_ui/eche_tray_stream_status_observer.h"
  20. #include "ash/webui/eche_app_ui/eche_uid_provider.h"
  21. #include "ash/webui/eche_app_ui/launch_app_helper.h"
  22. #include "ash/webui/eche_app_ui/system_info.h"
  23. #include "ash/webui/eche_app_ui/system_info_provider.h"
  24. #include "base/system/sys_info.h"
  25. namespace ash {
  26. namespace {
  27. const char kSecureChannelFeatureName[] = "eche";
  28. } // namespace
  29. namespace eche_app {
  30. EcheAppManager::EcheAppManager(
  31. PrefService* pref_service,
  32. std::unique_ptr<SystemInfo> system_info,
  33. phonehub::PhoneHubManager* phone_hub_manager,
  34. device_sync::DeviceSyncClient* device_sync_client,
  35. multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client,
  36. secure_channel::SecureChannelClient* secure_channel_client,
  37. std::unique_ptr<secure_channel::PresenceMonitorClient>
  38. presence_monitor_client,
  39. LaunchAppHelper::LaunchEcheAppFunction launch_eche_app_function,
  40. LaunchAppHelper::LaunchNotificationFunction launch_notification_function,
  41. LaunchAppHelper::CloseNotificationFunction close_notification_function)
  42. : connection_manager_(
  43. std::make_unique<secure_channel::ConnectionManagerImpl>(
  44. multidevice_setup_client,
  45. device_sync_client,
  46. secure_channel_client,
  47. kSecureChannelFeatureName,
  48. std::make_unique<EcheConnectionMetricsRecorder>())),
  49. feature_status_provider_(std::make_unique<EcheFeatureStatusProvider>(
  50. phone_hub_manager,
  51. device_sync_client,
  52. multidevice_setup_client,
  53. connection_manager_.get())),
  54. launch_app_helper_(
  55. std::make_unique<LaunchAppHelper>(phone_hub_manager,
  56. launch_eche_app_function,
  57. launch_notification_function,
  58. close_notification_function)),
  59. stream_status_change_handler_(
  60. std::make_unique<EcheStreamStatusChangeHandler>()),
  61. eche_notification_click_handler_(
  62. std::make_unique<EcheNotificationClickHandler>(
  63. phone_hub_manager,
  64. feature_status_provider_.get(),
  65. launch_app_helper_.get())),
  66. connection_scheduler_(std::make_unique<EcheConnectionSchedulerImpl>(
  67. connection_manager_.get(),
  68. feature_status_provider_.get())),
  69. eche_connector_(
  70. std::make_unique<EcheConnectorImpl>(feature_status_provider_.get(),
  71. connection_manager_.get(),
  72. connection_scheduler_.get())),
  73. signaler_(std::make_unique<EcheSignaler>(eche_connector_.get(),
  74. connection_manager_.get())),
  75. message_receiver_(
  76. std::make_unique<EcheMessageReceiverImpl>(connection_manager_.get())),
  77. eche_presence_manager_(std::make_unique<EchePresenceManager>(
  78. feature_status_provider_.get(),
  79. device_sync_client,
  80. multidevice_setup_client,
  81. std::move(presence_monitor_client),
  82. eche_connector_.get(),
  83. message_receiver_.get())),
  84. uid_(std::make_unique<EcheUidProvider>(pref_service)),
  85. eche_recent_app_click_handler_(
  86. std::make_unique<EcheRecentAppClickHandler>(
  87. phone_hub_manager,
  88. feature_status_provider_.get(),
  89. launch_app_helper_.get(),
  90. stream_status_change_handler_.get())),
  91. alert_generator_(
  92. std::make_unique<EcheAlertGenerator>(launch_app_helper_.get(),
  93. pref_service)),
  94. apps_access_manager_(std::make_unique<AppsAccessManagerImpl>(
  95. eche_connector_.get(),
  96. message_receiver_.get(),
  97. feature_status_provider_.get(),
  98. pref_service,
  99. multidevice_setup_client,
  100. connection_manager_.get())),
  101. eche_tray_stream_status_observer_(
  102. std::make_unique<EcheTrayStreamStatusObserver>(
  103. stream_status_change_handler_.get(),
  104. feature_status_provider_.get())) {
  105. ash::GetNetworkConfigService(
  106. remote_cros_network_config_.BindNewPipeAndPassReceiver());
  107. system_info_provider_ = std::make_unique<SystemInfoProvider>(
  108. std::move(system_info), remote_cros_network_config_.get());
  109. }
  110. EcheAppManager::~EcheAppManager() = default;
  111. void EcheAppManager::BindSignalingMessageExchangerInterface(
  112. mojo::PendingReceiver<mojom::SignalingMessageExchanger> receiver) {
  113. signaler_->Bind(std::move(receiver));
  114. }
  115. void EcheAppManager::BindSystemInfoProviderInterface(
  116. mojo::PendingReceiver<mojom::SystemInfoProvider> receiver) {
  117. system_info_provider_->Bind(std::move(receiver));
  118. }
  119. void EcheAppManager::BindUidGeneratorInterface(
  120. mojo::PendingReceiver<mojom::UidGenerator> receiver) {
  121. uid_->Bind(std::move(receiver));
  122. }
  123. void EcheAppManager::BindNotificationGeneratorInterface(
  124. mojo::PendingReceiver<mojom::NotificationGenerator> receiver) {
  125. alert_generator_->Bind(std::move(receiver));
  126. }
  127. void EcheAppManager::BindDisplayStreamHandlerInterface(
  128. mojo::PendingReceiver<mojom::DisplayStreamHandler> receiver) {
  129. stream_status_change_handler_->Bind(std::move(receiver));
  130. }
  131. AppsAccessManager* EcheAppManager::GetAppsAccessManager() {
  132. return apps_access_manager_.get();
  133. }
  134. void EcheAppManager::CloseStream() {
  135. stream_status_change_handler_->CloseStream();
  136. }
  137. void EcheAppManager::StreamGoBack() {
  138. stream_status_change_handler_->StreamGoBack();
  139. }
  140. // NOTE: These should be destroyed in the opposite order of how these objects
  141. // are initialized in the constructor.
  142. void EcheAppManager::Shutdown() {
  143. system_info_provider_.reset();
  144. eche_tray_stream_status_observer_.reset();
  145. apps_access_manager_.reset();
  146. alert_generator_.reset();
  147. eche_recent_app_click_handler_.reset();
  148. uid_.reset();
  149. eche_presence_manager_.reset();
  150. message_receiver_.reset();
  151. signaler_.reset();
  152. eche_connector_.reset();
  153. connection_scheduler_.reset();
  154. eche_notification_click_handler_.reset();
  155. stream_status_change_handler_.reset();
  156. launch_app_helper_.reset();
  157. feature_status_provider_.reset();
  158. connection_manager_.reset();
  159. }
  160. } // namespace eche_app
  161. } // namespace ash