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