Commit 6c29a291 authored by jam's avatar jam Committed by Commit bot

Revert of Intorduce PowerButtonObserver API (patchset #3 id:80001 of...

Revert of Intorduce PowerButtonObserver API (patchset #3 id:80001 of https://codereview.chromium.org/654343002/)

Reason for revert:
This is breaking the main waterfall : http://build.chromium.org/p/chromium.chromiumos/builders/Linux%20ChromiumOS%20Tests%20(1)

It appears that athena_unittests got added to the waterfall and not trybots. Please fix that before relanding this.

Original issue's description:
> Intorduce PowerButtonObserver API
>
> renamed existing PowerButtonController to ShutdownDialog
>
> BUG=None
> TEST=covered by unit tests
>
> Committed: https://crrev.com/0d921cdf45872ebff6c22da6a21c12d44054a860
> Cr-Commit-Position: refs/heads/master@{#299821}

TBR=mukai@chromium.org,oshima@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=None

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

Cr-Commit-Position: refs/heads/master@{#299846}
parent 15e2d7bf
...@@ -69,9 +69,6 @@ ...@@ -69,9 +69,6 @@
'input/accelerator_manager_impl.cc', 'input/accelerator_manager_impl.cc',
'input/accelerator_manager_impl.h', 'input/accelerator_manager_impl.h',
'input/input_manager_impl.cc', 'input/input_manager_impl.cc',
'input/input_manager_impl.h',
'input/power_button_controller.cc',
'input/power_button_controller.h',
'input/public/accelerator_manager.h', 'input/public/accelerator_manager.h',
'input/public/input_manager.h', 'input/public/input_manager.h',
'resource_manager/delegate/resource_manager_delegate.cc', 'resource_manager/delegate/resource_manager_delegate.cc',
...@@ -90,8 +87,8 @@ ...@@ -90,8 +87,8 @@
'system/network_selector.h', 'system/network_selector.h',
'system/orientation_controller.cc', 'system/orientation_controller.cc',
'system/orientation_controller.h', 'system/orientation_controller.h',
'system/shutdown_dialog.cc', 'system/power_button_controller.cc',
'system/shutdown_dialog.h', 'system/power_button_controller.h',
'system/status_icon_container_view.cc', 'system/status_icon_container_view.cc',
'system/status_icon_container_view.h', 'system/status_icon_container_view.h',
'system/time_view.cc', 'system/time_view.cc',
...@@ -292,7 +289,6 @@ ...@@ -292,7 +289,6 @@
'home/home_card_gesture_manager_unittest.cc', 'home/home_card_gesture_manager_unittest.cc',
'home/home_card_unittest.cc', 'home/home_card_unittest.cc',
'input/accelerator_manager_unittest.cc', 'input/accelerator_manager_unittest.cc',
'input/input_manager_unittest.cc',
'resource_manager/memory_pressure_notifier_unittest.cc', 'resource_manager/memory_pressure_notifier_unittest.cc',
'resource_manager/resource_manager_unittest.cc', 'resource_manager/resource_manager_unittest.cc',
'screen/screen_manager_unittest.cc', 'screen/screen_manager_unittest.cc',
......
include_rules = [ include_rules = [
"+chromeos",
"+ui/aura", "+ui/aura",
"+ui/base", "+ui/base",
"+ui/events", "+ui/events",
...@@ -8,9 +7,3 @@ include_rules = [ ...@@ -8,9 +7,3 @@ include_rules = [
"+ui/views", "+ui/views",
] ]
specific_include_rules = {
# exported for test.
"input_manager_impl.h": [
"+athena/athena_export.h",
],
}
...@@ -43,7 +43,7 @@ class TestHandler : public AcceleratorHandler { ...@@ -43,7 +43,7 @@ class TestHandler : public AcceleratorHandler {
DISALLOW_COPY_AND_ASSIGN(TestHandler); DISALLOW_COPY_AND_ASSIGN(TestHandler);
}; };
} // namespace } // namespace athena
typedef test::AthenaTestBase InputManagerTest; typedef test::AthenaTestBase InputManagerTest;
......
...@@ -2,24 +2,60 @@ ...@@ -2,24 +2,60 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "athena/input/input_manager_impl.h" #include "athena/input/public/input_manager.h"
#include "athena/input/power_button_controller.h" #include "athena/input/accelerator_manager_impl.h"
#include "base/logging.h" #include "base/logging.h"
#include "ui/aura/client/event_client.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/events/event_target.h"
namespace athena { namespace athena {
namespace { namespace {
InputManager* instance = NULL; InputManager* instance = NULL;
} // namespace class InputManagerImpl : public InputManager,
public ui::EventTarget,
public aura::client::EventClient {
public:
InputManagerImpl();
virtual ~InputManagerImpl();
void Init();
void Shutdown();
private:
// InputManager:
virtual void OnRootWindowCreated(aura::Window* root_window) override;
virtual ui::EventTarget* GetTopmostEventTarget() override { return this; }
virtual AcceleratorManager* GetAcceleratorManager() override {
return accelerator_manager_.get();
}
// Overridden from aura::client::EventClient:
virtual bool CanProcessEventsWithinSubtree(
const aura::Window* window) const override {
return window && !window->ignore_events();
}
virtual ui::EventTarget* GetToplevelEventTarget() override { return this; }
// ui::EventTarget:
virtual bool CanAcceptEvent(const ui::Event& event) override;
virtual ui::EventTarget* GetParentTarget() override;
virtual scoped_ptr<ui::EventTargetIterator> GetChildIterator() const override;
virtual ui::EventTargeter* GetEventTargeter() override;
virtual void OnEvent(ui::Event* event) override;
scoped_ptr<AcceleratorManagerImpl> accelerator_manager_;
DISALLOW_COPY_AND_ASSIGN(InputManagerImpl);
};
InputManagerImpl::InputManagerImpl() InputManagerImpl::InputManagerImpl()
: accelerator_manager_( : accelerator_manager_(
AcceleratorManagerImpl::CreateGlobalAcceleratorManager()), AcceleratorManagerImpl::CreateGlobalAcceleratorManager()) {
power_button_controller_(new PowerButtonController) {
DCHECK(!instance); DCHECK(!instance);
instance = this; instance = this;
} }
...@@ -32,7 +68,6 @@ InputManagerImpl::~InputManagerImpl() { ...@@ -32,7 +68,6 @@ InputManagerImpl::~InputManagerImpl() {
void InputManagerImpl::Init() { void InputManagerImpl::Init() {
accelerator_manager_->Init(); accelerator_manager_->Init();
power_button_controller_->InstallAccelerators();
} }
void InputManagerImpl::Shutdown() { void InputManagerImpl::Shutdown() {
...@@ -44,31 +79,6 @@ void InputManagerImpl::OnRootWindowCreated(aura::Window* root_window) { ...@@ -44,31 +79,6 @@ void InputManagerImpl::OnRootWindowCreated(aura::Window* root_window) {
accelerator_manager_->OnRootWindowCreated(root_window); accelerator_manager_->OnRootWindowCreated(root_window);
} }
ui::EventTarget* InputManagerImpl::GetTopmostEventTarget() {
return this;
}
AcceleratorManager* InputManagerImpl::GetAcceleratorManager() {
return accelerator_manager_.get();
}
void InputManagerImpl::AddPowerButtonObserver(PowerButtonObserver* observer) {
power_button_controller_->AddPowerButtonObserver(observer);
}
void InputManagerImpl::RemovePowerButtonObserver(
PowerButtonObserver* observer) {
power_button_controller_->RemovePowerButtonObserver(observer);
}
bool InputManagerImpl::CanProcessEventsWithinSubtree(
const aura::Window* window) const {
return window && !window->ignore_events();
}
ui::EventTarget* InputManagerImpl::GetToplevelEventTarget() {
return this;
}
bool InputManagerImpl::CanAcceptEvent(const ui::Event& event) { bool InputManagerImpl::CanAcceptEvent(const ui::Event& event) {
return true; return true;
} }
...@@ -89,9 +99,7 @@ ui::EventTargeter* InputManagerImpl::GetEventTargeter() { ...@@ -89,9 +99,7 @@ ui::EventTargeter* InputManagerImpl::GetEventTargeter() {
void InputManagerImpl::OnEvent(ui::Event* event) { void InputManagerImpl::OnEvent(ui::Event* event) {
} }
int InputManagerImpl::SetPowerButtonTimeoutMsForTest(int timeout) { } // namespace
return power_button_controller_->SetPowerButtonTimeoutMsForTest(timeout);
}
// static // static
InputManager* InputManager::Create() { InputManager* InputManager::Create() {
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ATHENA_INPUT_INPUT_MANAGER_IMPL_H_
#define ATHENA_INPUT_INPUT_MANAGER_IMPL_H_
#include "athena/input/public/input_manager.h"
#include "athena/athena_export.h"
#include "athena/input/accelerator_manager_impl.h"
#include "ui/aura/client/event_client.h"
#include "ui/events/event_target.h"
namespace athena {
class PowerButtonController;
namespace test {
class ScopedPowerButtonTimeoutShortener;
}
class ATHENA_EXPORT InputManagerImpl : public InputManager,
public ui::EventTarget,
public aura::client::EventClient {
public:
InputManagerImpl();
virtual ~InputManagerImpl();
void Init();
void Shutdown();
private:
friend class test::ScopedPowerButtonTimeoutShortener;
// InputManager:
virtual void OnRootWindowCreated(aura::Window* root_window) override;
virtual ui::EventTarget* GetTopmostEventTarget() override;
virtual AcceleratorManager* GetAcceleratorManager() override;
virtual void AddPowerButtonObserver(PowerButtonObserver* observer) override;
virtual void RemovePowerButtonObserver(
PowerButtonObserver* observer) override;
// Overridden from aura::client::EventClient:
virtual bool CanProcessEventsWithinSubtree(
const aura::Window* window) const override;
virtual ui::EventTarget* GetToplevelEventTarget() override;
// ui::EventTarget:
virtual bool CanAcceptEvent(const ui::Event& event) override;
virtual ui::EventTarget* GetParentTarget() override;
virtual scoped_ptr<ui::EventTargetIterator> GetChildIterator() const override;
virtual ui::EventTargeter* GetEventTargeter() override;
virtual void OnEvent(ui::Event* event) override;
int SetPowerButtonTimeoutMsForTest(int timeout);
scoped_ptr<AcceleratorManagerImpl> accelerator_manager_;
scoped_ptr<PowerButtonController> power_button_controller_;
DISALLOW_COPY_AND_ASSIGN(InputManagerImpl);
};
} // namespace athena
#endif // ATHENA_INPUT_INPUT_MANAGER_IMPL_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "athena/input/input_manager_impl.h"
#include "athena/input/public/accelerator_manager.h"
#include "athena/test/base/athena_test_base.h"
#include "base/run_loop.h"
#include "ui/events/test/event_generator.h"
namespace athena {
namespace {
class TestPowerButtonObserver : public PowerButtonObserver {
public:
TestPowerButtonObserver() : count_(0), state_(RELEASED) {
InputManager::Get()->AddPowerButtonObserver(this);
}
virtual ~TestPowerButtonObserver() {
InputManager::Get()->RemovePowerButtonObserver(this);
}
int count() const { return count_; }
State state() const { return state_; }
bool WaitForLongPress() {
run_loop_.Run();
return state_ == LONG_PRESSED;
}
private:
virtual void OnPowerButtonStateChanged(
PowerButtonObserver::State state) override {
state_ = state;
count_++;
if (state == LONG_PRESSED) {
DCHECK(run_loop_.running());
run_loop_.Quit();
}
}
base::RunLoop run_loop_;
int count_;
State state_;
DISALLOW_COPY_AND_ASSIGN(TestPowerButtonObserver);
};
} // namespace
namespace test {
class ScopedPowerButtonTimeoutShortener {
public:
ScopedPowerButtonTimeoutShortener()
: original_timeout_(
GetInputManagerImpl()->SetPowerButtonTimeoutMsForTest(0)) {}
~ScopedPowerButtonTimeoutShortener() {
GetInputManagerImpl()->SetPowerButtonTimeoutMsForTest(original_timeout_);
}
private:
InputManagerImpl* GetInputManagerImpl() {
return static_cast<InputManagerImpl*>(InputManager::Get());
}
int original_timeout_;
DISALLOW_COPY_AND_ASSIGN(ScopedPowerButtonTimeoutShortener);
};
} // namespace test
typedef test::AthenaTestBase InputManagerTest;
TEST_F(InputManagerTest, PowerButton) {
test::ScopedPowerButtonTimeoutShortener shortener;
TestPowerButtonObserver observer;
ui::test::EventGenerator generator(root_window());
generator.PressKey(ui::VKEY_P, ui::EF_NONE);
EXPECT_EQ(0, observer.count());
// Test short press.
generator.PressKey(ui::VKEY_P, ui::EF_ALT_DOWN);
EXPECT_EQ(1, observer.count());
EXPECT_EQ(PowerButtonObserver::PRESSED, observer.state());
generator.ReleaseKey(ui::VKEY_P, ui::EF_ALT_DOWN);
EXPECT_EQ(2, observer.count());
EXPECT_EQ(PowerButtonObserver::RELEASED, observer.state());
// Test long press.
generator.PressKey(ui::VKEY_P, ui::EF_ALT_DOWN);
EXPECT_EQ(3, observer.count());
EXPECT_EQ(PowerButtonObserver::PRESSED, observer.state());
EXPECT_TRUE(observer.WaitForLongPress());
EXPECT_EQ(4, observer.count());
EXPECT_EQ(PowerButtonObserver::LONG_PRESSED, observer.state());
generator.ReleaseKey(ui::VKEY_P, ui::EF_ALT_DOWN);
EXPECT_EQ(5, observer.count());
EXPECT_EQ(PowerButtonObserver::RELEASED, observer.state());
}
} // namespace athena
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "athena/input/power_button_controller.h"
#include "athena/input/public/accelerator_manager.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "ui/events/event_constants.h"
namespace athena {
namespace {
// The amount of time that the power button must be held to be
// treated as long press.
const int kLongPressTimeoutMs = 1000;
enum {
CMD_DEBUG_POWER_BUTTON_PRESSED,
CMD_DEBUG_POWER_BUTTON_RELEASED,
};
} // namespace
PowerButtonController::PowerButtonController()
: power_button_timeout_ms_(kLongPressTimeoutMs),
brightness_is_zero_(false) {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
this);
}
PowerButtonController::~PowerButtonController() {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(
this);
}
void PowerButtonController::AddPowerButtonObserver(
PowerButtonObserver* observer) {
observers_.AddObserver(observer);
}
void PowerButtonController::RemovePowerButtonObserver(
PowerButtonObserver* observer) {
observers_.RemoveObserver(observer);
}
void PowerButtonController::InstallAccelerators() {
const AcceleratorData accelerator_data[] = {
{TRIGGER_ON_PRESS,
ui::VKEY_P,
ui::EF_ALT_DOWN,
CMD_DEBUG_POWER_BUTTON_PRESSED,
AF_DEBUG | AF_NON_AUTO_REPEATABLE},
{TRIGGER_ON_RELEASE,
ui::VKEY_P,
ui::EF_ALT_DOWN,
CMD_DEBUG_POWER_BUTTON_RELEASED,
AF_DEBUG},
};
AcceleratorManager::Get()->RegisterAccelerators(
accelerator_data, arraysize(accelerator_data), this);
}
int PowerButtonController::SetPowerButtonTimeoutMsForTest(int timeout) {
int old_timeout = power_button_timeout_ms_;
power_button_timeout_ms_ = timeout;
return old_timeout;
}
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) {
// Ignore power button pressed while the screen is off
// (http://crbug.com/128451).
// TODO(oshima): This needs to be revisited for athena.
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) {
FOR_EACH_OBSERVER(PowerButtonObserver,
observers_,
OnPowerButtonStateChanged(PowerButtonObserver::PRESSED));
timer_.Start(FROM_HERE,
base::TimeDelta::FromMilliseconds(kLongPressTimeoutMs),
this,
&PowerButtonController::NotifyLongPress);
} else {
FOR_EACH_OBSERVER(PowerButtonObserver,
observers_,
OnPowerButtonStateChanged(PowerButtonObserver::RELEASED));
timer_.Stop();
}
}
bool PowerButtonController::IsCommandEnabled(int command_id) const {
return true;
}
bool PowerButtonController::OnAcceleratorFired(
int command_id,
const ui::Accelerator& accelerator) {
switch (command_id) {
case CMD_DEBUG_POWER_BUTTON_PRESSED:
PowerButtonEventReceived(true, base::TimeTicks());
break;
case CMD_DEBUG_POWER_BUTTON_RELEASED:
PowerButtonEventReceived(false, base::TimeTicks());
break;
}
return true;
}
void PowerButtonController::NotifyLongPress() {
FOR_EACH_OBSERVER(
PowerButtonObserver,
observers_,
OnPowerButtonStateChanged(PowerButtonObserver::LONG_PRESSED));
}
} // namespace
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ATHENA_INPUT_POWER_BUTTON_CONTROLLER_H_
#define ATHENA_INPUT_POWER_BUTTON_CONTROLLER_H_
#include "athena/input/public/accelerator_manager.h"
#include "athena/input/public/input_manager.h"
#include "base/observer_list.h"
#include "base/timer/timer.h"
#include "chromeos/dbus/power_manager_client.h"
namespace athena {
class PowerButtonController : public chromeos::PowerManagerClient::Observer,
public AcceleratorHandler {
public:
PowerButtonController();
virtual ~PowerButtonController();
void AddPowerButtonObserver(PowerButtonObserver* observer);
void RemovePowerButtonObserver(PowerButtonObserver* observer);
void InstallAccelerators();
// A timer callabck to notify the long press event.
int SetPowerButtonTimeoutMsForTest(int timeout);
private:
// chromeos::PowerManagerClient::Observer:
virtual void BrightnessChanged(int level, bool user_initiated) override;
virtual void PowerButtonEventReceived(
bool down,
const base::TimeTicks& timestamp) override;
// AcceleratorHandler:
virtual bool IsCommandEnabled(int command_id) const override;
virtual bool OnAcceleratorFired(int command_id,
const ui::Accelerator& accelerator) override;
void NotifyLongPress();
int power_button_timeout_ms_;
ObserverList<PowerButtonObserver> observers_;
// The last time at which the screen brightness was 0%.
base::TimeTicks zero_brightness_end_time_;
bool brightness_is_zero_;
base::OneShotTimer<PowerButtonController> timer_;
DISALLOW_COPY_AND_ASSIGN(PowerButtonController);
};
} // namespace athena
#endif // ATHENA_INPUT_POWER_BUTTON_CONTROLLER_H_
...@@ -18,17 +18,6 @@ class EventTarget; ...@@ -18,17 +18,6 @@ class EventTarget;
namespace athena { namespace athena {
class AcceleratorManager; class AcceleratorManager;
class PowerButtonObserver {
public:
enum State {
PRESSED,
LONG_PRESSED,
RELEASED,
};
virtual void OnPowerButtonStateChanged(State state) = 0;
};
class ATHENA_EXPORT InputManager { class ATHENA_EXPORT InputManager {
public: public:
// Creates and deletes the singleton object of the InputManager // Creates and deletes the singleton object of the InputManager
...@@ -41,10 +30,6 @@ class ATHENA_EXPORT InputManager { ...@@ -41,10 +30,6 @@ class ATHENA_EXPORT InputManager {
// with EnvObserver::WindowInitialized // with EnvObserver::WindowInitialized
virtual void OnRootWindowCreated(aura::Window* root_window) = 0; virtual void OnRootWindowCreated(aura::Window* root_window) = 0;
// Add/remove power button observer.
virtual void AddPowerButtonObserver(PowerButtonObserver* observer) = 0;
virtual void RemovePowerButtonObserver(PowerButtonObserver* observer) = 0;
virtual ui::EventTarget* GetTopmostEventTarget() = 0; virtual ui::EventTarget* GetTopmostEventTarget() = 0;
virtual AcceleratorManager* GetAcceleratorManager() = 0; virtual AcceleratorManager* GetAcceleratorManager() = 0;
......
...@@ -3,7 +3,6 @@ include_rules = [ ...@@ -3,7 +3,6 @@ include_rules = [
"+athena/screen/public", "+athena/screen/public",
"+athena/strings/grit/athena_strings.h", "+athena/strings/grit/athena_strings.h",
"+athena/system/public", "+athena/system/public",
"+athena/input/public",
"+chromeos", "+chromeos",
"+third_party/cros_system_api/dbus/service_constants.h", "+third_party/cros_system_api/dbus/service_constants.h",
"+third_party/skia/include", "+third_party/skia/include",
......
...@@ -2,12 +2,11 @@ ...@@ -2,12 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "athena/system/shutdown_dialog.h" #include "athena/system/power_button_controller.h"
#include "athena/screen/public/screen_manager.h" #include "athena/screen/public/screen_manager.h"
#include "athena/strings/grit/athena_strings.h" #include "athena/strings/grit/athena_strings.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager_client.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/font_list.h" #include "ui/gfx/font_list.h"
#include "ui/views/background.h" #include "ui/views/background.h"
...@@ -19,22 +18,30 @@ ...@@ -19,22 +18,30 @@
namespace athena { namespace athena {
namespace { 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 // The amount of time that the power button must be held to shut down the
// device after shutdown dialog is shown. // device.
const int kShutdownTimeoutMs = 4000; const int kShutdownTimeoutMs = 5000;
} // namespace } // namespace
ShutdownDialog::ShutdownDialog(aura::Window* dialog_container) PowerButtonController::PowerButtonController(aura::Window* dialog_container)
: warning_message_container_(dialog_container), state_(STATE_OTHER) { : warning_message_container_(dialog_container),
InputManager::Get()->AddPowerButtonObserver(this); brightness_is_zero_(false),
state_(STATE_OTHER) {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
this);
} }
ShutdownDialog::~ShutdownDialog() { PowerButtonController::~PowerButtonController() {
InputManager::Get()->RemovePowerButtonObserver(this); chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(
this);
} }
void ShutdownDialog::ShowShutdownWarningDialog() { void PowerButtonController::ShowShutdownWarningDialog() {
state_ = STATE_SHUTDOWN_WARNING_VISIBLE; state_ = STATE_SHUTDOWN_WARNING_VISIBLE;
shutdown_warning_message_.reset(new views::Widget); shutdown_warning_message_.reset(new views::Widget);
...@@ -62,41 +69,57 @@ void ShutdownDialog::ShowShutdownWarningDialog() { ...@@ -62,41 +69,57 @@ void ShutdownDialog::ShowShutdownWarningDialog() {
shutdown_warning_message_->SetContentsView(container); shutdown_warning_message_->SetContentsView(container);
shutdown_warning_message_->CenterWindow(container->GetPreferredSize()); shutdown_warning_message_->CenterWindow(container->GetPreferredSize());
shutdown_warning_message_->Show(); shutdown_warning_message_->Show();
timer_.Start(FROM_HERE, timer_.Start(FROM_HERE,
base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs), base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs -
kShowShutdownWarningTimeoutMs),
this, this,
&ShutdownDialog::Shutdown); &PowerButtonController::Shutdown);
} }
void ShutdownDialog::Shutdown() { void PowerButtonController::Shutdown() {
state_ = STATE_SHUTDOWN_REQUESTED; state_ = STATE_SHUTDOWN_REQUESTED;
chromeos::DBusThreadManager::Get() chromeos::DBusThreadManager::Get()
->GetPowerManagerClient() ->GetPowerManagerClient()
->RequestShutdown(); ->RequestShutdown();
} }
void ShutdownDialog::OnPowerButtonStateChanged( void PowerButtonController::BrightnessChanged(int level, bool user_initiated) {
PowerButtonObserver::State state) { 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) {
if (state_ == STATE_SHUTDOWN_REQUESTED) if (state_ == STATE_SHUTDOWN_REQUESTED)
return; return;
switch (state) { // Avoid requesting suspend or shutdown if the power button is pressed while
case PRESSED: // the screen is off (http://crbug.com/128451).
state_ = STATE_SUSPEND_ON_RELEASE; base::TimeDelta time_since_zero_brightness = brightness_is_zero_ ?
break; base::TimeDelta() : (base::TimeTicks::Now() - zero_brightness_end_time_);
case LONG_PRESSED: const int kShortTimeMs = 10;
ShowShutdownWarningDialog(); if (time_since_zero_brightness.InMilliseconds() <= kShortTimeMs)
break; return;
case RELEASED:
if (state_ == STATE_SUSPEND_ON_RELEASE) { if (down) {
chromeos::DBusThreadManager::Get() state_ = STATE_SUSPEND_ON_RELEASE;
->GetPowerManagerClient() timer_.Start(
->RequestSuspend(); FROM_HERE,
} base::TimeDelta::FromMilliseconds(kShowShutdownWarningTimeoutMs),
state_ = STATE_OTHER; this,
timer_.Stop(); &PowerButtonController::ShowShutdownWarningDialog);
shutdown_warning_message_.reset(); } else {
break; if (state_ == STATE_SUSPEND_ON_RELEASE) {
chromeos::DBusThreadManager::Get()
->GetPowerManagerClient()
->RequestSuspend();
}
state_ = STATE_OTHER;
timer_.Stop();
shutdown_warning_message_.reset();
} }
} }
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef ATHENA_SYSTEM_SHUTDOWN_DIALOG_H_ #ifndef ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_
#define ATHENA_SYSTEM_SHUTDOWN_DIALOG_H_ #define ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_
#include "athena/input/public/input_manager.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chromeos/dbus/power_manager_client.h"
namespace aura { namespace aura {
class Window; class Window;
...@@ -21,10 +21,10 @@ class Widget; ...@@ -21,10 +21,10 @@ class Widget;
namespace athena { namespace athena {
// Shuts down in response to the power button being pressed. // Shuts down in response to the power button being pressed.
class ShutdownDialog : public PowerButtonObserver { class PowerButtonController : public chromeos::PowerManagerClient::Observer {
public: public:
explicit ShutdownDialog(aura::Window* dialog_container); explicit PowerButtonController(aura::Window* dialog_container);
virtual ~ShutdownDialog(); virtual ~PowerButtonController();
private: private:
enum State { enum State {
...@@ -47,9 +47,11 @@ class ShutdownDialog : public PowerButtonObserver { ...@@ -47,9 +47,11 @@ class ShutdownDialog : public PowerButtonObserver {
// Requests shutdown. // Requests shutdown.
void Shutdown(); void Shutdown();
// PowerButtonObserver: // chromeos::PowerManagerClient::Observer:
virtual void OnPowerButtonStateChanged( virtual void BrightnessChanged(int level, bool user_initiated) override;
PowerButtonObserver::State state) override; virtual void PowerButtonEventReceived(
bool down,
const base::TimeTicks& timestamp) override;
// |shutdown_warning_message_|'s parent container. // |shutdown_warning_message_|'s parent container.
aura::Window* warning_message_container_; aura::Window* warning_message_container_;
...@@ -57,13 +59,19 @@ class ShutdownDialog : public PowerButtonObserver { ...@@ -57,13 +59,19 @@ class ShutdownDialog : public PowerButtonObserver {
// Shows a warning that the device is about to be shutdown. // Shows a warning that the device is about to be shutdown.
scoped_ptr<views::Widget> shutdown_warning_message_; scoped_ptr<views::Widget> shutdown_warning_message_;
// Whether the screen brightness was reduced to 0%.
bool brightness_is_zero_;
// The last time at which the screen brightness was 0%.
base::TimeTicks zero_brightness_end_time_;
State state_; State state_;
base::OneShotTimer<ShutdownDialog> timer_; base::OneShotTimer<PowerButtonController> timer_;
DISALLOW_COPY_AND_ASSIGN(ShutdownDialog); DISALLOW_COPY_AND_ASSIGN(PowerButtonController);
}; };
} // namespace athena } // namespace athena
#endif // ATHENA_SYSTEM_SHUTDOWN_DIALOG_H_ #endif // ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "athena/screen/public/screen_manager.h" #include "athena/screen/public/screen_manager.h"
#include "athena/system/background_controller.h" #include "athena/system/background_controller.h"
#include "athena/system/orientation_controller.h" #include "athena/system/orientation_controller.h"
#include "athena/system/shutdown_dialog.h" #include "athena/system/power_button_controller.h"
#include "athena/system/status_icon_container_view.h" #include "athena/system/status_icon_container_view.h"
#include "athena/system/time_view.h" #include "athena/system/time_view.h"
#include "athena/util/container_priorities.h" #include "athena/util/container_priorities.h"
...@@ -106,8 +106,8 @@ class SystemUIImpl : public SystemUI { ...@@ -106,8 +106,8 @@ class SystemUIImpl : public SystemUI {
// because it needs to show over the login screen. // because it needs to show over the login screen.
// TODO(pkotwicz): Pick the most appropriate container based on whether the // TODO(pkotwicz): Pick the most appropriate container based on whether the
// user has logged in. // user has logged in.
shutdown_dialog_.reset( power_button_controller_.reset(
new ShutdownDialog(login_screen_system_modal_container_)); new PowerButtonController(login_screen_system_modal_container_));
background_controller_.reset( background_controller_.reset(
new BackgroundController(background_container_)); new BackgroundController(background_container_));
} }
...@@ -122,7 +122,7 @@ class SystemUIImpl : public SystemUI { ...@@ -122,7 +122,7 @@ class SystemUIImpl : public SystemUI {
private: private:
scoped_ptr<OrientationController> orientation_controller_; scoped_ptr<OrientationController> orientation_controller_;
scoped_ptr<ShutdownDialog> shutdown_dialog_; scoped_ptr<PowerButtonController> power_button_controller_;
scoped_ptr<BackgroundController> background_controller_; scoped_ptr<BackgroundController> background_controller_;
// The parent container for the background. // The parent container for the background.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment