phone_hub_manager_impl.cc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. // Copyright 2020 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/components/phonehub/phone_hub_manager_impl.h"
  5. #include "ash/components/phonehub/browser_tabs_metadata_fetcher.h"
  6. #include "ash/components/phonehub/browser_tabs_model_controller.h"
  7. #include "ash/components/phonehub/browser_tabs_model_provider.h"
  8. #include "ash/components/phonehub/camera_roll_download_manager.h"
  9. #include "ash/components/phonehub/camera_roll_manager_impl.h"
  10. #include "ash/components/phonehub/connection_scheduler_impl.h"
  11. #include "ash/components/phonehub/cros_state_sender.h"
  12. #include "ash/components/phonehub/do_not_disturb_controller_impl.h"
  13. #include "ash/components/phonehub/feature_status_provider_impl.h"
  14. #include "ash/components/phonehub/find_my_device_controller_impl.h"
  15. #include "ash/components/phonehub/icon_decoder.h"
  16. #include "ash/components/phonehub/icon_decoder_impl.h"
  17. #include "ash/components/phonehub/invalid_connection_disconnector.h"
  18. #include "ash/components/phonehub/message_receiver_impl.h"
  19. #include "ash/components/phonehub/message_sender_impl.h"
  20. #include "ash/components/phonehub/multidevice_feature_access_manager_impl.h"
  21. #include "ash/components/phonehub/multidevice_setup_state_updater.h"
  22. #include "ash/components/phonehub/mutable_phone_model.h"
  23. #include "ash/components/phonehub/notification_interaction_handler_impl.h"
  24. #include "ash/components/phonehub/notification_manager_impl.h"
  25. #include "ash/components/phonehub/notification_processor.h"
  26. #include "ash/components/phonehub/onboarding_ui_tracker_impl.h"
  27. #include "ash/components/phonehub/phone_hub_metrics_recorder.h"
  28. #include "ash/components/phonehub/phone_model.h"
  29. #include "ash/components/phonehub/phone_status_processor.h"
  30. #include "ash/components/phonehub/recent_apps_interaction_handler_impl.h"
  31. #include "ash/components/phonehub/screen_lock_manager_impl.h"
  32. #include "ash/components/phonehub/tether_controller_impl.h"
  33. #include "ash/components/phonehub/user_action_recorder_impl.h"
  34. #include "ash/constants/ash_features.h"
  35. #include "ash/services/secure_channel/public/cpp/client/connection_manager_impl.h"
  36. #include "chromeos/dbus/power/power_manager_client.h"
  37. #include "components/session_manager/core/session_manager.h"
  38. namespace ash {
  39. namespace {
  40. const char kSecureChannelFeatureName[] = "phone_hub";
  41. } // namespace
  42. namespace phonehub {
  43. PhoneHubManagerImpl::PhoneHubManagerImpl(
  44. PrefService* pref_service,
  45. device_sync::DeviceSyncClient* device_sync_client,
  46. multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client,
  47. secure_channel::SecureChannelClient* secure_channel_client,
  48. std::unique_ptr<BrowserTabsModelProvider> browser_tabs_model_provider,
  49. std::unique_ptr<CameraRollDownloadManager> camera_roll_download_manager,
  50. const base::RepeatingClosure& show_multidevice_setup_dialog_callback)
  51. : connection_manager_(
  52. std::make_unique<secure_channel::ConnectionManagerImpl>(
  53. multidevice_setup_client,
  54. device_sync_client,
  55. secure_channel_client,
  56. kSecureChannelFeatureName,
  57. std::make_unique<PhoneHubMetricsRecorder>())),
  58. feature_status_provider_(std::make_unique<FeatureStatusProviderImpl>(
  59. device_sync_client,
  60. multidevice_setup_client,
  61. connection_manager_.get(),
  62. session_manager::SessionManager::Get(),
  63. chromeos::PowerManagerClient::Get())),
  64. user_action_recorder_(std::make_unique<UserActionRecorderImpl>(
  65. feature_status_provider_.get())),
  66. message_receiver_(
  67. std::make_unique<MessageReceiverImpl>(connection_manager_.get())),
  68. message_sender_(
  69. std::make_unique<MessageSenderImpl>(connection_manager_.get())),
  70. phone_model_(std::make_unique<MutablePhoneModel>()),
  71. cros_state_sender_(
  72. std::make_unique<CrosStateSender>(message_sender_.get(),
  73. connection_manager_.get(),
  74. multidevice_setup_client,
  75. phone_model_.get())),
  76. do_not_disturb_controller_(std::make_unique<DoNotDisturbControllerImpl>(
  77. message_sender_.get(),
  78. user_action_recorder_.get())),
  79. connection_scheduler_(std::make_unique<ConnectionSchedulerImpl>(
  80. connection_manager_.get(),
  81. feature_status_provider_.get())),
  82. find_my_device_controller_(std::make_unique<FindMyDeviceControllerImpl>(
  83. message_sender_.get(),
  84. user_action_recorder_.get())),
  85. multidevice_feature_access_manager_(
  86. std::make_unique<MultideviceFeatureAccessManagerImpl>(
  87. pref_service,
  88. multidevice_setup_client,
  89. feature_status_provider_.get(),
  90. message_sender_.get(),
  91. connection_scheduler_.get())),
  92. screen_lock_manager_(
  93. features::IsEcheSWAEnabled()
  94. ? std::make_unique<ScreenLockManagerImpl>(pref_service)
  95. : nullptr),
  96. notification_interaction_handler_(
  97. features::IsEcheSWAEnabled()
  98. ? std::make_unique<NotificationInteractionHandlerImpl>()
  99. : nullptr),
  100. notification_manager_(
  101. std::make_unique<NotificationManagerImpl>(message_sender_.get(),
  102. user_action_recorder_.get(),
  103. multidevice_setup_client)),
  104. onboarding_ui_tracker_(std::make_unique<OnboardingUiTrackerImpl>(
  105. pref_service,
  106. feature_status_provider_.get(),
  107. multidevice_setup_client,
  108. show_multidevice_setup_dialog_callback)),
  109. notification_processor_(
  110. std::make_unique<NotificationProcessor>(notification_manager_.get())),
  111. recent_apps_interaction_handler_(
  112. features::IsEcheSWAEnabled()
  113. ? std::make_unique<RecentAppsInteractionHandlerImpl>(
  114. pref_service,
  115. multidevice_setup_client,
  116. multidevice_feature_access_manager_.get(),
  117. std::make_unique<IconDecoderImpl>())
  118. : nullptr),
  119. phone_status_processor_(std::make_unique<PhoneStatusProcessor>(
  120. do_not_disturb_controller_.get(),
  121. feature_status_provider_.get(),
  122. message_receiver_.get(),
  123. find_my_device_controller_.get(),
  124. multidevice_feature_access_manager_.get(),
  125. screen_lock_manager_.get(),
  126. notification_processor_.get(),
  127. multidevice_setup_client,
  128. phone_model_.get(),
  129. recent_apps_interaction_handler_.get())),
  130. tether_controller_(
  131. std::make_unique<TetherControllerImpl>(phone_model_.get(),
  132. user_action_recorder_.get(),
  133. multidevice_setup_client)),
  134. browser_tabs_model_provider_(std::move(browser_tabs_model_provider)),
  135. browser_tabs_model_controller_(
  136. std::make_unique<BrowserTabsModelController>(
  137. multidevice_setup_client,
  138. browser_tabs_model_provider_.get(),
  139. phone_model_.get())),
  140. multidevice_setup_state_updater_(
  141. std::make_unique<MultideviceSetupStateUpdater>(
  142. pref_service,
  143. multidevice_setup_client,
  144. multidevice_feature_access_manager_.get())),
  145. invalid_connection_disconnector_(
  146. std::make_unique<InvalidConnectionDisconnector>(
  147. connection_manager_.get(),
  148. phone_model_.get())),
  149. camera_roll_manager_(features::IsPhoneHubCameraRollEnabled()
  150. ? std::make_unique<CameraRollManagerImpl>(
  151. message_receiver_.get(),
  152. message_sender_.get(),
  153. multidevice_setup_client,
  154. connection_manager_.get(),
  155. std::move(camera_roll_download_manager))
  156. : nullptr),
  157. feature_setup_response_processor_(
  158. features::IsPhoneHubFeatureSetupErrorHandlingEnabled()
  159. ? std::make_unique<FeatureSetupResponseProcessor>(
  160. message_receiver_.get(),
  161. multidevice_feature_access_manager_.get())
  162. : nullptr) {}
  163. PhoneHubManagerImpl::~PhoneHubManagerImpl() = default;
  164. BrowserTabsModelProvider* PhoneHubManagerImpl::GetBrowserTabsModelProvider() {
  165. return browser_tabs_model_provider_.get();
  166. }
  167. CameraRollManager* PhoneHubManagerImpl::GetCameraRollManager() {
  168. return camera_roll_manager_.get();
  169. }
  170. ConnectionScheduler* PhoneHubManagerImpl::GetConnectionScheduler() {
  171. return connection_scheduler_.get();
  172. }
  173. DoNotDisturbController* PhoneHubManagerImpl::GetDoNotDisturbController() {
  174. return do_not_disturb_controller_.get();
  175. }
  176. FeatureStatusProvider* PhoneHubManagerImpl::GetFeatureStatusProvider() {
  177. return feature_status_provider_.get();
  178. }
  179. FindMyDeviceController* PhoneHubManagerImpl::GetFindMyDeviceController() {
  180. return find_my_device_controller_.get();
  181. }
  182. MultideviceFeatureAccessManager*
  183. PhoneHubManagerImpl::GetMultideviceFeatureAccessManager() {
  184. return multidevice_feature_access_manager_.get();
  185. }
  186. NotificationInteractionHandler*
  187. PhoneHubManagerImpl::GetNotificationInteractionHandler() {
  188. return notification_interaction_handler_.get();
  189. }
  190. NotificationManager* PhoneHubManagerImpl::GetNotificationManager() {
  191. return notification_manager_.get();
  192. }
  193. OnboardingUiTracker* PhoneHubManagerImpl::GetOnboardingUiTracker() {
  194. return onboarding_ui_tracker_.get();
  195. }
  196. PhoneModel* PhoneHubManagerImpl::GetPhoneModel() {
  197. return phone_model_.get();
  198. }
  199. RecentAppsInteractionHandler*
  200. PhoneHubManagerImpl::GetRecentAppsInteractionHandler() {
  201. return recent_apps_interaction_handler_.get();
  202. }
  203. ScreenLockManager* PhoneHubManagerImpl::GetScreenLockManager() {
  204. return screen_lock_manager_.get();
  205. }
  206. TetherController* PhoneHubManagerImpl::GetTetherController() {
  207. return tether_controller_.get();
  208. }
  209. UserActionRecorder* PhoneHubManagerImpl::GetUserActionRecorder() {
  210. return user_action_recorder_.get();
  211. }
  212. void PhoneHubManagerImpl::GetHostLastSeenTimestamp(
  213. base::OnceCallback<void(absl::optional<base::Time>)> callback) {
  214. connection_manager_->GetHostLastSeenTimestamp(std::move(callback));
  215. }
  216. // NOTE: These should be destroyed in the opposite order of how these objects
  217. // are initialized in the constructor.
  218. void PhoneHubManagerImpl::Shutdown() {
  219. feature_setup_response_processor_.reset();
  220. camera_roll_manager_.reset();
  221. invalid_connection_disconnector_.reset();
  222. multidevice_setup_state_updater_.reset();
  223. browser_tabs_model_controller_.reset();
  224. browser_tabs_model_provider_.reset();
  225. tether_controller_.reset();
  226. phone_status_processor_.reset();
  227. recent_apps_interaction_handler_.reset();
  228. notification_processor_.reset();
  229. onboarding_ui_tracker_.reset();
  230. notification_manager_.reset();
  231. notification_interaction_handler_.reset();
  232. screen_lock_manager_.reset();
  233. multidevice_feature_access_manager_.reset();
  234. find_my_device_controller_.reset();
  235. connection_scheduler_.reset();
  236. do_not_disturb_controller_.reset();
  237. cros_state_sender_.reset();
  238. phone_model_.reset();
  239. message_sender_.reset();
  240. message_receiver_.reset();
  241. user_action_recorder_.reset();
  242. feature_status_provider_.reset();
  243. connection_manager_.reset();
  244. }
  245. } // namespace phonehub
  246. } // namespace ash