Tetsui Ohkubo | 2172293 | 2018-03-02 02:56:56 | [diff] [blame] | 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 | |
| 5 | #include "ash/system/model/system_tray_model.h" |
| 6 | |
Tetsui Ohkubo | 3679446 | 2018-06-29 07:26:02 | [diff] [blame] | 7 | #include "ash/root_window_controller.h" |
| 8 | #include "ash/shell.h" |
Tim Song | 4434c75 | 2020-09-17 10:24:47 | [diff] [blame] | 9 | #include "ash/system/message_center/message_center_controller.h" |
Tetsui Ohkubo | 6ab6ae1 | 2018-03-28 06:26:07 | [diff] [blame] | 10 | #include "ash/system/model/clock_model.h" |
Tetsui Ohkubo | 2172293 | 2018-03-02 02:56:56 | [diff] [blame] | 11 | #include "ash/system/model/enterprise_domain_model.h" |
Wenzhao Zang | bdf7734 | 2018-12-12 00:24:45 | [diff] [blame] | 12 | #include "ash/system/model/locale_model.h" |
Tetsui Ohkubo | 9090a19 | 2018-04-18 00:20:39 | [diff] [blame] | 13 | #include "ash/system/model/session_length_limit_model.h" |
Tetsui Ohkubo | ac7b967 | 2018-03-28 02:43:45 | [diff] [blame] | 14 | #include "ash/system/model/tracing_model.h" |
Tetsui Ohkubo | 335179a | 2018-03-28 05:18:19 | [diff] [blame] | 15 | #include "ash/system/model/update_model.h" |
Tetsui Ohkubo | 852abe6 | 2018-10-03 02:52:27 | [diff] [blame] | 16 | #include "ash/system/model/virtual_keyboard_model.h" |
Steven Bennetts | 71ac265 | 2019-02-07 00:32:51 | [diff] [blame] | 17 | #include "ash/system/network/active_network_icon.h" |
Steven Bennetts | 02abafd | 2019-05-22 14:47:02 | [diff] [blame] | 18 | #include "ash/system/network/tray_network_state_model.h" |
Tim Song | 4434c75 | 2020-09-17 10:24:47 | [diff] [blame] | 19 | #include "ash/system/phonehub/phone_hub_notification_controller.h" |
Tim Song | b32e781 | 2020-09-11 22:42:19 | [diff] [blame] | 20 | #include "ash/system/phonehub/phone_hub_tray.h" |
Tetsui Ohkubo | 3679446 | 2018-06-29 07:26:02 | [diff] [blame] | 21 | #include "ash/system/status_area_widget.h" |
Tetsui Ohkubo | 3679446 | 2018-06-29 07:26:02 | [diff] [blame] | 22 | #include "ash/system/unified/unified_system_tray.h" |
Tim Song | b32e781 | 2020-09-11 22:42:19 | [diff] [blame] | 23 | #include "chromeos/components/phonehub/phone_hub_manager.h" |
Tetsui Ohkubo | 2172293 | 2018-03-02 02:56:56 | [diff] [blame] | 24 | |
| 25 | namespace ash { |
| 26 | |
Ken Rockot | 80738e4 | 2019-08-15 20:34:57 | [diff] [blame] | 27 | SystemTrayModel::SystemTrayModel() |
Tetsui Ohkubo | 6ab6ae1 | 2018-03-28 06:26:07 | [diff] [blame] | 28 | : clock_(std::make_unique<ClockModel>()), |
| 29 | enterprise_domain_(std::make_unique<EnterpriseDomainModel>()), |
Wenzhao Zang | bdf7734 | 2018-12-12 00:24:45 | [diff] [blame] | 30 | locale_(std::make_unique<LocaleModel>()), |
Tetsui Ohkubo | 9090a19 | 2018-04-18 00:20:39 | [diff] [blame] | 31 | session_length_limit_(std::make_unique<SessionLengthLimitModel>()), |
Tetsui Ohkubo | 335179a | 2018-03-28 05:18:19 | [diff] [blame] | 32 | tracing_(std::make_unique<TracingModel>()), |
Tetsui Ohkubo | 852abe6 | 2018-10-03 02:52:27 | [diff] [blame] | 33 | update_model_(std::make_unique<UpdateModel>()), |
Steven Bennetts | 71ac265 | 2019-02-07 00:32:51 | [diff] [blame] | 34 | virtual_keyboard_(std::make_unique<VirtualKeyboardModel>()), |
Ken Rockot | 80738e4 | 2019-08-15 20:34:57 | [diff] [blame] | 35 | network_state_model_(std::make_unique<TrayNetworkStateModel>()), |
Steven Bennetts | 64682d74 | 2019-05-21 19:16:06 | [diff] [blame] | 36 | active_network_icon_( |
Ken Rockot | 80738e4 | 2019-08-15 20:34:57 | [diff] [blame] | 37 | std::make_unique<ActiveNetworkIcon>(network_state_model_.get())) {} |
Tetsui Ohkubo | 2172293 | 2018-03-02 02:56:56 | [diff] [blame] | 38 | |
| 39 | SystemTrayModel::~SystemTrayModel() = default; |
| 40 | |
James Cook | a354b3b | 2019-05-22 23:15:38 | [diff] [blame] | 41 | void SystemTrayModel::SetClient(SystemTrayClient* client) { |
| 42 | client_ = client; |
Tetsui Ohkubo | ac7b967 | 2018-03-28 02:43:45 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | void SystemTrayModel::SetPrimaryTrayEnabled(bool enabled) { |
Tetsui Ohkubo | d013252 | 2018-10-29 03:08:37 | [diff] [blame] | 46 | UnifiedSystemTray* tray = Shell::GetPrimaryRootWindowController() |
| 47 | ->GetStatusAreaWidget() |
| 48 | ->unified_system_tray(); |
| 49 | if (!tray) |
| 50 | return; |
| 51 | tray->SetTrayEnabled(enabled); |
Tetsui Ohkubo | ac7b967 | 2018-03-28 02:43:45 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | void SystemTrayModel::SetPrimaryTrayVisible(bool visible) { |
Tetsui Ohkubo | 3679446 | 2018-06-29 07:26:02 | [diff] [blame] | 55 | auto* status_area = |
| 56 | Shell::GetPrimaryRootWindowController()->GetStatusAreaWidget(); |
| 57 | if (status_area) |
| 58 | status_area->SetSystemTrayVisibility(visible); |
Tetsui Ohkubo | ac7b967 | 2018-03-28 02:43:45 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void SystemTrayModel::SetUse24HourClock(bool use_24_hour) { |
Tetsui Ohkubo | 6ab6ae1 | 2018-03-28 06:26:07 | [diff] [blame] | 62 | clock()->SetUse24HourClock(use_24_hour); |
Tetsui Ohkubo | ac7b967 | 2018-03-28 02:43:45 | [diff] [blame] | 63 | } |
| 64 | |
Brian Malcolm | 1246992d | 2020-10-07 18:11:57 | [diff] [blame] | 65 | void SystemTrayModel::SetEnterpriseDomainInfo( |
| 66 | const std::string& enterprise_domain_manager, |
Tetsui Ohkubo | ac7b967 | 2018-03-28 02:43:45 | [diff] [blame] | 67 | bool active_directory_managed) { |
Brian Malcolm | 1246992d | 2020-10-07 18:11:57 | [diff] [blame] | 68 | enterprise_domain()->SetEnterpriseDomainInfo(enterprise_domain_manager, |
| 69 | active_directory_managed); |
Tetsui Ohkubo | ac7b967 | 2018-03-28 02:43:45 | [diff] [blame] | 70 | } |
| 71 | |
Andre Le | 7cc5fc3 | 2021-02-18 00:54:02 | [diff] [blame] | 72 | void SystemTrayModel::SetEnterpriseAccountDomainInfo( |
| 73 | const std::string& account_domain_manager) { |
| 74 | enterprise_domain()->SetEnterpriseAccountDomainInfo(account_domain_manager); |
| 75 | } |
| 76 | |
Tetsui Ohkubo | ac7b967 | 2018-03-28 02:43:45 | [diff] [blame] | 77 | void SystemTrayModel::SetPerformanceTracingIconVisible(bool visible) { |
| 78 | tracing()->SetIsTracing(visible); |
| 79 | } |
| 80 | |
Wenzhao Zang | 0cb311d7 | 2018-11-15 22:42:31 | [diff] [blame] | 81 | void SystemTrayModel::SetLocaleList( |
Xiyuan Xia | be4303e7 | 2019-06-06 18:14:50 | [diff] [blame] | 82 | std::vector<LocaleInfo> locale_list, |
Wenzhao Zang | 0cb311d7 | 2018-11-15 22:42:31 | [diff] [blame] | 83 | const std::string& current_locale_iso_code) { |
Wenzhao Zang | bdf7734 | 2018-12-12 00:24:45 | [diff] [blame] | 84 | locale()->SetLocaleList(std::move(locale_list), current_locale_iso_code); |
Wenzhao Zang | 0cb311d7 | 2018-11-15 22:42:31 | [diff] [blame] | 85 | } |
| 86 | |
Xiyuan Xia | b6fc248 | 2019-06-05 20:45:04 | [diff] [blame] | 87 | void SystemTrayModel::ShowUpdateIcon(UpdateSeverity severity, |
Tetsui Ohkubo | ac7b967 | 2018-03-28 02:43:45 | [diff] [blame] | 88 | bool factory_reset_required, |
Marton Hunyady | 37ecdeb | 2018-07-20 18:10:07 | [diff] [blame] | 89 | bool rollback, |
Xiyuan Xia | b6fc248 | 2019-06-05 20:45:04 | [diff] [blame] | 90 | UpdateType update_type) { |
Marton Hunyady | 37ecdeb | 2018-07-20 18:10:07 | [diff] [blame] | 91 | update_model()->SetUpdateAvailable(severity, factory_reset_required, rollback, |
Tetsui Ohkubo | 335179a | 2018-03-28 05:18:19 | [diff] [blame] | 92 | update_type); |
Tetsui Ohkubo | ac7b967 | 2018-03-28 02:43:45 | [diff] [blame] | 93 | } |
| 94 | |
Stefan Teodorescu | e2f0139 | 2018-08-22 19:13:43 | [diff] [blame] | 95 | void SystemTrayModel::SetUpdateNotificationState( |
Xiyuan Xia | b6fc248 | 2019-06-05 20:45:04 | [diff] [blame] | 96 | NotificationStyle style, |
Jan Wilken Dörrie | 85285b0 | 2021-03-11 23:38:47 | [diff] [blame^] | 97 | const std::u16string& notification_title, |
| 98 | const std::u16string& notification_body) { |
Stefan Teodorescu | e2f0139 | 2018-08-22 19:13:43 | [diff] [blame] | 99 | update_model()->SetUpdateNotificationState(style, notification_title, |
| 100 | notification_body); |
| 101 | } |
| 102 | |
Tetsui Ohkubo | ac7b967 | 2018-03-28 02:43:45 | [diff] [blame] | 103 | void SystemTrayModel::SetUpdateOverCellularAvailableIconVisible(bool visible) { |
Tetsui Ohkubo | 335179a | 2018-03-28 05:18:19 | [diff] [blame] | 104 | update_model()->SetUpdateOverCellularAvailable(visible); |
Tetsui Ohkubo | ac7b967 | 2018-03-28 02:43:45 | [diff] [blame] | 105 | } |
| 106 | |
Tetsui Ohkubo | eb0879f | 2018-06-11 22:52:51 | [diff] [blame] | 107 | void SystemTrayModel::ShowVolumeSliderBubble() { |
Tetsui Ohkubo | 3679446 | 2018-06-29 07:26:02 | [diff] [blame] | 108 | // Show the bubble on all monitors with a system tray. |
Tetsui Ohkubo | d013252 | 2018-10-29 03:08:37 | [diff] [blame] | 109 | for (RootWindowController* root : Shell::GetAllRootWindowControllers()) { |
| 110 | UnifiedSystemTray* system_tray = |
| 111 | root->GetStatusAreaWidget()->unified_system_tray(); |
| 112 | if (!system_tray) |
| 113 | continue; |
| 114 | system_tray->ShowVolumeSliderBubble(); |
Tetsui Ohkubo | 3679446 | 2018-06-29 07:26:02 | [diff] [blame] | 115 | } |
Tetsui Ohkubo | eb0879f | 2018-06-11 22:52:51 | [diff] [blame] | 116 | } |
| 117 | |
Ahmed Mehfooz | 15cebdd | 2021-03-03 01:07:07 | [diff] [blame] | 118 | void SystemTrayModel::ShowNetworkDetailedViewBubble() { |
Petr Smirnov | 9db99f13 | 2019-09-25 21:07:37 | [diff] [blame] | 119 | // Show the bubble on the primary display. |
| 120 | UnifiedSystemTray* system_tray = Shell::GetPrimaryRootWindowController() |
| 121 | ->GetStatusAreaWidget() |
| 122 | ->unified_system_tray(); |
| 123 | if (system_tray) |
Ahmed Mehfooz | 15cebdd | 2021-03-03 01:07:07 | [diff] [blame] | 124 | system_tray->ShowNetworkDetailedViewBubble(); |
Petr Smirnov | 9db99f13 | 2019-09-25 21:07:37 | [diff] [blame] | 125 | } |
| 126 | |
Kyle Horimoto | f4b8e3d | 2020-08-21 23:35:28 | [diff] [blame] | 127 | void SystemTrayModel::SetPhoneHubManager( |
| 128 | chromeos::phonehub::PhoneHubManager* phone_hub_manager) { |
Andre Le | 4a5d5cd | 2020-12-08 20:04:15 | [diff] [blame] | 129 | for (RootWindowController* root_window_controller : |
| 130 | Shell::GetAllRootWindowControllers()) { |
| 131 | auto* phone_hub_tray = |
| 132 | root_window_controller->GetStatusAreaWidget()->phone_hub_tray(); |
| 133 | phone_hub_tray->SetPhoneHubManager(phone_hub_manager); |
| 134 | } |
Tim Song | 4434c75 | 2020-09-17 10:24:47 | [diff] [blame] | 135 | |
| 136 | Shell::Get() |
| 137 | ->message_center_controller() |
| 138 | ->phone_hub_notification_controller() |
Andre Le | aeb1a90 | 2020-10-27 18:53:56 | [diff] [blame] | 139 | ->SetManager(phone_hub_manager); |
Kyle Horimoto | f4b8e3d | 2020-08-21 23:35:28 | [diff] [blame] | 140 | } |
| 141 | |
Tetsui Ohkubo | 2172293 | 2018-03-02 02:56:56 | [diff] [blame] | 142 | } // namespace ash |