diff options
author | pkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-30 00:36:42 +0000 |
---|---|---|
committer | pkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-30 00:36:42 +0000 |
commit | 39ea59c84dc70e7b215440e60dab8821796afd27 (patch) | |
tree | 7ae70ffaceabb4e2a0c0c11711797eb1c73b9e80 /athena | |
parent | f42187891777d22aa331fffe0842b2af6903f105 (diff) | |
download | chromium_src-39ea59c84dc70e7b215440e60dab8821796afd27.zip chromium_src-39ea59c84dc70e7b215440e60dab8821796afd27.tar.gz chromium_src-39ea59c84dc70e7b215440e60dab8821796afd27.tar.bz2 |
Hook up the power button in athena
BUG=389552
TEST=Manual, see bug
Review URL: https://codereview.chromium.org/407093013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@286360 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'athena')
-rw-r--r-- | athena/athena.gyp | 7 | ||||
-rw-r--r-- | athena/main/DEPS | 1 | ||||
-rw-r--r-- | athena/main/athena_launcher.cc | 3 | ||||
-rw-r--r-- | athena/system/DEPS | 5 | ||||
-rw-r--r-- | athena/system/power_button_controller.cc | 48 | ||||
-rw-r--r-- | athena/system/power_button_controller.h | 39 | ||||
-rw-r--r-- | athena/system/public/DEPS | 4 | ||||
-rw-r--r-- | athena/system/public/system_ui.h | 23 | ||||
-rw-r--r-- | athena/system/system_ui_impl.cc | 45 | ||||
-rw-r--r-- | athena/test/DEPS | 1 | ||||
-rw-r--r-- | athena/test/athena_test_helper.cc | 5 |
11 files changed, 180 insertions, 1 deletions
diff --git a/athena/athena.gyp b/athena/athena.gyp index 93f5057..4f78923 100644 --- a/athena/athena.gyp +++ b/athena/athena.gyp @@ -54,14 +54,18 @@ 'input/accelerator_manager_impl.cc', 'input/accelerator_manager_impl.h', 'input/input_manager_impl.cc', - 'input/public/input_manager.h', 'input/public/accelerator_manager.h', + 'input/public/input_manager.h', 'screen/background_controller.cc', 'screen/background_controller.h', 'screen/public/screen_manager.h', 'screen/screen_accelerator_handler.cc', 'screen/screen_accelerator_handler.h', 'screen/screen_manager_impl.cc', + 'system/power_button_controller.cc', + 'system/power_button_controller.h', + 'system/public/system_ui.h', + 'system/system_ui_impl.cc', 'wm/public/window_manager.h', 'wm/public/window_manager_observer.h', 'wm/bezel_controller.cc', @@ -114,6 +118,7 @@ 'type': 'static_library', 'dependencies': [ '../base/base.gyp:test_support_base', + '../chromeos/chromeos.gyp:chromeos', '../skia/skia.gyp:skia', '../testing/gtest.gyp:gtest', '../ui/accessibility/accessibility.gyp:ax_gen', diff --git a/athena/main/DEPS b/athena/main/DEPS index fca20e1..5385def 100644 --- a/athena/main/DEPS +++ b/athena/main/DEPS @@ -4,6 +4,7 @@ include_rules = [ "+athena/home/public", "+athena/input/public", "+athena/screen/public", + "+athena/system/public", "+athena/task/public", "+athena/virtual_keyboard/public", "+athena/wm/public", diff --git a/athena/main/athena_launcher.cc b/athena/main/athena_launcher.cc index 5da9274..4fa35a1 100644 --- a/athena/main/athena_launcher.cc +++ b/athena/main/athena_launcher.cc @@ -10,6 +10,7 @@ #include "athena/input/public/input_manager.h" #include "athena/main/placeholder.h" #include "athena/screen/public/screen_manager.h" +#include "athena/system/public/system_ui.h" #include "athena/wm/public/window_manager.h" #include "base/memory/scoped_ptr.h" #include "ui/aura/window_property.h" @@ -49,6 +50,7 @@ void StartAthena(aura::Window* root_window, aura::client::SetVisibilityClient(root_window, root_window_state->visibility_client.get()); + athena::SystemUI::Create(); athena::InputManager::Create()->OnRootWindowCreated(root_window); athena::ScreenManager::Create(root_window); athena::WindowManager::Create(); @@ -65,6 +67,7 @@ void ShutdownAthena() { athena::WindowManager::Shutdown(); athena::ScreenManager::Shutdown(); athena::InputManager::Shutdown(); + athena::SystemUI::Shutdown(); } } // namespace athena diff --git a/athena/system/DEPS b/athena/system/DEPS new file mode 100644 index 0000000..ae97819 --- /dev/null +++ b/athena/system/DEPS @@ -0,0 +1,5 @@ +include_rules = [ + "+athena/system/public", + "+chromeos/dbus", +] + diff --git a/athena/system/power_button_controller.cc b/athena/system/power_button_controller.cc new file mode 100644 index 0000000..c54ca46 --- /dev/null +++ b/athena/system/power_button_controller.cc @@ -0,0 +1,48 @@ +// 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/system/power_button_controller.h" + +#include "chromeos/dbus/dbus_thread_manager.h" + +namespace athena { + +PowerButtonController::PowerButtonController() + : brightness_is_zero_(false), + shutdown_requested_(false) { + chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( + this); +} + +PowerButtonController::~PowerButtonController() { + chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( + this); +} + +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& details) { + // Avoid requesting a 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 && !shutdown_requested_) { + shutdown_requested_ = true; + chromeos::DBusThreadManager::Get() + ->GetPowerManagerClient() + ->RequestShutdown(); + } +} + +} // namespace athena diff --git a/athena/system/power_button_controller.h b/athena/system/power_button_controller.h new file mode 100644 index 0000000..69fa9a8 --- /dev/null +++ b/athena/system/power_button_controller.h @@ -0,0 +1,39 @@ +// 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_SYSTEM_POWER_BUTTON_CONTROLLER_H_ +#define ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_ + +#include "chromeos/dbus/power_manager_client.h" + +namespace athena { + +// Shuts down in response to the power button being pressed. +class PowerButtonController : public chromeos::PowerManagerClient::Observer { + public: + PowerButtonController(); + virtual ~PowerButtonController(); + + // chromeos::PowerManagerClient::Observer: + virtual void BrightnessChanged(int level, bool user_initiated) OVERRIDE; + virtual void PowerButtonEventReceived( + bool down, + const base::TimeTicks& timestamp) OVERRIDE; + + private: + // 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_; + + // Whether shutdown was requested. + bool shutdown_requested_; + + DISALLOW_COPY_AND_ASSIGN(PowerButtonController); +}; + +} // namespace athena + +#endif // ATHENA_SYSTEM_POWER_BUTTON_CONTROLLER_H_ diff --git a/athena/system/public/DEPS b/athena/system/public/DEPS new file mode 100644 index 0000000..82426b4 --- /dev/null +++ b/athena/system/public/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + "-athena/system", + "+athena/athena_export.h", +] diff --git a/athena/system/public/system_ui.h b/athena/system/public/system_ui.h new file mode 100644 index 0000000..c1e21d6 --- /dev/null +++ b/athena/system/public/system_ui.h @@ -0,0 +1,23 @@ +// 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_SYSTEM_PUBLIC_SYSTEM_UI_H_ +#define ATHENA_SYSTEM_PUBLIC_SYSTEM_UI_H_ + +#include "athena/athena_export.h" + +namespace athena { + +class ATHENA_EXPORT SystemUI { + public: + // Creates and deletes the singleton object of the SystemUI implementation. + static SystemUI* Create(); + static void Shutdown(); + + virtual ~SystemUI() {} +}; + +} // namespace athena + +#endif // ATHENA_SYSTEM_PUBLIC_SYSTEM_UI_H_ diff --git a/athena/system/system_ui_impl.cc b/athena/system/system_ui_impl.cc new file mode 100644 index 0000000..4b94d03 --- /dev/null +++ b/athena/system/system_ui_impl.cc @@ -0,0 +1,45 @@ +// 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/system/public/system_ui.h" + +#include "athena/system/power_button_controller.h" +#include "base/logging.h" +#include "base/memory/scoped_ptr.h" + +namespace athena { +namespace { + +SystemUI* instance = NULL; + +class SystemUIImpl : public SystemUI { + public: + SystemUIImpl() : power_button_controller_(new PowerButtonController) { + } + + virtual ~SystemUIImpl() { + } + + private: + scoped_ptr<PowerButtonController> power_button_controller_; + + DISALLOW_COPY_AND_ASSIGN(SystemUIImpl); +}; + +} // namespace + +// static +SystemUI* SystemUI::Create() { + instance = new SystemUIImpl; + return instance; +} + +// static +void SystemUI::Shutdown() { + CHECK(instance); + delete instance; + instance = NULL; +} + +} // namespace athena diff --git a/athena/test/DEPS b/athena/test/DEPS index 69827ad..ded0bbd 100644 --- a/athena/test/DEPS +++ b/athena/test/DEPS @@ -3,6 +3,7 @@ include_rules = [ "+athena/home/public", "+athena/main", "+athena/screen/public", + "+chromeos/dbus", "+third_party/skia/include", "+ui/app_list", "+ui/aura", diff --git a/athena/test/athena_test_helper.cc b/athena/test/athena_test_helper.cc index 9adacc0..8f5df97 100644 --- a/athena/test/athena_test_helper.cc +++ b/athena/test/athena_test_helper.cc @@ -11,6 +11,7 @@ #include "base/command_line.h" #include "base/message_loop/message_loop.h" #include "base/run_loop.h" +#include "chromeos/dbus/dbus_thread_manager.h" #include "ui/app_list/app_list_switches.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/env.h" @@ -53,6 +54,8 @@ void AthenaTestHelper::SetUp(ui::ContextFactory* context_factory) { base::CommandLine::ForCurrentProcess()->AppendSwitch( app_list::switches::kEnableExperimentalAppList); + chromeos::DBusThreadManager::InitializeWithStub(); + aura::Env::CreateInstance(true); aura::Env::GetInstance()->set_context_factory(context_factory); @@ -109,6 +112,8 @@ void AthenaTestHelper::TearDown() { ui::ShutdownInputMethodForTesting(); + chromeos::DBusThreadManager::Shutdown(); + aura::Env::DeleteInstance(); } |