Skip to content

Commit

Permalink
Revert 207374 "cros: Show notification when low-power charger co..."
Browse files Browse the repository at this point in the history
Broke Win Aura compile:
http://build.chromium.org/p/chromium.win/builders/Win%20Aura%20Builder/builds/9060

> cros: Show notification when low-power charger connected
> 
> Encourage the user to plug in the official charger.
> 
> Also extract FakeMessageCenter into a message_center_test_support target
> so I can use it for a unit test.
> 
> BUG=249852
> TEST=ash_unittests TrayPowerTest.*
> 
> Review URL: https://chromiumcodereview.appspot.com/17157007

TBR=jamescook@chromium.org

Review URL: https://codereview.chromium.org/17363004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207436 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
rsesek@chromium.org committed Jun 20, 2013
1 parent e3fb71b commit 11ca722
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 294 deletions.
2 changes: 0 additions & 2 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@
'../ui/compositor/compositor.gyp:compositor',
'../ui/keyboard/keyboard.gyp:keyboard',
'../ui/message_center/message_center.gyp:message_center',
'../ui/message_center/message_center.gyp:message_center_test_support',
'../ui/ui.gyp:ui',
'../ui/ui.gyp:ui_resources',
'../ui/ui.gyp:ui_test_support',
Expand Down Expand Up @@ -695,7 +694,6 @@
'shell/window_watcher.cc',
'shell/window_watcher_unittest.cc',
'system/chromeos/network/network_state_notifier_unittest.cc',
'system/chromeos/power/tray_power_unittest.cc',
'system/tray/system_tray_unittest.cc',
'system/user/tray_user_unittest.cc',
'system/web_notification/web_notification_tray_unittest.cc',
Expand Down
8 changes: 0 additions & 8 deletions ash/ash_chromeos_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
Everything in this file is wrapped in <if expr="pp_ifdef('chromeos')">. -->
<grit-part>

<!-- Status tray charging strings. -->
<message name="IDS_ASH_STATUS_TRAY_LOW_POWER_CHARGER_TITLE" desc="The title of a notification indicating that a low-current USB charger has been connected.">
Low-power charger connected
</message>
<message name="IDS_ASH_STATUS_TRAY_LOW_POWER_CHARGER_MESSAGE" desc="The message body of a notification indicating that a low-current USB charger has been connected.">
Your Chromebook may not charge while it is turned on. Consider using the official charger.
</message>

<!-- Status Tray Network strings -->
<message name="IDS_ASH_STATUS_TRAY_NETWORK" desc="The label used in the network dialog header.">
Network
Expand Down
11 changes: 0 additions & 11 deletions ash/ash_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ const char kAshDisableUIScaling[] = "ash-disable-ui-scaling";
#if defined(OS_CHROMEOS)
// Disable compositor based mirroring.
const char kAshDisableSoftwareMirroring[] = "ash-disable-software-mirroring";

// Disable the notification when a low-power USB charger is connected.
const char kAshDisableUsbChargerNotification[] =
"ash-disable-usb-charger-notification";
#endif

// Extend the status tray volume item to allow the user to choose an audio
Expand Down Expand Up @@ -182,12 +178,5 @@ bool UseAlternateShelfLayout() {
HasSwitch(ash::switches::kAshUseAlternateShelfLayout);
}

#if defined(OS_CHROMEOS)
bool UseUsbChargerNotification() {
return !CommandLine::ForCurrentProcess()->
HasSwitch(ash::switches::kAshDisableUsbChargerNotification);
}
#endif

} // namespace switches
} // namespace ash
7 changes: 0 additions & 7 deletions ash/ash_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ ASH_EXPORT extern const char kAshDisableDisplayRotation[];
ASH_EXPORT extern const char kAshDisableDragAndDropAppListToLauncher[];
#if defined(OS_CHROMEOS)
ASH_EXPORT extern const char kAshDisableSoftwareMirroring[];
ASH_EXPORT extern const char kAshDisableUsbChargerNotification[];
#endif
ASH_EXPORT extern const char kAshEnableAudioDeviceMenu[];
ASH_EXPORT extern const char kAshEnableAdvancedGestures[];
Expand Down Expand Up @@ -70,12 +69,6 @@ ASH_EXPORT bool ShowAudioDeviceMenu();
// Returns true if the alternate shelf layout should be used.
ASH_EXPORT bool UseAlternateShelfLayout();

