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

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

Issue 107103004: Implement the spring charger replacement UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add UMA stats. Created 7 years 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 | Annotate | Revision Log
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/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/shell.h"
8 #include "ash/system/chromeos/power/power_status_view.h" 9 #include "ash/system/chromeos/power/power_status_view.h"
9 #include "ash/system/date/date_view.h" 10 #include "ash/system/date/date_view.h"
10 #include "ash/system/system_notifier.h" 11 #include "ash/system/system_notifier.h"
12 #include "ash/system/tray/system_tray_delegate.h"
11 #include "ash/system/tray/tray_constants.h" 13 #include "ash/system/tray/tray_constants.h"
12 #include "ash/system/tray/tray_notification_view.h" 14 #include "ash/system/tray/tray_notification_view.h"
13 #include "ash/system/tray/tray_utils.h" 15 #include "ash/system/tray/tray_utils.h"
14 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/metrics/histogram.h"
15 #include "grit/ash_resources.h" 18 #include "grit/ash_resources.h"
16 #include "grit/ash_strings.h" 19 #include "grit/ash_strings.h"
17 #include "third_party/icu/source/i18n/unicode/fieldpos.h" 20 #include "third_party/icu/source/i18n/unicode/fieldpos.h"
18 #include "third_party/icu/source/i18n/unicode/fmtable.h" 21 #include "third_party/icu/source/i18n/unicode/fmtable.h"
19 #include "ui/base/accessibility/accessible_view_state.h" 22 #include "ui/base/accessibility/accessible_view_state.h"
20 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/message_center/message_center.h" 24 #include "ui/message_center/message_center.h"
22 #include "ui/message_center/notification.h" 25 #include "ui/message_center/notification.h"
23 #include "ui/views/controls/button/button.h" 26 #include "ui/views/controls/button/button.h"
24 #include "ui/views/controls/image_view.h" 27 #include "ui/views/controls/image_view.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 const int TrayPower::kCriticalPercentage = 5; 104 const int TrayPower::kCriticalPercentage = 5;
102 const int TrayPower::kLowPowerPercentage = 10; 105 const int TrayPower::kLowPowerPercentage = 10;
103 const int TrayPower::kNoWarningPercentage = 15; 106 const int TrayPower::kNoWarningPercentage = 15;
104 107
105 TrayPower::TrayPower(SystemTray* system_tray, MessageCenter* message_center) 108 TrayPower::TrayPower(SystemTray* system_tray, MessageCenter* message_center)
106 : SystemTrayItem(system_tray), 109 : SystemTrayItem(system_tray),
107 message_center_(message_center), 110 message_center_(message_center),
108 power_tray_(NULL), 111 power_tray_(NULL),
109 notification_view_(NULL), 112 notification_view_(NULL),
110 notification_state_(NOTIFICATION_NONE), 113 notification_state_(NOTIFICATION_NONE),
111 usb_charger_was_connected_(false) { 114 usb_charger_was_connected_(false),
115 is_line_power_connected_(false) {
112 PowerStatus::Get()->AddObserver(this); 116 PowerStatus::Get()->AddObserver(this);
113 } 117 }
114 118
115 TrayPower::~TrayPower() { 119 TrayPower::~TrayPower() {
116 PowerStatus::Get()->RemoveObserver(this); 120 PowerStatus::Get()->RemoveObserver(this);
117 } 121 }
118 122
119 views::View* TrayPower::CreateTrayView(user::LoginStatus status) { 123 views::View* TrayPower::CreateTrayView(user::LoginStatus status) {
120 // There may not be enough information when this is created about whether 124 // There may not be enough information when this is created about whether
121 // there is a battery or not. So always create this, and adjust visibility as 125 // there is a battery or not. So always create this, and adjust visibility as
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 159 }
156 160
157 void TrayPower::UpdateAfterLoginStatusChange(user::LoginStatus status) { 161 void TrayPower::UpdateAfterLoginStatusChange(user::LoginStatus status) {
158 } 162 }
159 163
160 void TrayPower::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 164 void TrayPower::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
161 SetTrayImageItemBorder(power_tray_, alignment); 165 SetTrayImageItemBorder(power_tray_, alignment);
162 } 166 }
163 167
164 void TrayPower::OnPowerStatusChanged() { 168 void TrayPower::OnPowerStatusChanged() {
169 RecordExternalPowerSupply();
170
171 if (PowerStatus::Get()->IsOriginalSpringChargerConnected()) {
Daniel Erat 2013/12/10 00:08:58 shouldn't this also check !HasUserConfirmedSafeSpr
jennyz 2013/12/10 19:14:11 The logic for checking if the dialog should be sho
172 ash::Shell::GetInstance()->system_tray_delegate()->
173 ShowSpringChargerReplacementDialog();
Daniel Erat 2013/12/10 00:08:58 should the dialog be hidden when the charger is un
jennyz 2013/12/10 19:14:11 Once the dialog is shown, user has to complete the
174 }
175
165 bool battery_alert = UpdateNotificationState(); 176 bool battery_alert = UpdateNotificationState();
166 if (power_tray_) 177 if (power_tray_)
167 power_tray_->UpdateStatus(battery_alert); 178 power_tray_->UpdateStatus(battery_alert);
168 if (notification_view_) 179 if (notification_view_)
169 notification_view_->UpdateStatus(); 180 notification_view_->UpdateStatus();
170 181
171 // Factory testing may place the battery into unusual states. 182 // Factory testing may place the battery into unusual states.
172 if (CommandLine::ForCurrentProcess()->HasSwitch( 183 if (CommandLine::ForCurrentProcess()->HasSwitch(
173 ash::switches::kAshHideNotificationsForFactory)) 184 ash::switches::kAshHideNotificationsForFactory))
174 return; 185 return;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 return true; 305 return true;
295 } 306 }
296 return false; 307 return false;
297 case NOTIFICATION_CRITICAL: 308 case NOTIFICATION_CRITICAL:
298 return false; 309 return false;
299 } 310 }
300 NOTREACHED(); 311 NOTREACHED();
301 return false; 312 return false;
302 } 313 }
303 314
315 void TrayPower::RecordExternalPowerSupply() {
316 if (!PowerStatus::Get()->IsLinePowerConnected()) {
317 is_line_power_connected_ = false;
318 return;
319 }
320
321 if (is_line_power_connected_)
322 return;
323
324 is_line_power_connected_ = true;
325 ExternalPowerSupply current_charger;
326 if (PowerStatus::Get()->IsMainsChargerConnected()) {
327 current_charger = MAINS_CHARGER;
328 } else if (PowerStatus::Get()->IsUsbChargerConnected()) {
329 current_charger = USB_CHARGER;
330 } else if (PowerStatus::Get()->IsOriginalSpringChargerConnected()) {
331 current_charger =
332 ash::Shell::GetInstance()->system_tray_delegate()->
333 HasUserConfirmedSafeSpringCharger() ?
334 SAFE_SPRING_CHARGER : ORIGINAL_SPRING_CHARGER;
335 } else {
336 current_charger = UNKNOWN_CHARGER;
Daniel Erat 2013/12/10 00:08:58 nit: if you just initialize current_charger to UNK
jennyz 2013/12/10 19:14:11 Done.
337 }
338
339 if (current_charger != UNKNOWN_CHARGER) {
340 UMA_HISTOGRAM_ENUMERATION("PowerSupply.ExternalPowerSupply",
Daniel Erat 2013/12/10 00:08:58 where did this name come from? all of the histogra
jennyz 2013/12/10 19:14:11 Done.
341 current_charger,
342 NUM_EXTERNAL_POWER_SUPPLY);
343 }
344 }
345
304 } // namespace internal 346 } // namespace internal
305 } // namespace ash 347 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698