Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/session/session_controller.h" | 10 #include "ash/session/session_controller.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/shell_port.h" | 12 #include "ash/shell_port.h" |
| 13 #include "ash/strings/grit/ash_strings.h" | 13 #include "ash/strings/grit/ash_strings.h" |
| 14 #include "ash/system/tray/system_tray.h" | 14 #include "ash/system/tray/system_tray.h" |
| 15 #include "ash/system/tray/system_tray_controller.h" | 15 #include "ash/system/tray/system_tray_controller.h" |
| 16 #include "ash/system/tray/system_tray_delegate.h" | 16 #include "ash/system/tray/system_tray_delegate.h" |
| 17 #include "ash/system/tray/system_tray_notifier.h" | |
| 17 #include "ash/system/tray/tray_constants.h" | 18 #include "ash/system/tray/tray_constants.h" |
| 18 #include "ash/system/tray/tray_popup_item_style.h" | 19 #include "ash/system/tray/tray_popup_item_style.h" |
| 19 #include "ash/system/tray/tray_popup_utils.h" | 20 #include "ash/system/tray/tray_popup_utils.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/gfx/color_palette.h" | 22 #include "ui/gfx/color_palette.h" |
| 22 #include "ui/gfx/image/image.h" | 23 #include "ui/gfx/image/image.h" |
| 23 #include "ui/gfx/paint_vector_icon.h" | 24 #include "ui/gfx/paint_vector_icon.h" |
| 24 #include "ui/views/controls/image_view.h" | 25 #include "ui/views/controls/image_view.h" |
| 25 #include "ui/views/controls/label.h" | 26 #include "ui/views/controls/label.h" |
| 26 #include "ui/views/layout/fill_layout.h" | 27 #include "ui/views/layout/fill_layout.h" |
| 28 #include "ui/views/widget/widget.h" | |
| 27 | 29 |
| 28 namespace ash { | 30 namespace ash { |
| 29 namespace { | 31 namespace { |
| 30 | 32 |
| 31 // Returns the color to use for the update icon when the update severity is | 33 // Returns the color to use for the update icon when the update severity is |
| 32 // |severity|. If |for_menu| is true, the icon color for the system menu is | 34 // |severity|. If |for_menu| is true, the icon color for the system menu is |
| 33 // given, otherwise the icon color for the system tray is given. | 35 // given, otherwise the icon color for the system tray is given. |
| 34 SkColor IconColorForUpdateSeverity(mojom::UpdateSeverity severity, | 36 SkColor IconColorForUpdateSeverity(mojom::UpdateSeverity severity, |
| 35 bool for_menu) { | 37 bool for_menu) { |
| 36 const SkColor default_color = for_menu ? kMenuIconColor : kTrayIconColor; | 38 const SkColor default_color = for_menu ? kMenuIconColor : kTrayIconColor; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 Shell::Get()->system_tray_controller()->ShowAboutChromeOS(); | 132 Shell::Get()->system_tray_controller()->ShowAboutChromeOS(); |
| 131 } | 133 } |
| 132 CloseSystemBubble(); | 134 CloseSystemBubble(); |
| 133 return true; | 135 return true; |
| 134 } | 136 } |
| 135 | 137 |
| 136 DISALLOW_COPY_AND_ASSIGN(UpdateView); | 138 DISALLOW_COPY_AND_ASSIGN(UpdateView); |
| 137 }; | 139 }; |
| 138 | 140 |
| 139 TrayUpdate::TrayUpdate(SystemTray* system_tray) | 141 TrayUpdate::TrayUpdate(SystemTray* system_tray) |
| 140 : TrayImageItem(system_tray, kSystemTrayUpdateIcon, UMA_UPDATE) {} | 142 : TrayImageItem(system_tray, kSystemTrayUpdateIcon, UMA_UPDATE) { |
| 143 Shell::Get()->system_tray_notifier()->AddUpdateObserver(this); | |
| 144 } | |
| 141 | 145 |
| 142 TrayUpdate::~TrayUpdate() {} | 146 TrayUpdate::~TrayUpdate() { |
| 147 Shell::Get()->system_tray_notifier()->RemoveUpdateObserver(this); | |
| 148 } | |
| 143 | 149 |
| 144 bool TrayUpdate::GetInitialVisibility() { | 150 bool TrayUpdate::GetInitialVisibility() { |
| 145 // If chrome tells ash there is an update available before this item's system | 151 // If chrome tells ash there is an update available before this item's system |
| 146 // tray is constructed then show the icon. | 152 // tray is constructed then show the icon. |
| 147 return update_required_ || update_over_cellular_available_; | 153 return update_required_ || update_over_cellular_available_; |
| 148 } | 154 } |
| 149 | 155 |
| 150 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) { | 156 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) { |
| 151 if (update_required_ || update_over_cellular_available_) { | 157 if (update_required_ || update_over_cellular_available_) { |
| 152 update_view_ = new UpdateView(this); | 158 update_view_ = new UpdateView(this); |
| 153 return update_view_; | 159 return update_view_; |
| 154 } | 160 } |
| 155 return nullptr; | 161 return nullptr; |
| 156 } | 162 } |
| 157 | 163 |
| 158 void TrayUpdate::OnDefaultViewDestroyed() { | 164 void TrayUpdate::OnDefaultViewDestroyed() { |
| 159 update_view_ = nullptr; | 165 update_view_ = nullptr; |
| 160 } | 166 } |
| 161 | 167 |
| 168 void TrayUpdate::OnUpdateOverCellularTargetSet(bool success) { | |
| 169 if (success) { | |
|
stevenjb
2017/06/13 17:38:18
if (!success) return;
weidongg
2017/06/13 19:01:39
Done.
| |
| 170 tray_view()->SetVisible(false); | |
| 171 update_over_cellular_available_ = false; | |
| 172 if (update_view_) | |
| 173 update_view_->GetWidget()->Close(); | |
| 174 } | |
| 175 } | |
| 176 | |
| 162 void TrayUpdate::ShowUpdateIcon(mojom::UpdateSeverity severity, | 177 void TrayUpdate::ShowUpdateIcon(mojom::UpdateSeverity severity, |
| 163 bool factory_reset_required, | 178 bool factory_reset_required, |
| 164 mojom::UpdateType update_type) { | 179 mojom::UpdateType update_type) { |
| 165 // Cache update info so we can create the default view when the menu opens. | 180 // Cache update info so we can create the default view when the menu opens. |
| 166 update_required_ = true; | 181 update_required_ = true; |
| 167 severity_ = severity; | 182 severity_ = severity; |
| 168 factory_reset_required_ = factory_reset_required; | 183 factory_reset_required_ = factory_reset_required; |
| 169 update_type_ = update_type; | 184 update_type_ = update_type; |
| 170 | 185 |
| 171 // Show the icon in the tray. | 186 // Show the icon in the tray. |
| 172 SetIconColor(IconColorForUpdateSeverity(severity_, false)); | 187 SetIconColor(IconColorForUpdateSeverity(severity_, false)); |
| 173 tray_view()->SetVisible(true); | 188 tray_view()->SetVisible(true); |
| 174 } | 189 } |
| 175 | 190 |
| 176 views::Label* TrayUpdate::GetLabelForTesting() { | 191 views::Label* TrayUpdate::GetLabelForTesting() { |
| 177 return update_view_ ? update_view_->update_label_ : nullptr; | 192 return update_view_ ? update_view_->update_label_ : nullptr; |
| 178 } | 193 } |
| 179 | 194 |
| 180 void TrayUpdate::ShowUpdateOverCellularAvailableIcon() { | 195 void TrayUpdate::ShowUpdateOverCellularAvailableIcon() { |
| 181 update_over_cellular_available_ = true; | 196 update_over_cellular_available_ = true; |
| 182 | 197 |
| 183 // TODO(weidongg/691108): adjust severity according the amount of time passing | 198 // TODO(weidongg/691108): adjust severity according the amount of time passing |
| 184 // after update is available over cellular connection. | 199 // after update is available over cellular connection. |
| 185 // Use low severity for update available over cellular connection. | 200 // Use low severity for update available over cellular connection. |
| 186 SetIconColor(IconColorForUpdateSeverity(mojom::UpdateSeverity::LOW, false)); | 201 SetIconColor(IconColorForUpdateSeverity(mojom::UpdateSeverity::LOW, false)); |
| 187 tray_view()->SetVisible(true); | 202 tray_view()->SetVisible(true); |
| 188 } | 203 } |
| 189 | 204 |
| 190 } // namespace ash | 205 } // namespace ash |
| OLD | NEW |