#if defined(OS_CHROMEOS)
// Returns true if a notification should appear when a low-power USB charger
// is connected.
ASH_EXPORT bool UseUsbChargerNotification();
#endif

} // namespace switches
} // namespace ash

Expand Down
59 changes: 3 additions & 56 deletions ash/system/chromeos/power/tray_power.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/size.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/notification.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
Expand All @@ -42,8 +40,6 @@

using chromeos::PowerManagerHandler;
using chromeos::PowerSupplyStatus;
using message_center::MessageCenter;
using message_center::Notification;

namespace ash {
namespace internal {
Expand Down Expand Up @@ -205,15 +201,12 @@ class PowerNotificationView : public TrayNotificationView {

using tray::PowerNotificationView;

TrayPower::TrayPower(SystemTray* system_tray, MessageCenter* message_center)
TrayPower::TrayPower(SystemTray* system_tray)
: SystemTrayItem(system_tray),
message_center_(message_center),
power_tray_(NULL),
notification_view_(NULL),
notification_state_(NOTIFICATION_NONE) {
// Tests may not have a PowerManagerHandler.
if (PowerManagerHandler::IsInitialized())
PowerManagerHandler::Get()->AddObserver(this);
PowerManagerHandler::Get()->AddObserver(this);
}

TrayPower::~TrayPower() {
Expand Down Expand Up @@ -280,14 +273,6 @@ gfx::ImageSkia TrayPower::GetBatteryImage(int image_index,
return gfx::ImageSkiaOperations::ExtractSubset(*all.ToImageSkia(), region);
}

// static
gfx::Image TrayPower::GetUsbChargerNotificationImage() {
// TODO(jamescook): Use a specialized art asset here.
gfx::ImageSkia icon =
GetBatteryImage(kNumPowerImages - 1, 0, true, ICON_LIGHT);
return gfx::Image(icon);
}

// static
base::string16 TrayPower::GetAccessibleNameString(
const chromeos::PowerSupplyStatus& supply_status) {
Expand Down Expand Up @@ -415,53 +400,16 @@ void TrayPower::OnPowerStatusChanged(
ash::switches::kAshHideNotificationsForFactory))
return;

if (ash::switches::UseUsbChargerNotification())
MaybeShowUsbChargerNotification(last_power_supply_status_, status);

if (battery_alert)
ShowNotificationView();
else if (notification_state_ == NOTIFICATION_NONE)
HideNotificationView();

last_power_supply_status_ = status;
}

void TrayPower::RequestStatusUpdate() const {
PowerManagerHandler::Get()->RequestStatusUpdate();
}

bool TrayPower::MaybeShowUsbChargerNotification(
const PowerSupplyStatus& old_status,
const PowerSupplyStatus& new_status) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
const char kNotificationId[] = "usb-charger";
// Check for a USB charger being connected.
if (new_status.battery_state == PowerSupplyStatus::CONNECTED_TO_USB &&
old_status.battery_state != PowerSupplyStatus::CONNECTED_TO_USB) {
scoped_ptr<Notification> notification(new Notification(
message_center::NOTIFICATION_TYPE_SIMPLE,
kNotificationId,
rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOW_POWER_CHARGER_TITLE),
rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOW_POWER_CHARGER_MESSAGE),
GetUsbChargerNotificationImage(),
base::string16(),
std::string(),
message_center::RichNotificationData(),
NULL));
message_center_->AddNotification(notification.Pass());
return true;
}

// Check for unplug of a USB charger while the USB charger notification is
// showing.
if (new_status.battery_state != PowerSupplyStatus::CONNECTED_TO_USB &&
old_status.battery_state == PowerSupplyStatus::CONNECTED_TO_USB) {
message_center_->RemoveNotification(kNotificationId, false);
return true;
}
return false;
}

