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

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

Issue 2882933002: Add update available icon in system tray (Closed)
Patch Set: Created 3 years, 7 months 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/system/update/tray_update.h" 5 #include "ash/system/update/tray_update.h"
6 6
7 #include "ash/metrics/user_metrics_action.h" 7 #include "ash/metrics/user_metrics_action.h"
8 #include "ash/public/interfaces/update.mojom.h" 8 #include "ash/public/interfaces/update.mojom.h"
9 #include "ash/resources/vector_icons/vector_icons.h" 9 #include "ash/resources/vector_icons/vector_icons.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 default: 48 default:
49 NOTREACHED(); 49 NOTREACHED();
50 break; 50 break;
51 } 51 }
52 return default_color; 52 return default_color;
53 } 53 }
54 54
55 } // namespace 55 } // namespace
56 56
57 // static 57 // static
58 bool TrayUpdate::update_required_ = false; 58 bool TrayUpdate::upgrade_required_ = false;
59 // static 59 // static
60 mojom::UpdateSeverity TrayUpdate::severity_ = mojom::UpdateSeverity::NONE; 60 mojom::UpdateSeverity TrayUpdate::severity_ = mojom::UpdateSeverity::NONE;
61 // static 61 // static
62 bool TrayUpdate::factory_reset_required_ = false; 62 bool TrayUpdate::factory_reset_required_ = false;
63 // static
64 bool TrayUpdate::update_over_cellular_available_ = false;
65
63 mojom::UpdateType TrayUpdate::update_type_ = mojom::UpdateType::SYSTEM; 66 mojom::UpdateType TrayUpdate::update_type_ = mojom::UpdateType::SYSTEM;
64 67
65 // The "restart to update" item in the system tray menu. 68 // The "restart to update" item in the system tray menu.
66 class TrayUpdate::UpdateView : public ActionableView { 69 class TrayUpdate::UpdateView : public ActionableView {
67 public: 70 public:
68 explicit UpdateView(TrayUpdate* owner) 71 explicit UpdateView(TrayUpdate* owner)
69 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS), 72 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS),
70 update_label_(nullptr) { 73 update_label_(nullptr) {
71 SetLayoutManager(new views::FillLayout); 74 SetLayoutManager(new views::FillLayout);
72 75
73 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 76 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
74 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); 77 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView();
75 AddChildView(tri_view); 78 AddChildView(tri_view);
76 views::ImageView* image = TrayPopupUtils::CreateMainImageView(); 79 views::ImageView* image = TrayPopupUtils::CreateMainImageView();
77 image->SetImage(gfx::CreateVectorIcon( 80 image->SetImage(gfx::CreateVectorIcon(
78 kSystemMenuUpdateIcon, 81 kSystemMenuUpdateIcon,
79 IconColorForUpdateSeverity(owner->severity_, true))); 82 IconColorForUpdateSeverity(owner->severity_, true)));
80 tri_view->AddView(TriView::Container::START, image); 83 tri_view->AddView(TriView::Container::START, image);
81 84
82 base::string16 label_text; 85 base::string16 label_text;
83 if (owner->factory_reset_required_) { 86 if (owner->factory_reset_required_) {
84 label_text = bundle.GetLocalizedString( 87 label_text = bundle.GetLocalizedString(
85 IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE); 88 IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE);
86 } else if (owner->update_type_ == mojom::UpdateType::FLASH) { 89 } else if (owner->update_type_ == mojom::UpdateType::FLASH) {
87 label_text = bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE_FLASH); 90 label_text = bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE_FLASH);
91 } else if (!owner->upgrade_required_ &&
92 owner->update_over_cellular_available_) {
93 label_text = bundle.GetLocalizedString(
94 IDS_ASH_STATUS_TRAY_UPDATE_OVER_CELLULAR_AVAILABLE);
88 } else { 95 } else {
89 label_text = bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE); 96 label_text = bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE);
90 } 97 }
91 98
92 SetAccessibleName(label_text); 99 SetAccessibleName(label_text);
93 update_label_ = TrayPopupUtils::CreateDefaultLabel(); 100 update_label_ = TrayPopupUtils::CreateDefaultLabel();
94 update_label_->SetText(label_text); 101 update_label_->SetText(label_text);
95 102
96 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); 103 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL);
97 style.SetupLabel(update_label_); 104 style.SetupLabel(update_label_);
98 tri_view->AddView(TriView::Container::CENTER, update_label_); 105 tri_view->AddView(TriView::Container::CENTER, update_label_);
99 106
100 SetInkDropMode(InkDropHostView::InkDropMode::ON); 107 SetInkDropMode(InkDropHostView::InkDropMode::ON);
101 } 108 }
102 109
103 ~UpdateView() override {} 110 ~UpdateView() override {}
104 111
105 views::Label* update_label_; 112 views::Label* update_label_;
106 113
107 private: 114 private:
108 // Overridden from ActionableView. 115 // Overridden from ActionableView.
109 bool PerformAction(const ui::Event& event) override { 116 bool PerformAction(const ui::Event& /* event */) override {
110 Shell::Get()->system_tray_controller()->RequestRestartForUpdate(); 117 DCHECK(upgrade_required_ || update_over_cellular_available_);
111 ShellPort::Get()->RecordUserMetricsAction( 118 if (upgrade_required_) {
112 UMA_STATUS_AREA_OS_UPDATE_DEFAULT_SELECTED); 119 Shell::Get()->system_tray_controller()->RequestRestartForUpdate();
120 ShellPort::Get()->RecordUserMetricsAction(
121 UMA_STATUS_AREA_OS_UPDATE_DEFAULT_SELECTED);
122 } else {
123 // Opens about Chrome OS page, after which checks for update.
124 Shell::Get()->system_tray_controller()->ShowAboutChromeOS();
weidongg 2017/05/15 04:54:13 Here I want to show the about Chrome OS page first
stevenjb 2017/05/15 18:06:45 What is the reason for wanting to show the about p
weidongg 2017/05/15 20:06:57 In the design doc, clicking this icon will bring u
125 Shell::Get()->system_tray_controller()->RequestUpdateCheck();
126 }
113 CloseSystemBubble(); 127 CloseSystemBubble();
114 return true; 128 return true;
115 } 129 }
116 130
117 DISALLOW_COPY_AND_ASSIGN(UpdateView); 131 DISALLOW_COPY_AND_ASSIGN(UpdateView);
118 }; 132 };
119 133
120 TrayUpdate::TrayUpdate(SystemTray* system_tray) 134 TrayUpdate::TrayUpdate(SystemTray* system_tray)
121 : TrayImageItem(system_tray, kSystemTrayUpdateIcon, UMA_UPDATE) {} 135 : TrayImageItem(system_tray, kSystemTrayUpdateIcon, UMA_UPDATE) {}
122 136
123 TrayUpdate::~TrayUpdate() {} 137 TrayUpdate::~TrayUpdate() {}
124 138
125 bool TrayUpdate::GetInitialVisibility() { 139 bool TrayUpdate::GetInitialVisibility() {
126 // If chrome tells ash there is an update available before this item's system 140 // If chrome tells ash there is an update available before this item's system
127 // tray is constructed then show the icon. 141 // tray is constructed then show the icon.
128 return update_required_; 142 return upgrade_required_ || update_over_cellular_available_;
129 } 143 }
130 144
131 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) { 145 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) {
132 if (update_required_) { 146 if (upgrade_required_ || update_over_cellular_available_) {
133 update_view_ = new UpdateView(this); 147 update_view_ = new UpdateView(this);
134 return update_view_; 148 return update_view_;
135 } 149 }
136 return nullptr; 150 return nullptr;
137 } 151 }
138 152
139 void TrayUpdate::DestroyDefaultView() { 153 void TrayUpdate::DestroyDefaultView() {
140 update_view_ = nullptr; 154 update_view_ = nullptr;
141 } 155 }
142 156
143 void TrayUpdate::ShowUpdateIcon(mojom::UpdateSeverity severity, 157 void TrayUpdate::ShowUpdateIcon(mojom::UpdateSeverity severity,
144 bool factory_reset_required, 158 bool factory_reset_required,
145 mojom::UpdateType update_type) { 159 mojom::UpdateType update_type) {
146 // Cache update info so we can create the default view when the menu opens. 160 // Cache update info so we can create the default view when the menu opens.
147 update_required_ = true; 161 upgrade_required_ = true;
stevenjb 2017/05/15 18:06:45 Switching to 'upgrade' just seems confusing to me.
weidongg 2017/05/15 20:06:57 Ok, I see, I will refactor it back.
148 severity_ = severity; 162 severity_ = severity;
149 factory_reset_required_ = factory_reset_required; 163 factory_reset_required_ = factory_reset_required;
150 update_type_ = update_type; 164 update_type_ = update_type;
151 165
152 // Show the icon in the tray. 166 // Show the icon in the tray.
153 SetIconColor(IconColorForUpdateSeverity(severity_, false)); 167 SetIconColor(IconColorForUpdateSeverity(severity_, false));
154 tray_view()->SetVisible(true); 168 tray_view()->SetVisible(true);
155 } 169 }
156 170
157 views::Label* TrayUpdate::GetLabelForTesting() { 171 views::Label* TrayUpdate::GetLabelForTesting() {
158 return update_view_ ? update_view_->update_label_ : nullptr; 172 return update_view_ ? update_view_->update_label_ : nullptr;
159 } 173 }
160 174
175 void TrayUpdate::ShowUpdateOverCellularAvailableIcon() {
176 update_over_cellular_available_ = true;
177
178 // TODO(weidongg/691108): adjust severity according the amount of time passing
179 // after update is available over cellular connection.
180 // Use low severity for update available over cellular connection.
181 SetIconColor(IconColorForUpdateSeverity(mojom::UpdateSeverity::LOW, false));
182 tray_view()->SetVisible(true);
183 }
184
161 } // namespace ash 185 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698