Chromium Code Reviews| 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..6b44aee0e514e5e84f91f47abdb78ccabc122470 100644 |
| --- a/ash/common/system/update/tray_update.cc |
| +++ b/ash/common/system/update/tray_update.cc |
| @@ -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,12 @@ SkColor IconColorForUpdateSeverity(UpdateInfo::UpdateSeverity severity, |
| return default_color; |
| } |
| -class UpdateView : public ActionableView { |
| +} // namespace |
| + |
| +// 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 +98,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,8 +153,6 @@ 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); |
| @@ -161,22 +163,26 @@ TrayUpdate::~TrayUpdate() { |
| } |
| bool TrayUpdate::GetInitialVisibility() { |
| - UpdateInfo info; |
| - WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&info); |
| - return info.update_required; |
| + // Icon is hidden until Chrome explicitly tells us an update is available. |
| + return false; |
|
msw
2016/12/09 23:41:51
Should this just return update_required_?
James Cook
2016/12/12 18:15:12
Yeah, I think so.
|
| } |
| 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); |
| } |