bool TrayPower::UpdateNotificationState(
const chromeos::PowerSupplyStatus& status) {
if (!status.battery_is_present ||
Expand Down Expand Up @@ -491,8 +439,7 @@ bool TrayPower::UpdateNotificationStateForRemainingTime(int remaining_seconds) {
if (remaining_seconds <= kCriticalSeconds) {
notification_state_ = NOTIFICATION_CRITICAL;
return true;
}
if (remaining_seconds <= kLowPowerSeconds) {
} else if (remaining_seconds <= kLowPowerSeconds) {
notification_state_ = NOTIFICATION_LOW_POWER;
return true;
}
Expand Down
42 changes: 8 additions & 34 deletions ash/system/chromeos/power/tray_power.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@
class SkBitmap;

namespace gfx {
class Image;
class ImageSkia;
}

namespace message_center {
class MessageCenter;
}

namespace ash {
namespace internal {

Expand All @@ -32,22 +27,10 @@ enum IconSet {
ICON_DARK
};

class ASH_EXPORT TrayPower : public SystemTrayItem,
public chromeos::PowerManagerHandler::Observer {
class TrayPower : public SystemTrayItem,
public chromeos::PowerManagerHandler::Observer {
public:
// Visible for testing.
enum NotificationState {
NOTIFICATION_NONE,

// Low battery charge.
NOTIFICATION_LOW_POWER,

// Critically low battery charge.
NOTIFICATION_CRITICAL,
};

TrayPower(SystemTray* system_tray,
message_center::MessageCenter* message_center);
explicit TrayPower(SystemTray* system_tray);
virtual ~TrayPower();

// Gets whether battery charging is unreliable for |supply_status|.
Expand Down Expand Up @@ -75,9 +58,6 @@ class ASH_EXPORT TrayPower : public SystemTrayItem,
bool charging_unreliable,
IconSet icon_set);

// Returns an icon for the USB charger notification.
static gfx::Image GetUsbChargerNotificationImage();

// Gets the battery accessible string for |supply_status|.
static base::string16 GetAccessibleNameString(
const chromeos::PowerSupplyStatus& supply_status);
Expand All @@ -86,7 +66,11 @@ class ASH_EXPORT TrayPower : public SystemTrayItem,
static int GetRoundedBatteryPercentage(double battery_percentage);

private:
friend class TrayPowerTest;
enum NotificationState {
NOTIFICATION_NONE,
NOTIFICATION_LOW_POWER,
NOTIFICATION_CRITICAL
};

// Overridden from SystemTrayItem.
virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE;
Expand All @@ -107,26 +91,16 @@ class ASH_EXPORT TrayPower : public SystemTrayItem,
// Requests a power status update.
void RequestStatusUpdate() const;

// Show a notification that a low-power USB charger has been connected.
// Returns true if a notification was shown or explicitly hidden.
bool MaybeShowUsbChargerNotification(
const chromeos::PowerSupplyStatus& old_status,
const chromeos::PowerSupplyStatus& new_status);

// Sets |notification_state_|. Returns true if a notification should be shown.
bool UpdateNotificationState(const chromeos::PowerSupplyStatus& status);
bool UpdateNotificationStateForRemainingTime(int remaining_seconds);
bool UpdateNotificationStateForRemainingPercentage(
double remaining_percentage);

message_center::MessageCenter* message_center_; // Not owned.
tray::PowerTrayView* power_tray_;
tray::PowerNotificationView* notification_view_;
NotificationState notification_state_;

// Power supply status at the last update.
chromeos::PowerSupplyStatus last_power_supply_status_;

DISALLOW_COPY_AND_ASSIGN(TrayPower);
};

Expand Down
Loading

0 comments on commit 11ca722

Please sign in to comment.