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

Unified Diff: athena/system/shutdown_dialog.cc

Issue 654343002: Intorduce PowerButtonObserver API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: speculative fix Created 6 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « athena/system/shutdown_dialog.h ('k') | athena/system/system_ui_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
}
« no previous file with comments | « athena/system/shutdown_dialog.h ('k') | athena/system/system_ui_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698