system_tray_model.cc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. #include "ash/system/model/system_tray_model.h"
  5. #include <memory>
  6. #include "ash/components/phonehub/phone_hub_manager.h"
  7. #include "ash/public/cpp/login_types.h"
  8. #include "ash/public/cpp/update_types.h"
  9. #include "ash/root_window_controller.h"
  10. #include "ash/shell.h"
  11. #include "ash/system/message_center/message_center_controller.h"
  12. #include "ash/system/model/clock_model.h"
  13. #include "ash/system/model/enterprise_domain_model.h"
  14. #include "ash/system/model/locale_model.h"
  15. #include "ash/system/model/session_length_limit_model.h"
  16. #include "ash/system/model/tracing_model.h"
  17. #include "ash/system/model/update_model.h"
  18. #include "ash/system/model/virtual_keyboard_model.h"
  19. #include "ash/system/network/active_network_icon.h"
  20. #include "ash/system/network/tray_network_state_model.h"
  21. #include "ash/system/phonehub/phone_hub_notification_controller.h"
  22. #include "ash/system/phonehub/phone_hub_tray.h"
  23. #include "ash/system/status_area_widget.h"
  24. #include "ash/system/time/calendar_model.h"
  25. #include "ash/system/time/calendar_utils.h"
  26. #include "ash/system/unified/unified_system_tray.h"
  27. namespace ash {
  28. SystemTrayModel::SystemTrayModel()
  29. : clock_(std::make_unique<ClockModel>()),
  30. enterprise_domain_(std::make_unique<EnterpriseDomainModel>()),
  31. locale_(std::make_unique<LocaleModel>()),
  32. session_length_limit_(std::make_unique<SessionLengthLimitModel>()),
  33. tracing_(std::make_unique<TracingModel>()),
  34. update_model_(std::make_unique<UpdateModel>()),
  35. virtual_keyboard_(std::make_unique<VirtualKeyboardModel>()),
  36. network_state_model_(std::make_unique<TrayNetworkStateModel>()),
  37. active_network_icon_(
  38. std::make_unique<ActiveNetworkIcon>(network_state_model_.get())),
  39. calendar_model_(std::make_unique<CalendarModel>()) {}
  40. SystemTrayModel::~SystemTrayModel() = default;
  41. void SystemTrayModel::SetClient(SystemTrayClient* client) {
  42. client_ = client;
  43. }
  44. void SystemTrayModel::SetPrimaryTrayEnabled(bool enabled) {
  45. UnifiedSystemTray* tray = Shell::GetPrimaryRootWindowController()
  46. ->GetStatusAreaWidget()
  47. ->unified_system_tray();
  48. if (!tray)
  49. return;
  50. tray->SetTrayEnabled(enabled);
  51. }
  52. void SystemTrayModel::SetPrimaryTrayVisible(bool visible) {
  53. auto* status_area =
  54. Shell::GetPrimaryRootWindowController()->GetStatusAreaWidget();
  55. if (status_area)
  56. status_area->SetSystemTrayVisibility(visible);
  57. }
  58. void SystemTrayModel::SetUse24HourClock(bool use_24_hour) {
  59. clock()->SetUse24HourClock(use_24_hour);
  60. }
  61. void SystemTrayModel::SetDeviceEnterpriseInfo(
  62. const DeviceEnterpriseInfo& device_enterprise_info) {
  63. enterprise_domain()->SetDeviceEnterpriseInfo(device_enterprise_info);
  64. }
  65. void SystemTrayModel::SetEnterpriseAccountDomainInfo(
  66. const std::string& account_domain_manager) {
  67. enterprise_domain()->SetEnterpriseAccountDomainInfo(account_domain_manager);
  68. }
  69. void SystemTrayModel::SetPerformanceTracingIconVisible(bool visible) {
  70. tracing()->SetIsTracing(visible);
  71. }
  72. void SystemTrayModel::SetLocaleList(
  73. std::vector<LocaleInfo> locale_list,
  74. const std::string& current_locale_iso_code) {
  75. locale()->SetLocaleList(std::move(locale_list), current_locale_iso_code);
  76. }
  77. void SystemTrayModel::ShowUpdateIcon(UpdateSeverity severity,
  78. bool factory_reset_required,
  79. bool rollback,
  80. UpdateType update_type) {
  81. update_model()->SetUpdateAvailable(severity, factory_reset_required, rollback,
  82. update_type);
  83. }
  84. void SystemTrayModel::SetRelaunchNotificationState(
  85. const RelaunchNotificationState& relaunch_notification_state) {
  86. update_model()->SetRelaunchNotificationState(relaunch_notification_state);
  87. }
  88. void SystemTrayModel::ResetUpdateState() {
  89. update_model()->ResetUpdateAvailable();
  90. }
  91. void SystemTrayModel::SetUpdateDeferred(DeferredUpdateState state) {
  92. update_model()->SetUpdateDeferred(state);
  93. }
  94. void SystemTrayModel::SetUpdateOverCellularAvailableIconVisible(bool visible) {
  95. update_model()->SetUpdateOverCellularAvailable(visible);
  96. }
  97. void SystemTrayModel::ShowVolumeSliderBubble() {
  98. // Show the bubble on all monitors with a system tray.
  99. for (RootWindowController* root : Shell::GetAllRootWindowControllers()) {
  100. UnifiedSystemTray* system_tray =
  101. root->GetStatusAreaWidget()->unified_system_tray();
  102. if (!system_tray)
  103. continue;
  104. system_tray->ShowVolumeSliderBubble();
  105. }
  106. }
  107. void SystemTrayModel::ShowNetworkDetailedViewBubble() {
  108. // Show the bubble on the primary display.
  109. UnifiedSystemTray* system_tray = Shell::GetPrimaryRootWindowController()
  110. ->GetStatusAreaWidget()
  111. ->unified_system_tray();
  112. if (system_tray)
  113. system_tray->ShowNetworkDetailedViewBubble();
  114. }
  115. void SystemTrayModel::SetPhoneHubManager(
  116. phonehub::PhoneHubManager* phone_hub_manager) {
  117. for (RootWindowController* root_window_controller :
  118. Shell::GetAllRootWindowControllers()) {
  119. auto* phone_hub_tray =
  120. root_window_controller->GetStatusAreaWidget()->phone_hub_tray();
  121. phone_hub_tray->SetPhoneHubManager(phone_hub_manager);
  122. }
  123. Shell::Get()
  124. ->message_center_controller()
  125. ->phone_hub_notification_controller()
  126. ->SetManager(phone_hub_manager);
  127. }
  128. } // namespace ash