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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/common/system/update/tray_update.h" 5 #include "ash/common/system/update/tray_update.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h" 7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/metrics/user_metrics_action.h" 8 #include "ash/common/metrics/user_metrics_action.h"
9 #include "ash/common/system/tray/fixed_sized_image_view.h" 9 #include "ash/common/system/tray/fixed_sized_image_view.h"
10 #include "ash/common/system/tray/system_tray.h" 10 #include "ash/common/system/tray/system_tray.h"
(...skipping 15 matching lines...) Expand all
26 #include "ui/views/controls/label.h" 26 #include "ui/views/controls/label.h"
27 #include "ui/views/layout/fill_layout.h" 27 #include "ui/views/layout/fill_layout.h"
28 28
29 namespace ash { 29 namespace ash {
30 namespace { 30 namespace {
31 31
32 // Decides the non-material design image resource to use for a given update 32 // Decides the non-material design image resource to use for a given update
33 // severity. 33 // severity.
34 // TODO(tdanderson): This is only used for non-material design, so remove it 34 // TODO(tdanderson): This is only used for non-material design, so remove it
35 // when material design is the default. See crbug.com/625692. 35 // when material design is the default. See crbug.com/625692.
36 int DecideResource(UpdateInfo::UpdateSeverity severity, bool dark) { 36 int DecideResource(mojom::UpdateSeverity severity, bool dark) {
37 switch (severity) { 37 switch (severity) {
38 case UpdateInfo::UPDATE_NONE: 38 case mojom::UpdateSeverity::NONE:
39 case UpdateInfo::UPDATE_LOW: 39 case mojom::UpdateSeverity::LOW:
40 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK : IDR_AURA_UBER_TRAY_UPDATE; 40 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK : IDR_AURA_UBER_TRAY_UPDATE;
41 41
42 case UpdateInfo::UPDATE_ELEVATED: 42 case mojom::UpdateSeverity::ELEVATED:
43 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_GREEN 43 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_GREEN
44 : IDR_AURA_UBER_TRAY_UPDATE_GREEN; 44 : IDR_AURA_UBER_TRAY_UPDATE_GREEN;
45 45
46 case UpdateInfo::UPDATE_HIGH: 46 case mojom::UpdateSeverity::HIGH:
47 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_ORANGE 47 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_ORANGE
48 : IDR_AURA_UBER_TRAY_UPDATE_ORANGE; 48 : IDR_AURA_UBER_TRAY_UPDATE_ORANGE;
49 49
50 case UpdateInfo::UPDATE_SEVERE: 50 case mojom::UpdateSeverity::SEVERE:
51 case UpdateInfo::UPDATE_CRITICAL: 51 case mojom::UpdateSeverity::CRITICAL:
52 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_RED 52 return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_RED
53 : IDR_AURA_UBER_TRAY_UPDATE_RED; 53 : IDR_AURA_UBER_TRAY_UPDATE_RED;
54 } 54 }
55 55
56 NOTREACHED() << "Unknown update severity level."; 56 NOTREACHED() << "Unknown update severity level.";
57 return 0; 57 return 0;
58 } 58 }
59 59
60 // Returns the color to use for the material design update icon when the update 60 // Returns the color to use for the material design update icon when the update
61 // severity is |severity|. If |for_menu| is true, the icon color for the system 61 // severity is |severity|. If |for_menu| is true, the icon color for the system
62 // menu is given, otherwise the icon color for the system tray is given. 62 // menu is given, otherwise the icon color for the system tray is given.
63 SkColor IconColorForUpdateSeverity(UpdateInfo::UpdateSeverity severity, 63 SkColor IconColorForUpdateSeverity(mojom::UpdateSeverity severity,
64 bool for_menu) { 64 bool for_menu) {
65 const SkColor default_color = for_menu ? kMenuIconColor : kTrayIconColor; 65 const SkColor default_color = for_menu ? kMenuIconColor : kTrayIconColor;
66 switch (severity) { 66 switch (severity) {
67 case UpdateInfo::UPDATE_NONE: 67 case mojom::UpdateSeverity::NONE:
68 return default_color; 68 return default_color;
69 case UpdateInfo::UPDATE_LOW: 69 case mojom::UpdateSeverity::LOW:
70 return for_menu ? gfx::kGoogleGreen700 : kTrayIconColor; 70 return for_menu ? gfx::kGoogleGreen700 : kTrayIconColor;
71 case UpdateInfo::UPDATE_ELEVATED: 71 case mojom::UpdateSeverity::ELEVATED:
72 return for_menu ? gfx::kGoogleYellow700 : gfx::kGoogleYellow300; 72 return for_menu ? gfx::kGoogleYellow700 : gfx::kGoogleYellow300;
73 case UpdateInfo::UPDATE_HIGH: 73 case mojom::UpdateSeverity::HIGH:
74 case UpdateInfo::UPDATE_SEVERE: 74 case mojom::UpdateSeverity::SEVERE:
75 case UpdateInfo::UPDATE_CRITICAL: 75 case mojom::UpdateSeverity::CRITICAL:
76 return for_menu ? gfx::kGoogleRed700 : gfx::kGoogleRed300; 76 return for_menu ? gfx::kGoogleRed700 : gfx::kGoogleRed300;
77 default: 77 default:
78 NOTREACHED(); 78 NOTREACHED();
79 break; 79 break;
80 } 80 }
81 return default_color; 81 return default_color;
82 } 82 }
83 83
84 class UpdateView : public ActionableView { 84 } // namespace
85
86 // The "restart to update" item in the system tray menu.
87 class TrayUpdate::UpdateView : public ActionableView {
85 public: 88 public:
86 UpdateView(SystemTrayItem* owner, const UpdateInfo& info) 89 explicit UpdateView(TrayUpdate* owner)
87 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS), 90 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS),
88 label_(nullptr) { 91 label_(nullptr) {
89 SetLayoutManager(new views::FillLayout); 92 SetLayoutManager(new views::FillLayout);
90 93
91 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 94 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
92 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); 95 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView();
93 AddChildView(tri_view); 96 AddChildView(tri_view);
94 views::ImageView* image = TrayPopupUtils::CreateMainImageView(); 97 views::ImageView* image = TrayPopupUtils::CreateMainImageView();
95 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 98 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
96 image->SetImage(gfx::CreateVectorIcon( 99 image->SetImage(gfx::CreateVectorIcon(
97 kSystemMenuUpdateIcon, 100 kSystemMenuUpdateIcon,
98 IconColorForUpdateSeverity(info.severity, true))); 101 IconColorForUpdateSeverity(owner->severity_, true)));
99 } else { 102 } else {
100 image->SetImage(bundle.GetImageNamed(DecideResource(info.severity, true)) 103 image->SetImage(
101 .ToImageSkia()); 104 bundle.GetImageNamed(DecideResource(owner->severity_, true))
105 .ToImageSkia());
102 } 106 }
103 tri_view->AddView(TriView::Container::START, image); 107 tri_view->AddView(TriView::Container::START, image);
104 108
105 base::string16 label_text = 109 base::string16 label_text =
106 info.factory_reset_required 110 owner->factory_reset_required_
107 ? bundle.GetLocalizedString( 111 ? bundle.GetLocalizedString(
108 IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE) 112 IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE)
109 : bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE); 113 : bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE);
110 label_ = TrayPopupUtils::CreateDefaultLabel(); 114 label_ = TrayPopupUtils::CreateDefaultLabel();
111 label_->SetText(label_text); 115 label_->SetText(label_text);
112 SetAccessibleName(label_text); 116 SetAccessibleName(label_text);
113 tri_view->AddView(TriView::Container::CENTER, label_); 117 tri_view->AddView(TriView::Container::CENTER, label_);
114 118
115 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 119 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
116 UpdateStyle(); 120 UpdateStyle();
(...skipping 25 matching lines...) Expand all
142 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) 146 if (!MaterialDesignController::IsSystemTrayMenuMaterial())
143 return; 147 return;
144 UpdateStyle(); 148 UpdateStyle();
145 } 149 }
146 150
147 views::Label* label_; 151 views::Label* label_;
148 152
149 DISALLOW_COPY_AND_ASSIGN(UpdateView); 153 DISALLOW_COPY_AND_ASSIGN(UpdateView);
150 }; 154 };
151 155
152 } // namespace
153
154 TrayUpdate::TrayUpdate(SystemTray* system_tray) 156 TrayUpdate::TrayUpdate(SystemTray* system_tray)
155 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_UPDATE, UMA_UPDATE) { 157 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_UPDATE, UMA_UPDATE) {
156 WmShell::Get()->system_tray_notifier()->AddUpdateObserver(this); 158 WmShell::Get()->system_tray_notifier()->AddUpdateObserver(this);
157 } 159 }
158 160
159 TrayUpdate::~TrayUpdate() { 161 TrayUpdate::~TrayUpdate() {
160 WmShell::Get()->system_tray_notifier()->RemoveUpdateObserver(this); 162 WmShell::Get()->system_tray_notifier()->RemoveUpdateObserver(this);
161 } 163 }
162 164
163 bool TrayUpdate::GetInitialVisibility() { 165 bool TrayUpdate::GetInitialVisibility() {
164 UpdateInfo info; 166 // Icon is hidden until Chrome explicitly tells us an update is available.
165 WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&info); 167 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.
166 return info.update_required;
167 } 168 }
168 169
169 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) { 170 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) {
170 UpdateInfo info; 171 return update_required_ ? new UpdateView(this) : nullptr;
171 WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&info);
172 return info.update_required ? new UpdateView(this, info) : nullptr;
173 } 172 }
174 173
175 void TrayUpdate::OnUpdateRecommended(const UpdateInfo& info) { 174 void TrayUpdate::ShowUpdateIcon(mojom::UpdateSeverity severity,
175 bool factory_reset_required) {
176 // Cache update info so we can create the default view when the menu opens.
177 update_required_ = true;
178 severity_ = severity;
179 factory_reset_required_ = factory_reset_required;
180
181 // Show the icon in the tray.
176 if (MaterialDesignController::UseMaterialDesignSystemIcons()) 182 if (MaterialDesignController::UseMaterialDesignSystemIcons())
177 SetIconColor(IconColorForUpdateSeverity(info.severity, false)); 183 SetIconColor(IconColorForUpdateSeverity(severity_, false));
178 else 184 else
179 SetImageFromResourceId(DecideResource(info.severity, false)); 185 SetImageFromResourceId(DecideResource(severity_, false));
180 tray_view()->SetVisible(true); 186 tray_view()->SetVisible(true);
181 } 187 }
182 188
183 } // namespace ash 189 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698