| Index: athena/system/power_button_controller.cc
|
| diff --git a/athena/system/power_button_controller.cc b/athena/system/power_button_controller.cc
|
| index e1105b90e9ad458f4816dfc5d525aa5e4247813d..3926b6da9728bd10545a49242b673506315b4237 100644
|
| --- a/athena/system/power_button_controller.cc
|
| +++ b/athena/system/power_button_controller.cc
|
| @@ -7,6 +7,7 @@
|
| #include "athena/screen/public/screen_manager.h"
|
| #include "athena/strings/grit/athena_strings.h"
|
| #include "chromeos/dbus/dbus_thread_manager.h"
|
| +#include "chromeos/dbus/power_manager_client.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "ui/gfx/font_list.h"
|
| #include "ui/views/background.h"
|
| @@ -18,27 +19,20 @@
|
| namespace athena {
|
| namespace {
|
|
|
| -// The amount of time that the power button must be held to show the shutdown
|
| -// warning dialog.
|
| -const int kShowShutdownWarningTimeoutMs = 1000;
|
| -
|
| // The amount of time that the power button must be held to shut down the
|
| -// device.
|
| -const int kShutdownTimeoutMs = 5000;
|
| +// device after shutdown dialog is shown.
|
| +const int kShutdownTimeoutMs = 4000;
|
|
|
| } // namespace
|
|
|
| PowerButtonController::PowerButtonController(aura::Window* dialog_container)
|
| : warning_message_container_(dialog_container),
|
| - brightness_is_zero_(false),
|
| state_(STATE_OTHER) {
|
| - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
|
| - this);
|
| + InputManager::Get()->AddPowerButtonObserver(this);
|
| }
|
|
|
| PowerButtonController::~PowerButtonController() {
|
| - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(
|
| - this);
|
| + InputManager::Get()->RemovePowerButtonObserver(this);
|
| }
|
|
|
| void PowerButtonController::ShowShutdownWarningDialog() {
|
| @@ -69,10 +63,8 @@ void PowerButtonController::ShowShutdownWarningDialog() {
|
| shutdown_warning_message_->SetContentsView(container);
|
| shutdown_warning_message_->CenterWindow(container->GetPreferredSize());
|
| shutdown_warning_message_->Show();
|
| -
|
| timer_.Start(FROM_HERE,
|
| - base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs -
|
| - kShowShutdownWarningTimeoutMs),
|
| + base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs),
|
| this,
|
| &PowerButtonController::Shutdown);
|
| }
|
| @@ -84,42 +76,28 @@ void PowerButtonController::Shutdown() {
|
| ->RequestShutdown();
|
| }
|
|
|
| -void PowerButtonController::BrightnessChanged(int level, bool user_initiated) {
|
| - if (brightness_is_zero_)
|
| - zero_brightness_end_time_ = base::TimeTicks::Now();
|
| - brightness_is_zero_ = (level == 0);
|
| -}
|
| -
|
| -void PowerButtonController::PowerButtonEventReceived(
|
| - bool down,
|
| - const base::TimeTicks& timestamp) {
|
| +void PowerButtonController::OnPowerButtonStateChanged(
|
| + PowerButtonObserver::State state) {
|
| if (state_ == STATE_SHUTDOWN_REQUESTED)
|
| return;
|
|
|
| - // Avoid requesting suspend or shutdown if the power button is pressed while
|
| - // the screen is off (http://crbug.com/128451).
|
| - base::TimeDelta time_since_zero_brightness = brightness_is_zero_ ?
|
| - base::TimeDelta() : (base::TimeTicks::Now() - zero_brightness_end_time_);
|
| - const int kShortTimeMs = 10;
|
| - if (time_since_zero_brightness.InMilliseconds() <= kShortTimeMs)
|
| - return;
|
| -
|
| - if (down) {
|
| - state_ = STATE_SUSPEND_ON_RELEASE;
|
| - timer_.Start(
|
| - FROM_HERE,
|
| - base::TimeDelta::FromMilliseconds(kShowShutdownWarningTimeoutMs),
|
| - this,
|
| - &PowerButtonController::ShowShutdownWarningDialog);
|
| - } else {
|
| - if (state_ == STATE_SUSPEND_ON_RELEASE) {
|
| - chromeos::DBusThreadManager::Get()
|
| - ->GetPowerManagerClient()
|
| - ->RequestSuspend();
|
| - }
|
| - state_ = STATE_OTHER;
|
| - timer_.Stop();
|
| - shutdown_warning_message_.reset();
|
| + switch (state) {
|
| + case PRESSED:
|
| + state_ = STATE_SUSPEND_ON_RELEASE;
|
| + break;
|
| + case LONG_PRESSED:
|
| + ShowShutdownWarningDialog();
|
| + break;
|
| + case RELEASED:
|
| + if (state_ == STATE_SUSPEND_ON_RELEASE) {
|
| + chromeos::DBusThreadManager::Get()
|
| + ->GetPowerManagerClient()
|
| + ->RequestSuspend();
|
| + }
|
| + state_ = STATE_OTHER;
|
| + timer_.Stop();
|
| + shutdown_warning_message_.reset();
|
| + break;
|
| }
|
| }
|
|
|
|
|