Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/ash/system_tray_client.h" | 5 #include "chrome/browser/ui/ash/system_tray_client.h" |
| 6 | 6 |
| 7 #include "ash/login_status.h" | 7 #include "ash/login_status.h" |
| 8 #include "ash/public/cpp/shell_window_ids.h" | 8 #include "ash/public/cpp/shell_window_ids.h" |
| 9 #include "ash/public/interfaces/constants.mojom.h" | 9 #include "ash/public/interfaces/constants.mojom.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/metrics/user_metrics.h" | 14 #include "base/metrics/user_metrics.h" |
| 15 #include "base/single_thread_task_runner.h" | |
| 16 #include "base/threading/thread_task_runner_handle.h" | |
| 17 #include "base/time/time.h" | |
| 14 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/browser_process_platform_part.h" | 19 #include "chrome/browser/browser_process_platform_part.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" | 21 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" |
| 18 #include "chrome/browser/chromeos/bluetooth/bluetooth_pairing_dialog.h" | 22 #include "chrome/browser/chromeos/bluetooth/bluetooth_pairing_dialog.h" |
| 19 #include "chrome/browser/chromeos/login/help_app_launcher.h" | 23 #include "chrome/browser/chromeos/login/help_app_launcher.h" |
| 20 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 24 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 21 #include "chrome/browser/chromeos/options/network_config_view.h" | 25 #include "chrome/browser/chromeos/options/network_config_view.h" |
| 22 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 26 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 23 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 27 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 54 #include "services/service_manager/public/cpp/connector.h" | 58 #include "services/service_manager/public/cpp/connector.h" |
| 55 #include "services/ui/public/cpp/property_type_converters.h" | 59 #include "services/ui/public/cpp/property_type_converters.h" |
| 56 #include "services/ui/public/interfaces/window_manager.mojom.h" | 60 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 57 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" | 61 #include "third_party/cros_system_api/dbus/shill/dbus-constants.h" |
| 58 #include "ui/views/widget/widget.h" | 62 #include "ui/views/widget/widget.h" |
| 59 #include "ui/views/window/dialog_delegate.h" | 63 #include "ui/views/window/dialog_delegate.h" |
| 60 | 64 |
| 61 using chromeos::BluetoothPairingDialog; | 65 using chromeos::BluetoothPairingDialog; |
| 62 using chromeos::DBusThreadManager; | 66 using chromeos::DBusThreadManager; |
| 63 using chromeos::LoginState; | 67 using chromeos::LoginState; |
| 68 using chromeos::UpdateEngineClient; | |
| 64 using device::BluetoothDevice; | 69 using device::BluetoothDevice; |
| 65 using views::Widget; | 70 using views::Widget; |
| 66 | 71 |
| 67 namespace { | 72 namespace { |
| 68 | 73 |
| 69 SystemTrayClient* g_instance = nullptr; | 74 SystemTrayClient* g_instance = nullptr; |
| 70 | 75 |
| 71 void ShowSettingsSubPageForActiveUser(const std::string& sub_page) { | 76 void ShowSettingsSubPageForActiveUser(const std::string& sub_page) { |
| 72 chrome::ShowSettingsSubPageForProfile(ProfileManager::GetActiveUserProfile(), | 77 chrome::ShowSettingsSubPageForProfile(ProfileManager::GetActiveUserProfile(), |
| 73 sub_page); | 78 sub_page); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 101 ->BindInterface(ash::mojom::kServiceName, &system_tray_); | 106 ->BindInterface(ash::mojom::kServiceName, &system_tray_); |
| 102 // Register this object as the client interface implementation. | 107 // Register this object as the client interface implementation. |
| 103 system_tray_->SetClient(binding_.CreateInterfacePtrAndBind()); | 108 system_tray_->SetClient(binding_.CreateInterfacePtrAndBind()); |
| 104 | 109 |
| 105 // If this observes clock setting changes before ash comes up the IPCs will | 110 // If this observes clock setting changes before ash comes up the IPCs will |
| 106 // be queued on |system_tray_|. | 111 // be queued on |system_tray_|. |
| 107 g_browser_process->platform_part()->GetSystemClock()->AddObserver(this); | 112 g_browser_process->platform_part()->GetSystemClock()->AddObserver(this); |
| 108 | 113 |
| 109 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 114 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
| 110 content::NotificationService::AllSources()); | 115 content::NotificationService::AllSources()); |
| 116 registrar_.Add(this, chrome::NOTIFICATION_UPDATE_OVER_CELLULAR_AVAILABLE, | |
| 117 content::NotificationService::AllSources()); | |
| 111 | 118 |
| 112 // If an upgrade is available at startup then tell ash about it. | 119 // If an upgrade is available at startup then tell ash about it. |
| 113 if (UpgradeDetector::GetInstance()->notify_upgrade()) | 120 if (UpgradeDetector::GetInstance()->notify_upgrade()) |
| 114 HandleUpdateAvailable(); | 121 HandleUpdateAvailable(); |
| 115 | 122 |
| 116 // If the device is enterprise managed then send ash the enterprise domain. | 123 // If the device is enterprise managed then send ash the enterprise domain. |
| 117 policy::BrowserPolicyConnectorChromeOS* policy_connector = | 124 policy::BrowserPolicyConnectorChromeOS* policy_connector = |
| 118 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 125 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 119 policy::DeviceCloudPolicyManagerChromeOS* policy_manager = | 126 policy::DeviceCloudPolicyManagerChromeOS* policy_manager = |
| 120 policy_connector->GetDeviceCloudPolicyManager(); | 127 policy_connector->GetDeviceCloudPolicyManager(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 return ash::LoginStatus::SUPERVISED; | 178 return ash::LoginStatus::SUPERVISED; |
| 172 case LoginState::LOGGED_IN_USER_KIOSK_APP: | 179 case LoginState::LOGGED_IN_USER_KIOSK_APP: |
| 173 return ash::LoginStatus::KIOSK_APP; | 180 return ash::LoginStatus::KIOSK_APP; |
| 174 case LoginState::LOGGED_IN_USER_ARC_KIOSK_APP: | 181 case LoginState::LOGGED_IN_USER_ARC_KIOSK_APP: |
| 175 return ash::LoginStatus::ARC_KIOSK_APP; | 182 return ash::LoginStatus::ARC_KIOSK_APP; |
| 176 } | 183 } |
| 177 NOTREACHED(); | 184 NOTREACHED(); |
| 178 return ash::LoginStatus::NOT_LOGGED_IN; | 185 return ash::LoginStatus::NOT_LOGGED_IN; |
| 179 } | 186 } |
| 180 | 187 |
| 188 void SystemTrayClient::ScheduleRequestUpdateCheck() { | |
| 189 base::WeakPtrFactory<SystemTrayClient> weak_ptr_factory_(this); | |
| 190 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 191 FROM_HERE, | |
| 192 base::Bind(&SystemTrayClient::RequestUpdateCheck, base::Unretained(this)), | |
| 193 // Waits 1 second until after the about Chrome OS | |
| 194 // page is loaded. | |
|
stevenjb
2017/05/16 19:49:06
What are we delaying this? Please explain. (Also c
weidongg
2017/05/16 19:58:36
Clicking this icon will bring user to About Chrome
stevenjb
2017/05/16 20:42:34
Using a time delay like this is fragile at best.
weidongg
2017/05/17 00:27:23
Yes, I was worried about the fragility too. Making
| |
| 195 base::TimeDelta::FromSeconds(1)); | |
| 196 } | |
| 197 | |
| 198 void SystemTrayClient::RequestUpdateCheck() { | |
| 199 base::WeakPtrFactory<SystemTrayClient> weak_ptr_factory_(this); | |
| 200 DBusThreadManager::Get()->GetUpdateEngineClient()->RequestUpdateCheck( | |
| 201 base::Bind(&SystemTrayClient::OnRequestUpdateCheck, | |
| 202 weak_ptr_factory_.GetWeakPtr())); | |
| 203 } | |
| 204 | |
| 205 void SystemTrayClient::OnRequestUpdateCheck( | |
| 206 UpdateEngineClient::UpdateCheckResult /* result */) {} | |
| 207 | |
| 181 // static | 208 // static |
| 182 int SystemTrayClient::GetDialogParentContainerId() { | 209 int SystemTrayClient::GetDialogParentContainerId() { |
| 183 const ash::LoginStatus login_status = GetUserLoginStatus(); | 210 const ash::LoginStatus login_status = GetUserLoginStatus(); |
| 184 if (login_status == ash::LoginStatus::NOT_LOGGED_IN || | 211 if (login_status == ash::LoginStatus::NOT_LOGGED_IN || |
| 185 login_status == ash::LoginStatus::LOCKED) { | 212 login_status == ash::LoginStatus::LOCKED) { |
| 186 return ash::kShellWindowId_LockSystemModalContainer; | 213 return ash::kShellWindowId_LockSystemModalContainer; |
| 187 } | 214 } |
| 188 | 215 |
| 189 session_manager::SessionManager* const session_manager = | 216 session_manager::SessionManager* const session_manager = |
| 190 session_manager::SessionManager::Get(); | 217 session_manager::SessionManager::Get(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 dialog->ShowInContainer(GetDialogParentContainerId()); | 289 dialog->ShowInContainer(GetDialogParentContainerId()); |
| 263 } | 290 } |
| 264 | 291 |
| 265 void SystemTrayClient::ShowDateSettings() { | 292 void SystemTrayClient::ShowDateSettings() { |
| 266 base::RecordAction(base::UserMetricsAction("ShowDateOptions")); | 293 base::RecordAction(base::UserMetricsAction("ShowDateOptions")); |
| 267 // Everybody can change the time zone (even though it is a device setting). | 294 // Everybody can change the time zone (even though it is a device setting). |
| 268 chrome::ShowSettingsSubPageForProfile(ProfileManager::GetActiveUserProfile(), | 295 chrome::ShowSettingsSubPageForProfile(ProfileManager::GetActiveUserProfile(), |
| 269 chrome::kDateTimeSubPage); | 296 chrome::kDateTimeSubPage); |
| 270 } | 297 } |
| 271 | 298 |
| 299 void SystemTrayClient::ShowAboutChromeOS() { | |
| 300 ShowSettingsSubPageForActiveUser(chrome::kHelpSubPage); | |
| 301 } | |
| 302 | |
| 272 void SystemTrayClient::ShowSetTimeDialog() { | 303 void SystemTrayClient::ShowSetTimeDialog() { |
| 273 chromeos::SetTimeDialog::ShowDialogInContainer(GetDialogParentContainerId()); | 304 chromeos::SetTimeDialog::ShowDialogInContainer(GetDialogParentContainerId()); |
| 274 } | 305 } |
| 275 | 306 |
| 276 void SystemTrayClient::ShowDisplaySettings() { | 307 void SystemTrayClient::ShowDisplaySettings() { |
| 277 base::RecordAction(base::UserMetricsAction("ShowDisplayOptions")); | 308 base::RecordAction(base::UserMetricsAction("ShowDisplayOptions")); |
| 278 ShowSettingsSubPageForActiveUser(chrome::kDisplaySubPage); | 309 ShowSettingsSubPageForActiveUser(chrome::kDisplaySubPage); |
| 279 } | 310 } |
| 280 | 311 |
| 281 void SystemTrayClient::ShowPowerSettings() { | 312 void SystemTrayClient::ShowPowerSettings() { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 // Show a string specific to updating flash player if there is no system | 484 // Show a string specific to updating flash player if there is no system |
| 454 // update. | 485 // update. |
| 455 ash::mojom::UpdateType update_type = detector->notify_upgrade() | 486 ash::mojom::UpdateType update_type = detector->notify_upgrade() |
| 456 ? ash::mojom::UpdateType::SYSTEM | 487 ? ash::mojom::UpdateType::SYSTEM |
| 457 : ash::mojom::UpdateType::FLASH; | 488 : ash::mojom::UpdateType::FLASH; |
| 458 | 489 |
| 459 system_tray_->ShowUpdateIcon(severity, detector->is_factory_reset_required(), | 490 system_tray_->ShowUpdateIcon(severity, detector->is_factory_reset_required(), |
| 460 update_type); | 491 update_type); |
| 461 } | 492 } |
| 462 | 493 |
| 494 void SystemTrayClient::HandleUpdateOverCellularAvailable() { | |
| 495 system_tray_->ShowUpdateOverCellularAvailableIcon(); | |
| 496 } | |
| 497 | |
| 463 //////////////////////////////////////////////////////////////////////////////// | 498 //////////////////////////////////////////////////////////////////////////////// |
| 464 // chromeos::system::SystemClockObserver: | 499 // chromeos::system::SystemClockObserver: |
| 465 | 500 |
| 466 void SystemTrayClient::OnSystemClockChanged( | 501 void SystemTrayClient::OnSystemClockChanged( |
| 467 chromeos::system::SystemClock* clock) { | 502 chromeos::system::SystemClock* clock) { |
| 468 system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock()); | 503 system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock()); |
| 469 } | 504 } |
| 470 | 505 |
| 471 void SystemTrayClient::Observe(int type, | 506 void SystemTrayClient::Observe(int type, |
| 472 const content::NotificationSource& source, | 507 const content::NotificationSource& source, |
| 473 const content::NotificationDetails& details) { | 508 const content::NotificationDetails& details) { |
| 474 DCHECK_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, type); | 509 if (chrome::NOTIFICATION_UPGRADE_RECOMMENDED == type) |
| 475 HandleUpdateAvailable(); | 510 HandleUpdateAvailable(); |
| 511 else if (chrome::NOTIFICATION_UPDATE_OVER_CELLULAR_AVAILABLE == type) | |
| 512 HandleUpdateOverCellularAvailable(); | |
| 476 } | 513 } |
| 477 | 514 |
| 478 //////////////////////////////////////////////////////////////////////////////// | 515 //////////////////////////////////////////////////////////////////////////////// |
| 479 // policy::CloudPolicyStore::Observer | 516 // policy::CloudPolicyStore::Observer |
| 480 void SystemTrayClient::OnStoreLoaded(policy::CloudPolicyStore* store) { | 517 void SystemTrayClient::OnStoreLoaded(policy::CloudPolicyStore* store) { |
| 481 UpdateEnterpriseDomain(); | 518 UpdateEnterpriseDomain(); |
| 482 } | 519 } |
| 483 | 520 |
| 484 void SystemTrayClient::OnStoreError(policy::CloudPolicyStore* store) { | 521 void SystemTrayClient::OnStoreError(policy::CloudPolicyStore* store) { |
| 485 UpdateEnterpriseDomain(); | 522 UpdateEnterpriseDomain(); |
| 486 } | 523 } |
| 487 | 524 |
| 488 void SystemTrayClient::UpdateEnterpriseDomain() { | 525 void SystemTrayClient::UpdateEnterpriseDomain() { |
| 489 policy::BrowserPolicyConnectorChromeOS* connector = | 526 policy::BrowserPolicyConnectorChromeOS* connector = |
| 490 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 527 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 491 const std::string enterprise_domain = connector->GetEnterpriseDomain(); | 528 const std::string enterprise_domain = connector->GetEnterpriseDomain(); |
| 492 const bool active_directory_managed = connector->IsActiveDirectoryManaged(); | 529 const bool active_directory_managed = connector->IsActiveDirectoryManaged(); |
| 493 if (enterprise_domain == last_enterprise_domain_ && | 530 if (enterprise_domain == last_enterprise_domain_ && |
| 494 active_directory_managed == last_active_directory_managed_) { | 531 active_directory_managed == last_active_directory_managed_) { |
| 495 return; | 532 return; |
| 496 } | 533 } |
| 497 // Send to ash, which will add an item to the system tray. | 534 // Send to ash, which will add an item to the system tray. |
| 498 system_tray_->SetEnterpriseDomain(enterprise_domain, | 535 system_tray_->SetEnterpriseDomain(enterprise_domain, |
| 499 active_directory_managed); | 536 active_directory_managed); |
| 500 last_enterprise_domain_ = enterprise_domain; | 537 last_enterprise_domain_ = enterprise_domain; |
| 501 last_active_directory_managed_ = active_directory_managed; | 538 last_active_directory_managed_ = active_directory_managed; |
| 502 } | 539 } |
| OLD | NEW |