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

Side by Side Diff: ash/common/system/update/tray_update.cc

Issue 2568413002: Revert of ash: Use system tray mojo interface to show system update tray icon (Closed)
Patch Set: 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"
11 #include "ash/common/system/tray/system_tray_controller.h" 11 #include "ash/common/system/tray/system_tray_controller.h"
12 #include "ash/common/system/tray/system_tray_delegate.h" 12 #include "ash/common/system/tray/system_tray_delegate.h"
13 #include "ash/common/system/tray/system_tray_notifier.h"
13 #include "ash/common/system/tray/tray_constants.h" 14 #include "ash/common/system/tray/tray_constants.h"
14 #include "ash/common/system/tray/tray_popup_item_style.h" 15 #include "ash/common/system/tray/tray_popup_item_style.h"
15 #include "ash/common/system/tray/tray_popup_utils.h" 16 #include "ash/common/system/tray/tray_popup_utils.h"
16 #include "ash/common/wm_shell.h" 17 #include "ash/common/wm_shell.h"
17 #include "ash/public/interfaces/update.mojom.h"
18 #include "ash/resources/vector_icons/vector_icons.h" 18 #include "ash/resources/vector_icons/vector_icons.h"
19 #include "grit/ash_resources.h" 19 #include "grit/ash_resources.h"
20 #include "grit/ash_strings.h" 20 #include "grit/ash_strings.h"
21 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/gfx/color_palette.h" 22 #include "ui/gfx/color_palette.h"
23 #include "ui/gfx/image/image.h" 23 #include "ui/gfx/image/image.h"
24 #include "ui/gfx/paint_vector_icon.h" 24 #include "ui/gfx/paint_vector_icon.h"
25 #include "ui/views/controls/image_view.h" 25 #include "ui/views/controls/image_view.h"
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(mojom::UpdateSeverity severity, bool dark) { 36 int DecideResource(UpdateInfo::UpdateSeverity severity, bool dark) {
37 switch (severity) { 37 switch (severity) {
38 case mojom::UpdateSeverity::NONE: 38 case UpdateInfo::UPDATE_NONE:
39 case mojom::UpdateSeverity::LOW: 39 case UpdateInfo::UPDATE_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 mojom::UpdateSeverity::ELEVATED: 42 case UpdateInfo::UPDATE_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 mojom::UpdateSeverity::HIGH: 46 case UpdateInfo::UPDATE_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 mojom::UpdateSeverity::SEVERE: 50 case UpdateInfo::UPDATE_SEVERE:
51 case mojom::UpdateSeverity::CRITICAL: 51 case UpdateInfo::UPDATE_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(mojom::UpdateSeverity severity, 63 SkColor IconColorForUpdateSeverity(UpdateInfo::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 mojom::UpdateSeverity::NONE: 67 case UpdateInfo::UPDATE_NONE:
68 return default_color; 68 return default_color;
69 case mojom::UpdateSeverity::LOW: 69 case UpdateInfo::UPDATE_LOW:
70 return for_menu ? gfx::kGoogleGreen700 : kTrayIconColor; 70 return for_menu ? gfx::kGoogleGreen700 : kTrayIconColor;
71 case mojom::UpdateSeverity::ELEVATED: 71 case UpdateInfo::UPDATE_ELEVATED:
72 return for_menu ? gfx::kGoogleYellow700 : gfx::kGoogleYellow300; 72 return for_menu ? gfx::kGoogleYellow700 : gfx::kGoogleYellow300;
73 case mojom::UpdateSeverity::HIGH: 73 case UpdateInfo::UPDATE_HIGH:
74 case mojom::UpdateSeverity::SEVERE: 74 case UpdateInfo::UPDATE_SEVERE:
75 case mojom::UpdateSeverity::CRITICAL: 75 case UpdateInfo::UPDATE_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 } // namespace 84 class UpdateView : public ActionableView {
85
86 // static
87 bool TrayUpdate::update_required_ = false;
88 // static
89 mojom::UpdateSeverity TrayUpdate::severity_ = mojom::UpdateSeverity::NONE;
90 // static
91 bool TrayUpdate::factory_reset_required_ = false;
92
93 // The "restart to update" item in the system tray menu.
94 class TrayUpdate::UpdateView : public ActionableView {
95 public: 85 public:
96 explicit UpdateView(TrayUpdate* owner) 86 UpdateView(SystemTrayItem* owner, const UpdateInfo& info)
97 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS), 87 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS),
98 label_(nullptr) { 88 label_(nullptr) {
99 SetLayoutManager(new views::FillLayout); 89 SetLayoutManager(new views::FillLayout);
100 90
101 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 91 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
102 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); 92 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView();
103 AddChildView(tri_view); 93 AddChildView(tri_view);
104 views::ImageView* image = TrayPopupUtils::CreateMainImageView(); 94 views::ImageView* image = TrayPopupUtils::CreateMainImageView();
105 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 95 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
106 image->SetImage(gfx::CreateVectorIcon( 96 image->SetImage(gfx::CreateVectorIcon(
107 kSystemMenuUpdateIcon, 97 kSystemMenuUpdateIcon,
108 IconColorForUpdateSeverity(owner->severity_, true))); 98 IconColorForUpdateSeverity(info.severity, true)));
109 } else { 99 } else {
110 image->SetImage( 100 image->SetImage(bundle.GetImageNamed(DecideResource(info.severity, true))
111 bundle.GetImageNamed(DecideResource(owner->severity_, true)) 101 .ToImageSkia());
112 .ToImageSkia());
113 } 102 }
114 tri_view->AddView(TriView::Container::START, image); 103 tri_view->AddView(TriView::Container::START, image);
115 104
116 base::string16 label_text = 105 base::string16 label_text =
117 owner->factory_reset_required_ 106 info.factory_reset_required
118 ? bundle.GetLocalizedString( 107 ? bundle.GetLocalizedString(
119 IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE) 108 IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE)
120 : bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE); 109 : bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE);
121 label_ = TrayPopupUtils::CreateDefaultLabel(); 110 label_ = TrayPopupUtils::CreateDefaultLabel();
122 label_->SetText(label_text); 111 label_->SetText(label_text);
123 SetAccessibleName(label_text); 112 SetAccessibleName(label_text);
124 tri_view->AddView(TriView::Container::CENTER, label_); 113 tri_view->AddView(TriView::Container::CENTER, label_);
125 114
126 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 115 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
127 UpdateStyle(); 116 UpdateStyle();
(...skipping 25 matching lines...) Expand all
153 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) 142 if (!MaterialDesignController::IsSystemTrayMenuMaterial())
154 return; 143 return;
155 UpdateStyle(); 144 UpdateStyle();
156 } 145 }
157 146
158 views::Label* label_; 147 views::Label* label_;
159 148
160 DISALLOW_COPY_AND_ASSIGN(UpdateView); 149 DISALLOW_COPY_AND_ASSIGN(UpdateView);
161 }; 150 };
162 151
152 } // namespace
153
163 TrayUpdate::TrayUpdate(SystemTray* system_tray) 154 TrayUpdate::TrayUpdate(SystemTray* system_tray)
164 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_UPDATE, UMA_UPDATE) {} 155 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_UPDATE, UMA_UPDATE) {
156 WmShell::Get()->system_tray_notifier()->AddUpdateObserver(this);
157 }
165 158
166 TrayUpdate::~TrayUpdate() {} 159 TrayUpdate::~TrayUpdate() {
160 WmShell::Get()->system_tray_notifier()->RemoveUpdateObserver(this);
161 }
167 162
168 bool TrayUpdate::GetInitialVisibility() { 163 bool TrayUpdate::GetInitialVisibility() {
169 // If chrome tells ash there is an update available before this item's system 164 UpdateInfo info;
170 // tray is constructed then show the icon. 165 WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&info);
171 return update_required_; 166 return info.update_required;
172 } 167 }
173 168
174 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) { 169 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) {
175 return update_required_ ? new UpdateView(this) : nullptr; 170 UpdateInfo info;
171 WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&info);
172 return info.update_required ? new UpdateView(this, info) : nullptr;
176 } 173 }
177 174
178 void TrayUpdate::ShowUpdateIcon(mojom::UpdateSeverity severity, 175 void TrayUpdate::OnUpdateRecommended(const UpdateInfo& info) {
179 bool factory_reset_required) {
180 // Cache update info so we can create the default view when the menu opens.
181 update_required_ = true;
182 severity_ = severity;
183 factory_reset_required_ = factory_reset_required;
184
185 // Show the icon in the tray.
186 if (MaterialDesignController::UseMaterialDesignSystemIcons()) 176 if (MaterialDesignController::UseMaterialDesignSystemIcons())
187 SetIconColor(IconColorForUpdateSeverity(severity_, false)); 177 SetIconColor(IconColorForUpdateSeverity(info.severity, false));
188 else 178 else
189 SetImageFromResourceId(DecideResource(severity_, false)); 179 SetImageFromResourceId(DecideResource(info.severity, false));
190 tray_view()->SetVisible(true); 180 tray_view()->SetVisible(true);
191 } 181 }
192 182
193 } // namespace ash 183 } // namespace ash
OLDNEW
« 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