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 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); |
James Cook
2017/04/19 00:27:28
nit: just use update_label_ here and below
Greg K
2017/04/19 21:42:10
Done.
| |
87 label->SetText(label_text); | 94 label->SetText(label_text); |
95 update_label_ = label; | |
96 | |
88 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); | 97 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); |
89 style.SetupLabel(label); | 98 style.SetupLabel(label); |
90 tri_view->AddView(TriView::Container::CENTER, label); | 99 tri_view->AddView(TriView::Container::CENTER, label); |
91 | 100 |
92 SetInkDropMode(InkDropHostView::InkDropMode::ON); | 101 SetInkDropMode(InkDropHostView::InkDropMode::ON); |
93 } | 102 } |
94 | 103 |
95 ~UpdateView() override {} | 104 ~UpdateView() override {} |
96 | 105 |
106 views::Label* update_label_; | |
107 | |
97 private: | 108 private: |
98 // Overridden from ActionableView. | 109 // Overridden from ActionableView. |
99 bool PerformAction(const ui::Event& event) override { | 110 bool PerformAction(const ui::Event& event) override { |
100 Shell::Get()->system_tray_controller()->RequestRestartForUpdate(); | 111 Shell::Get()->system_tray_controller()->RequestRestartForUpdate(); |
101 ShellPort::Get()->RecordUserMetricsAction( | 112 ShellPort::Get()->RecordUserMetricsAction( |
102 UMA_STATUS_AREA_OS_UPDATE_DEFAULT_SELECTED); | 113 UMA_STATUS_AREA_OS_UPDATE_DEFAULT_SELECTED); |
103 CloseSystemBubble(); | 114 CloseSystemBubble(); |
104 return true; | 115 return true; |
105 } | 116 } |
106 | 117 |
107 DISALLOW_COPY_AND_ASSIGN(UpdateView); | 118 DISALLOW_COPY_AND_ASSIGN(UpdateView); |
108 }; | 119 }; |
109 | 120 |
110 TrayUpdate::TrayUpdate(SystemTray* system_tray) | 121 TrayUpdate::TrayUpdate(SystemTray* system_tray) |
111 : TrayImageItem(system_tray, kSystemTrayUpdateIcon, UMA_UPDATE) {} | 122 : TrayImageItem(system_tray, kSystemTrayUpdateIcon, UMA_UPDATE) {} |
112 | 123 |
113 TrayUpdate::~TrayUpdate() {} | 124 TrayUpdate::~TrayUpdate() {} |
114 | 125 |
115 bool TrayUpdate::GetInitialVisibility() { | 126 bool TrayUpdate::GetInitialVisibility() { |
116 // If chrome tells ash there is an update available before this item's system | 127 // If chrome tells ash there is an update available before this item's system |
117 // tray is constructed then show the icon. | 128 // tray is constructed then show the icon. |
118 return update_required_; | 129 return update_required_; |
119 } | 130 } |
120 | 131 |
121 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) { | 132 views::View* TrayUpdate::CreateDefaultView(LoginStatus status) { |
122 return update_required_ ? new UpdateView(this) : nullptr; | 133 if (update_required_) { |
134 update_view_ = new UpdateView(this); | |
135 return update_view_; | |
136 } | |
137 return nullptr; | |
138 } | |
139 | |
140 void TrayUpdate::DestroyDefaultView() { | |
141 update_view_ = nullptr; | |
123 } | 142 } |
124 | 143 |
125 void TrayUpdate::ShowUpdateIcon(mojom::UpdateSeverity severity, | 144 void TrayUpdate::ShowUpdateIcon(mojom::UpdateSeverity severity, |
126 bool factory_reset_required) { | 145 bool factory_reset_required, |
146 mojom::UpdateType update_type) { | |
127 // Cache update info so we can create the default view when the menu opens. | 147 // Cache update info so we can create the default view when the menu opens. |
128 update_required_ = true; | 148 update_required_ = true; |
129 severity_ = severity; | 149 severity_ = severity; |
130 factory_reset_required_ = factory_reset_required; | 150 factory_reset_required_ = factory_reset_required; |
151 update_type_ = update_type; | |
131 | 152 |
132 // Show the icon in the tray. | 153 // Show the icon in the tray. |
133 SetIconColor(IconColorForUpdateSeverity(severity_, false)); | 154 SetIconColor(IconColorForUpdateSeverity(severity_, false)); |
134 tray_view()->SetVisible(true); | 155 tray_view()->SetVisible(true); |
135 } | 156 } |
136 | 157 |
158 views::Label* TrayUpdate::GetLabelForTesting() { | |
159 return update_view_ ? update_view_->update_label_ : nullptr; | |
160 } | |
161 | |
137 } // namespace ash | 162 } // namespace ash |
OLD | NEW |