Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Unified Diff: chrome/browser/ui/ash/system_tray_client.cc

Issue 2558043006: ash: Use system tray mojo interface to show system update tray icon (Closed)
Patch Set: Make Flash updates yellow Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/ash/system_tray_client.cc
diff --git a/chrome/browser/ui/ash/system_tray_client.cc b/chrome/browser/ui/ash/system_tray_client.cc
index 69427e804a97fb1e694d283053124121857a1d69..b0093a6b30e772811e12045ade2c3eb55d588d28 100644
--- a/chrome/browser/ui/ash/system_tray_client.cc
+++ b/chrome/browser/ui/ash/system_tray_client.cc
@@ -12,6 +12,7 @@
#include "base/logging.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
+#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/accessibility/accessibility_util.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h"
#include "chrome/browser/chromeos/options/network_config_view.h"
@@ -26,11 +27,13 @@
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/browser/ui/singleton_tabs.h"
+#include "chrome/browser/upgrade_detector.h"
#include "chrome/common/url_constants.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/session_manager_client.h"
#include "chromeos/login/login_state.h"
#include "components/user_manager/user_manager.h"
+#include "content/public/browser/notification_service.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/common/service_manager_connection.h"
#include "extensions/browser/api/vpn_provider/vpn_service.h"
@@ -59,6 +62,24 @@ void ShowSettingsSubPageForActiveUser(const std::string& sub_page) {
sub_page);
}
+// Returns the severity of a pending Chrome / Chrome OS update.
+ash::mojom::UpdateSeverity GetUpdateSeverity(UpgradeDetector* detector) {
+ switch (detector->upgrade_notification_stage()) {
+ case UpgradeDetector::UPGRADE_ANNOYANCE_NONE:
+ return ash::mojom::UpdateSeverity::NONE;
+ case UpgradeDetector::UPGRADE_ANNOYANCE_LOW:
+ return ash::mojom::UpdateSeverity::LOW;
+ case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED:
+ return ash::mojom::UpdateSeverity::ELEVATED;
+ case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH:
+ return ash::mojom::UpdateSeverity::HIGH;
+ case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE:
+ return ash::mojom::UpdateSeverity::SEVERE;
+ case UpgradeDetector::UPGRADE_ANNOYANCE_CRITICAL:
+ return ash::mojom::UpdateSeverity::CRITICAL;
+ }
+}
+
} // namespace
SystemTrayClient::SystemTrayClient() : binding_(this) {
@@ -72,6 +93,13 @@ SystemTrayClient::SystemTrayClient() : binding_(this) {
// be queued on |system_tray_|.
g_browser_process->platform_part()->GetSystemClock()->AddObserver(this);
+ registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
+ content::NotificationService::AllSources());
+
+ // If an upgrade is available at startup then tell ash about it.
+ if (UpgradeDetector::GetInstance()->notify_upgrade())
+ HandleUpdateAvailable();
+
DCHECK(!g_instance);
g_instance = this;
}
@@ -167,6 +195,11 @@ Widget* SystemTrayClient::CreateUnownedDialogWidget(
return widget;
}
+void SystemTrayClient::SetFlashUpdateAvailable() {
+ flash_update_available_ = true;
+ HandleUpdateAvailable();
+}
+
////////////////////////////////////////////////////////////////////////////////
// ash::mojom::SystemTrayClient:
@@ -309,19 +342,29 @@ void SystemTrayClient::SignOut() {
}
void SystemTrayClient::RequestRestartForUpdate() {
- bool component_update = false;
- chromeos::SystemTrayDelegateChromeOS* tray =
- chromeos::SystemTrayDelegateChromeOS::instance();
- if (tray)
- component_update = tray->GetFlashUpdateAvailable();
-
- chrome::RebootPolicy reboot_policy =
- component_update ? chrome::RebootPolicy::kForceReboot
- : chrome::RebootPolicy::kOptionalReboot;
+ // Flash updates on Chrome OS require device reboot.
+ const chrome::RebootPolicy reboot_policy =
+ flash_update_available_ ? chrome::RebootPolicy::kForceReboot
+ : chrome::RebootPolicy::kOptionalReboot;
chrome::NotifyAndTerminate(true /* fast_path */, reboot_policy);
}
+void SystemTrayClient::HandleUpdateAvailable() {
+ // Show update icon for Chrome updates and Flash component updates.
msw 2016/12/09 23:41:51 nit: "Show an update icon"
James Cook 2016/12/12 18:15:12 Done.
+ UpgradeDetector* detector = UpgradeDetector::GetInstance();
+ DCHECK(detector->notify_upgrade() || flash_update_available_);
+
+ // Get the Chrome update severity.
+ ash::mojom::UpdateSeverity severity = GetUpdateSeverity(detector);
+
+ // Flash updates are elevated severity unless the Chrome severity is higher.
+ if (flash_update_available_)
+ severity = std::max(severity, ash::mojom::UpdateSeverity::ELEVATED);
+
+ system_tray_->ShowUpdateIcon(severity, detector->is_factory_reset_required());
+}
+
////////////////////////////////////////////////////////////////////////////////
// chromeos::system::SystemClockObserver:
@@ -329,3 +372,10 @@ void SystemTrayClient::OnSystemClockChanged(
chromeos::system::SystemClock* clock) {
system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock());
}
+
+void SystemTrayClient::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, type);
+ HandleUpdateAvailable();
+}

Powered by Google App Engine
This is Rietveld 408576698