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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } | 53 } |
54 | 54 |
55 } // namespace | 55 } // namespace |
56 | 56 |
57 // static | 57 // static |
58 bool TrayUpdate::update_required_ = false; | 58 bool TrayUpdate::update_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 mojom::UpdateType TrayUpdate::update_type_ = mojom::UpdateType::SYSTEM; |
63 | 64 |
64 // The "restart to update" item in the system tray menu. | 65 // The "restart to update" item in the system tray menu. |
65 class TrayUpdate::UpdateView : public ActionableView { | 66 class TrayUpdate::UpdateView : public ActionableView { |
66 public: | 67 public: |
67 explicit UpdateView(TrayUpdate* owner) | 68 explicit UpdateView(TrayUpdate* owner) |
68 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS) { | 69 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS), |
| 70 update_label_(nullptr) { |
69 SetLayoutManager(new views::FillLayout); | 71 SetLayoutManager(new views::FillLayout); |
70 | 72 |
71 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 73 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
72 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); | 74 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); |
73 AddChildView(tri_view); | 75 AddChildView(tri_view); |
74 views::ImageView* image = TrayPopupUtils::CreateMainImageView(); | 76 views::ImageView* image = TrayPopupUtils::CreateMainImageView(); |
75 image->SetImage(gfx::CreateVectorIcon( | 77 image->SetImage(gfx::CreateVectorIcon( |
76 kSystemMenuUpdateIcon, | 78 kSystemMenuUpdateIcon, |
77 IconColorForUpdateSeverity(owner->severity_, true))); | 79 IconColorForUpdateSeverity(owner->severity_, true))); |
78 tri_view->AddView(TriView::Container::START, image); | 80 tri_view->AddView(TriView::Container::START, image); |
79 | 81 |
80 base::string16 label_text = | 82 base::string16 label_text; |
81 owner->factory_reset_required_ | 83 if (owner->factory_reset_required_) { |
82 ? bundle.GetLocalizedString( | 84 label_text = bundle.GetLocalizedString( |
83 IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE) | 85 IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE); |
84 : bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE); | 86 } else if (owner->update_type_ == mojom::UpdateType::FLASH) { |
| 87 label_text = bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE_FLASH); |
| 88 } else { |
| 89 label_text = bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE); |
| 90 } |
| 91 |
85 SetAccessibleName(label_text); | 92 SetAccessibleName(label_text); |
86 auto* label = TrayPopupUtils::CreateDefaultLabel(); | 93 update_label_ = TrayPopupUtils::CreateDefaultLabel(); |
87 label->SetText(label_text); | 94 update_label_->SetText(label_text); |
| 95 |
88 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); | 96 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); |
89 style.SetupLabel(label); | 97 style.SetupLabel(update_label_); |
90 tri_view->AddView(TriView::Container::CENTER, label); | 98 tri_view->AddView(TriView::Container::CENTER, update_label_); |
91 | 99 |
92 SetInkDropMode(InkDropHostView::InkDropMode::ON); | 100 SetInkDropMode(InkDropHostView::InkDropMode::ON); |
93 } | 101 } |
94 | 102 |
95 ~UpdateView() override {} | 103 ~UpdateView() override {} |
96 | 104 |
| 105 views::Label* update_label_; |
| 106 |
97 private: | 107 private: |
98 // Overridden from ActionableView. | 108 // Overridden from ActionableView. |
99 bool PerformAction(const ui::Event& event) override { | 109 bool PerformAction(const ui::Event& event) override { |
100 Shell::Get()->system_tray_controller()->RequestRestartForUpdate(); | 110 Shell::Get()->system_tray_controller()->RequestRestartForUpdate(); |
101 ShellPort::Get()->RecordUserMetricsAction( | 111 ShellPort::Get()->RecordUserMetricsAction( |
102 UMA_STATUS_AREA_OS_UPDATE_DEFAULT_SELECTED); | 112 UMA_STATUS_AREA_OS_UPDATE_DEFAULT_SELECTED); |
103 CloseSystemBubble(); | 113 CloseSystemBubble(); |
104 return true; | 114 return true; |
105 } | 115 } |
106 | 116 |
107 DISALLOW_COPY_AND_ASSIGN(UpdateView); | 117 DISALLOW_COPY_AND_ASSIGN(UpdateView); |
108 }; | 118 }; |
109 | 119 |
110 TrayUpdate::TrayUpdate(SystemTray* system_tray) | 120 TrayUpdate::TrayUpdate(SystemTray* system_tray) |
111 : TrayImageItem(system_tray, kSystemTrayUpdateIcon, UMA_UPDATE) {} | 121 : TrayImageItem(system_tray, kSystemTrayUpdateIcon, UMA_UPDATE) {} |
112 | 122 |
113 TrayUpdate::~TrayUpdate() {} | 123 TrayUpdate::~TrayUpdate() {} |
114 | 124 |
115 bool TrayUpdate::GetInitialVisibility() { | 125 bool TrayUpdate::GetInitialVisibility() { |
116 // If chrome tells ash there is an update available before this item's system | 126 // If chrome tells ash there is an update available before this item's system |
117 // tray is constructed then show the icon. | 127 // tray is constructed then show the icon. |
118 return update_required_; | 128 return update_required_; |
119 } | 129 } |
120 | 130 |
121 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) { | 131 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) { |
122 return update_required_ ? new UpdateView(this) : nullptr; | 132 if (update_required_) { |
| 133 update_view_ = new UpdateView(this); |
| 134 return update_view_; |
| 135 } |
| 136 return nullptr; |
| 137 } |
| 138 |
| 139 void TrayUpdate::DestroyDefaultView() { |
| 140 update_view_ = nullptr; |
123 } | 141 } |
124 | 142 |
125 void TrayUpdate::ShowUpdateIcon(mojom::UpdateSeverity severity, | 143 void TrayUpdate::ShowUpdateIcon(mojom::UpdateSeverity severity, |
126 bool factory_reset_required) { | 144 bool factory_reset_required, |
| 145 mojom::UpdateType update_type) { |
127 // Cache update info so we can create the default view when the menu opens. | 146 // Cache update info so we can create the default view when the menu opens. |
128 update_required_ = true; | 147 update_required_ = true; |
129 severity_ = severity; | 148 severity_ = severity; |
130 factory_reset_required_ = factory_reset_required; | 149 factory_reset_required_ = factory_reset_required; |
| 150 update_type_ = update_type; |
131 | 151 |
132 // Show the icon in the tray. | 152 // Show the icon in the tray. |
133 SetIconColor(IconColorForUpdateSeverity(severity_, false)); | 153 SetIconColor(IconColorForUpdateSeverity(severity_, false)); |
134 tray_view()->SetVisible(true); | 154 tray_view()->SetVisible(true); |
135 } | 155 } |
136 | 156 |
| 157 views::Label* TrayUpdate::GetLabelForTesting() { |
| 158 return update_view_ ? update_view_->update_label_ : nullptr; |
| 159 } |
| 160 |
137 } // namespace ash | 161 } // namespace ash |
OLD | NEW |