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

Side by Side Diff: ash/system/chromeos/power/tray_power.cc

Issue 731663002: Remove Yoshi charger recall pop up warning UI code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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/chromeos/power/tray_power.h" 5 #include "ash/system/chromeos/power/tray_power.h"
6 6
7 #include "ash/accessibility_delegate.h" 7 #include "ash/accessibility_delegate.h"
8 #include "ash/ash_switches.h" 8 #include "ash/ash_switches.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/chromeos/power/power_status_view.h" 10 #include "ash/system/chromeos/power/power_status_view.h"
(...skipping 21 matching lines...) Expand all
32 #include "ui/views/layout/fill_layout.h" 32 #include "ui/views/layout/fill_layout.h"
33 #include "ui/views/layout/grid_layout.h" 33 #include "ui/views/layout/grid_layout.h"
34 #include "ui/views/view.h" 34 #include "ui/views/view.h"
35 #include "ui/views/widget/widget.h" 35 #include "ui/views/widget/widget.h"
36 36
37 using message_center::MessageCenter; 37 using message_center::MessageCenter;
38 using message_center::Notification; 38 using message_center::Notification;
39 39
40 namespace ash { 40 namespace ash {
41 namespace tray { 41 namespace tray {
42 namespace {
43
44 const int kMaxSpringChargerAccessibilityNotifyCount = 3;
45 const int kSpringChargerAccessibilityTimerFirstTimeNotifyInSeconds = 30;
46 const int kSpringChargerAccessibilityTimerRepeatInMinutes = 5;
47
48 }
49 42
50 // This view is used only for the tray. 43 // This view is used only for the tray.
51 class PowerTrayView : public views::ImageView { 44 class PowerTrayView : public views::ImageView {
52 public: 45 public:
53 PowerTrayView() 46 PowerTrayView() {
54 : spring_charger_spoken_notification_count_(0) {
55 UpdateImage(); 47 UpdateImage();
56 } 48 }
57 49
58 virtual ~PowerTrayView() { 50 virtual ~PowerTrayView() {
59 } 51 }
60 52
61 // Overriden from views::View. 53 // Overriden from views::View.
62 virtual void GetAccessibleState(ui::AXViewState* state) override { 54 virtual void GetAccessibleState(ui::AXViewState* state) override {
63 state->name = accessible_name_; 55 state->name = accessible_name_;
64 state->role = ui::AX_ROLE_BUTTON; 56 state->role = ui::AX_ROLE_BUTTON;
65 } 57 }
66 58
67 void UpdateStatus(bool battery_alert) { 59 void UpdateStatus(bool battery_alert) {
68 UpdateImage(); 60 UpdateImage();
69 SetVisible(PowerStatus::Get()->IsBatteryPresent()); 61 SetVisible(PowerStatus::Get()->IsBatteryPresent());
70 62
71 if (battery_alert) { 63 if (battery_alert) {
72 accessible_name_ = PowerStatus::Get()->GetAccessibleNameString(true); 64 accessible_name_ = PowerStatus::Get()->GetAccessibleNameString(true);
73 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); 65 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
74 } 66 }
75 } 67 }
76 68
77 void SetupNotifyBadCharger() {
78 // Poll with a shorter duration timer to notify the charger issue
79 // for the first time after the charger dialog is displayed.
80 spring_charger_accessibility_timer_.Start(
81 FROM_HERE, base::TimeDelta::FromSeconds(
82 kSpringChargerAccessibilityTimerFirstTimeNotifyInSeconds),
83 this, &PowerTrayView::NotifyChargerIssue);
84 }
85
86 private: 69 private:
87 void UpdateImage() { 70 void UpdateImage() {
88 SetImage(PowerStatus::Get()->GetBatteryImage(PowerStatus::ICON_LIGHT)); 71 SetImage(PowerStatus::Get()->GetBatteryImage(PowerStatus::ICON_LIGHT));
89 } 72 }
90 73
91 void NotifyChargerIssue() {
92 if (!Shell::GetInstance()->accessibility_delegate()->
93 IsSpokenFeedbackEnabled())
94 return;
95
96 if (!Shell::GetInstance()->system_tray_delegate()->
97 IsSpringChargerReplacementDialogVisible()) {
98 spring_charger_accessibility_timer_.Stop();
99 return;
100 }
101
102 accessible_name_ = ui::ResourceBundle::GetSharedInstance().
103 GetLocalizedString(IDS_CHARGER_REPLACEMENT_ACCESSIBILITY_NOTIFICATION);
104 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
105 ++spring_charger_spoken_notification_count_;
106
107 if (spring_charger_spoken_notification_count_ == 1) {
108 // After notify the charger issue for the first time, repeat the
109 // notification with a longer duration timer.
110 spring_charger_accessibility_timer_.Stop();
111 spring_charger_accessibility_timer_.Start(
112 FROM_HERE, base::TimeDelta::FromMinutes(
113 kSpringChargerAccessibilityTimerRepeatInMinutes),
114 this, &PowerTrayView::NotifyChargerIssue);
115 } else if (spring_charger_spoken_notification_count_ >=
116 kMaxSpringChargerAccessibilityNotifyCount) {
117 spring_charger_accessibility_timer_.Stop();
118 }
119 }
120
121 base::string16 accessible_name_; 74 base::string16 accessible_name_;
122 75
123 // Tracks how many times the original spring charger accessibility
124 // notification has been spoken.
125 int spring_charger_spoken_notification_count_;
126
127 base::RepeatingTimer<PowerTrayView> spring_charger_accessibility_timer_;
128
129 DISALLOW_COPY_AND_ASSIGN(PowerTrayView); 76 DISALLOW_COPY_AND_ASSIGN(PowerTrayView);
130 }; 77 };
131 78
132 class PowerNotificationView : public TrayNotificationView { 79 class PowerNotificationView : public TrayNotificationView {
133 public: 80 public:
134 explicit PowerNotificationView(TrayPower* owner) 81 explicit PowerNotificationView(TrayPower* owner)
135 : TrayNotificationView(owner, 0) { 82 : TrayNotificationView(owner, 0) {
136 power_status_view_ = 83 power_status_view_ =
137 new PowerStatusView(PowerStatusView::VIEW_NOTIFICATION, true); 84 new PowerStatusView(PowerStatusView::VIEW_NOTIFICATION, true);
138 InitView(power_status_view_); 85 InitView(power_status_view_);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 160 }
214 161
215 void TrayPower::UpdateAfterLoginStatusChange(user::LoginStatus status) { 162 void TrayPower::UpdateAfterLoginStatusChange(user::LoginStatus status) {
216 } 163 }
217 164
218 void TrayPower::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 165 void TrayPower::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
219 SetTrayImageItemBorder(power_tray_, alignment); 166 SetTrayImageItemBorder(power_tray_, alignment);
220 } 167 }
221 168
222 void TrayPower::OnPowerStatusChanged() { 169 void TrayPower::OnPowerStatusChanged() {
223 RecordChargerType();
224
225 if (PowerStatus::Get()->IsOriginalSpringChargerConnected()) {
226 if (ash::Shell::GetInstance()->system_tray_delegate()->
227 ShowSpringChargerReplacementDialog()) {
228 power_tray_->SetupNotifyBadCharger();
229 }
230 }
231
232 bool battery_alert = UpdateNotificationState(); 170 bool battery_alert = UpdateNotificationState();
233 if (power_tray_) 171 if (power_tray_)
234 power_tray_->UpdateStatus(battery_alert); 172 power_tray_->UpdateStatus(battery_alert);
235 if (notification_view_) 173 if (notification_view_)
236 notification_view_->UpdateStatus(); 174 notification_view_->UpdateStatus();
237 175
238 // Factory testing may place the battery into unusual states. 176 // Factory testing may place the battery into unusual states.
239 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 177 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
240 ash::switches::kAshHideNotificationsForFactory)) 178 ash::switches::kAshHideNotificationsForFactory))
241 return; 179 return;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 message_center_->RemoveNotification(kNotificationId, false); 219 message_center_->RemoveNotification(kNotificationId, false);
282 return true; 220 return true;
283 } 221 }
284 return false; 222 return false;
285 } 223 }
286 224
287 bool TrayPower::UpdateNotificationState() { 225 bool TrayPower::UpdateNotificationState() {
288 const PowerStatus& status = *PowerStatus::Get(); 226 const PowerStatus& status = *PowerStatus::Get();
289 if (!status.IsBatteryPresent() || 227 if (!status.IsBatteryPresent() ||
290 status.IsBatteryTimeBeingCalculated() || 228 status.IsBatteryTimeBeingCalculated() ||
291 status.IsMainsChargerConnected() || 229 status.IsMainsChargerConnected()) {
292 status.IsOriginalSpringChargerConnected()) {
Daniel Erat 2014/11/14 22:48:26 i think we still want to include this here, at lea
jennyz 2014/11/15 00:04:04 Yes, please check in the change for updating power
293 notification_state_ = NOTIFICATION_NONE; 230 notification_state_ = NOTIFICATION_NONE;
294 return false; 231 return false;
295 } 232 }
296 233
297 return status.IsUsbChargerConnected() ? 234 return status.IsUsbChargerConnected() ?
298 UpdateNotificationStateForRemainingPercentage() : 235 UpdateNotificationStateForRemainingPercentage() :
299 UpdateNotificationStateForRemainingTime(); 236 UpdateNotificationStateForRemainingTime();
300 } 237 }
301 238
302 bool TrayPower::UpdateNotificationStateForRemainingTime() { 239 bool TrayPower::UpdateNotificationStateForRemainingTime() {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 return true; 301 return true;
365 } 302 }
366 return false; 303 return false;
367 case NOTIFICATION_CRITICAL: 304 case NOTIFICATION_CRITICAL:
368 return false; 305 return false;
369 } 306 }
370 NOTREACHED(); 307 NOTREACHED();
371 return false; 308 return false;
372 } 309 }
373 310
374 void TrayPower::RecordChargerType() {
Daniel Erat 2014/11/14 22:48:26 it might be worthwhile to keep this metric around,
jennyz 2014/11/15 00:04:04 I deprecated it in the histograms.xml.
375 if (!PowerStatus::Get()->IsLinePowerConnected() ||
376 line_power_was_connected_)
377 return;
378
379 ChargerType current_charger = UNKNOWN_CHARGER;
380 if (PowerStatus::Get()->IsMainsChargerConnected()) {
381 current_charger = MAINS_CHARGER;
382 } else if (PowerStatus::Get()->IsUsbChargerConnected()) {
383 current_charger = USB_CHARGER;
384 } else if (PowerStatus::Get()->IsOriginalSpringChargerConnected()) {
385 current_charger =
386 ash::Shell::GetInstance()->system_tray_delegate()->
387 HasUserConfirmedSafeSpringCharger() ?
388 SAFE_SPRING_CHARGER : UNCONFIRMED_SPRING_CHARGER;
389 }
390
391 if (current_charger != UNKNOWN_CHARGER) {
392 UMA_HISTOGRAM_ENUMERATION("Power.ChargerType",
393 current_charger,
394 CHARGER_TYPE_COUNT);
395 }
396 }
397
398 } // namespace ash 311 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/power/tray_power.h ('k') | ash/system/chromeos/power/tray_power_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698