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

Unified Diff: ash/common/system/update/tray_update.cc

Issue 2558043006: ash: Use system tray mojo interface to show system update tray icon (Closed)
Patch Set: fix gcc 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
« no previous file with comments | « ash/common/system/update/tray_update.h ('k') | ash/common/system/update/tray_update_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/common/system/update/tray_update.cc
diff --git a/ash/common/system/update/tray_update.cc b/ash/common/system/update/tray_update.cc
index 47e6cc2732e6b57845534ff6a35707dc908b6dcf..78a4469d81f0b2e01d158e477bcf7ad77a92df96 100644
--- a/ash/common/system/update/tray_update.cc
+++ b/ash/common/system/update/tray_update.cc
@@ -10,11 +10,11 @@
#include "ash/common/system/tray/system_tray.h"
#include "ash/common/system/tray/system_tray_controller.h"
#include "ash/common/system/tray/system_tray_delegate.h"
-#include "ash/common/system/tray/system_tray_notifier.h"
#include "ash/common/system/tray/tray_constants.h"
#include "ash/common/system/tray/tray_popup_item_style.h"
#include "ash/common/system/tray/tray_popup_utils.h"
#include "ash/common/wm_shell.h"
+#include "ash/public/interfaces/update.mojom.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "grit/ash_resources.h"
#include "grit/ash_strings.h"
@@ -33,22 +33,22 @@ namespace {
// severity.
// TODO(tdanderson): This is only used for non-material design, so remove it
// when material design is the default. See crbug.com/625692.
-int DecideResource(UpdateInfo::UpdateSeverity severity, bool dark) {
+int DecideResource(mojom::UpdateSeverity severity, bool dark) {
switch (severity) {
- case UpdateInfo::UPDATE_NONE:
- case UpdateInfo::UPDATE_LOW:
+ case mojom::UpdateSeverity::NONE:
+ case mojom::UpdateSeverity::LOW:
return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK : IDR_AURA_UBER_TRAY_UPDATE;
- case UpdateInfo::UPDATE_ELEVATED:
+ case mojom::UpdateSeverity::ELEVATED:
return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_GREEN
: IDR_AURA_UBER_TRAY_UPDATE_GREEN;
- case UpdateInfo::UPDATE_HIGH:
+ case mojom::UpdateSeverity::HIGH:
return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_ORANGE
: IDR_AURA_UBER_TRAY_UPDATE_ORANGE;
- case UpdateInfo::UPDATE_SEVERE:
- case UpdateInfo::UPDATE_CRITICAL:
+ case mojom::UpdateSeverity::SEVERE:
+ case mojom::UpdateSeverity::CRITICAL:
return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_RED
: IDR_AURA_UBER_TRAY_UPDATE_RED;
}
@@ -60,19 +60,19 @@ int DecideResource(UpdateInfo::UpdateSeverity severity, bool dark) {
// Returns the color to use for the material design update icon when the update
// severity is |severity|. If |for_menu| is true, the icon color for the system
// menu is given, otherwise the icon color for the system tray is given.
-SkColor IconColorForUpdateSeverity(UpdateInfo::UpdateSeverity severity,
+SkColor IconColorForUpdateSeverity(mojom::UpdateSeverity severity,
bool for_menu) {
const SkColor default_color = for_menu ? kMenuIconColor : kTrayIconColor;
switch (severity) {
- case UpdateInfo::UPDATE_NONE:
+ case mojom::UpdateSeverity::NONE:
return default_color;
- case UpdateInfo::UPDATE_LOW:
+ case mojom::UpdateSeverity::LOW:
return for_menu ? gfx::kGoogleGreen700 : kTrayIconColor;
- case UpdateInfo::UPDATE_ELEVATED:
+ case mojom::UpdateSeverity::ELEVATED:
return for_menu ? gfx::kGoogleYellow700 : gfx::kGoogleYellow300;
- case UpdateInfo::UPDATE_HIGH:
- case UpdateInfo::UPDATE_SEVERE:
- case UpdateInfo::UPDATE_CRITICAL:
+ case mojom::UpdateSeverity::HIGH:
+ case mojom::UpdateSeverity::SEVERE:
+ case mojom::UpdateSeverity::CRITICAL:
return for_menu ? gfx::kGoogleRed700 : gfx::kGoogleRed300;
default:
NOTREACHED();
@@ -81,9 +81,19 @@ SkColor IconColorForUpdateSeverity(UpdateInfo::UpdateSeverity severity,
return default_color;
}
-class UpdateView : public ActionableView {
+} // namespace
+
+// static
+bool TrayUpdate::update_required_ = false;
+// static
+mojom::UpdateSeverity TrayUpdate::severity_ = mojom::UpdateSeverity::NONE;
+// static
+bool TrayUpdate::factory_reset_required_ = false;
+
+// The "restart to update" item in the system tray menu.
+class TrayUpdate::UpdateView : public ActionableView {
public:
- UpdateView(SystemTrayItem* owner, const UpdateInfo& info)
+ explicit UpdateView(TrayUpdate* owner)
: ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS),
label_(nullptr) {
SetLayoutManager(new views::FillLayout);
@@ -95,15 +105,16 @@ class UpdateView : public ActionableView {
if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
image->SetImage(gfx::CreateVectorIcon(
kSystemMenuUpdateIcon,
- IconColorForUpdateSeverity(info.severity, true)));
+ IconColorForUpdateSeverity(owner->severity_, true)));
} else {
- image->SetImage(bundle.GetImageNamed(DecideResource(info.severity, true))
- .ToImageSkia());
+ image->SetImage(
+ bundle.GetImageNamed(DecideResource(owner->severity_, true))
+ .ToImageSkia());
}
tri_view->AddView(TriView::Container::START, image);
base::string16 label_text =
- info.factory_reset_required
+ owner->factory_reset_required_
? bundle.GetLocalizedString(
IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE)
: bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE);
@@ -149,34 +160,33 @@ class UpdateView : public ActionableView {
DISALLOW_COPY_AND_ASSIGN(UpdateView);
};
-} // namespace
-
TrayUpdate::TrayUpdate(SystemTray* system_tray)
- : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_UPDATE, UMA_UPDATE) {
- WmShell::Get()->system_tray_notifier()->AddUpdateObserver(this);
-}
+ : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_UPDATE, UMA_UPDATE) {}
-TrayUpdate::~TrayUpdate() {
- WmShell::Get()->system_tray_notifier()->RemoveUpdateObserver(this);
-}
+TrayUpdate::~TrayUpdate() {}
bool TrayUpdate::GetInitialVisibility() {
- UpdateInfo info;
- WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&info);
- return info.update_required;
+ // If chrome tells ash there is an update available before this item's system
+ // tray is constructed then show the icon.
+ return update_required_;
}
views::View* TrayUpdate::CreateDefaultView(LoginStatus status) {
- UpdateInfo info;
- WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&info);
- return info.update_required ? new UpdateView(this, info) : nullptr;
+ return update_required_ ? new UpdateView(this) : nullptr;
}
-void TrayUpdate::OnUpdateRecommended(const UpdateInfo& info) {
+void TrayUpdate::ShowUpdateIcon(mojom::UpdateSeverity severity,
+ bool factory_reset_required) {
+ // Cache update info so we can create the default view when the menu opens.
+ update_required_ = true;
+ severity_ = severity;
+ factory_reset_required_ = factory_reset_required;
+
+ // Show the icon in the tray.
if (MaterialDesignController::UseMaterialDesignSystemIcons())
- SetIconColor(IconColorForUpdateSeverity(info.severity, false));
+ SetIconColor(IconColorForUpdateSeverity(severity_, false));
else
- SetImageFromResourceId(DecideResource(info.severity, false));
+ SetImageFromResourceId(DecideResource(severity_, false));
tray_view()->SetVisible(true);
}
« no previous file with comments | « ash/common/system/update/tray_update.h ('k') | ash/common/system/update/tray_update_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698