Index: athena/system/shutdown_dialog.cc |
diff --git a/athena/system/power_button_controller.cc b/athena/system/shutdown_dialog.cc |
similarity index 50% |
rename from athena/system/power_button_controller.cc |
rename to athena/system/shutdown_dialog.cc |
index e1105b90e9ad458f4816dfc5d525aa5e4247813d..865349ea7613927444a9ff8ecbf2e2ab1515b3a7 100644 |
--- a/athena/system/power_button_controller.cc |
+++ b/athena/system/shutdown_dialog.cc |
@@ -2,11 +2,12 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "athena/system/power_button_controller.h" |
+#include "athena/system/shutdown_dialog.h" |
#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,30 +19,22 @@ |
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); |
+ShutdownDialog::ShutdownDialog(aura::Window* dialog_container) |
+ : warning_message_container_(dialog_container), state_(STATE_OTHER) { |
+ InputManager::Get()->AddPowerButtonObserver(this); |
} |
-PowerButtonController::~PowerButtonController() { |
- chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( |
- this); |
+ShutdownDialog::~ShutdownDialog() { |
+ InputManager::Get()->RemovePowerButtonObserver(this); |
} |
-void PowerButtonController::ShowShutdownWarningDialog() { |
+void ShutdownDialog::ShowShutdownWarningDialog() { |
state_ = STATE_SHUTDOWN_WARNING_VISIBLE; |
shutdown_warning_message_.reset(new views::Widget); |
@@ -69,57 +62,41 @@ 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); |
+ &ShutdownDialog::Shutdown); |
} |
-void PowerButtonController::Shutdown() { |
+void ShutdownDialog::Shutdown() { |
state_ = STATE_SHUTDOWN_REQUESTED; |
chromeos::DBusThreadManager::Get() |
->GetPowerManagerClient() |
->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 ShutdownDialog::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; |
} |
} |