Refactoring of SessionService into a component part 3.
[chromium-blink-merge.git] / athena / screen_lock / chrome / chrome_screen_lock_manager.cc
blob56c6d7137579725f66bd04f1bc079962302dbdd2
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "athena/input/public/accelerator_manager.h"
6 #include "athena/input/public/input_manager.h"
7 #include "athena/screen_lock/screen_lock_manager_base.h"
8 #include "base/logging.h"
9 #include "chrome/browser/chromeos/login/lock/screen_locker.h"
11 namespace athena {
12 namespace {
14 enum Command {
15 CMD_LOCK_SCREEN
18 const AcceleratorData accelerator_data[] = {
19 { TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN,
20 CMD_LOCK_SCREEN, AF_NONE }};
22 class ChromeScreenLockManager : public ScreenLockManagerBase,
23 public AcceleratorHandler,
24 public PowerButtonObserver {
25 public:
26 ChromeScreenLockManager() {}
28 void Init();
30 protected:
31 ~ChromeScreenLockManager() override;
33 private:
34 // ScreenLockManager:
35 void LockScreen() override;
37 // AcceleratorHandler:
38 bool IsCommandEnabled(int command_id) const override;
39 bool OnAcceleratorFired(int command_id,
40 const ui::Accelerator& accelerator) override;
42 // PowerButtonObserver:
43 void OnPowerButtonStateChanged(State state) override;
45 DISALLOW_COPY_AND_ASSIGN(ChromeScreenLockManager);
48 ChromeScreenLockManager::~ChromeScreenLockManager() {
49 InputManager::Get()->RemovePowerButtonObserver(this);
52 void ChromeScreenLockManager::Init() {
53 AcceleratorManager::Get()->RegisterAccelerators(
54 accelerator_data, arraysize(accelerator_data), this);
55 InputManager::Get()->AddPowerButtonObserver(this);
58 void ChromeScreenLockManager::LockScreen() {
59 chromeos::ScreenLocker::HandleLockScreenRequest();
62 bool ChromeScreenLockManager::IsCommandEnabled(int command_id) const {
63 return true;
66 bool ChromeScreenLockManager::OnAcceleratorFired(
67 int command_id,
68 const ui::Accelerator& accelerator) {
69 switch (command_id) {
70 case CMD_LOCK_SCREEN:
71 LockScreen();
72 return true;
74 default:
75 NOTREACHED();
77 return false;
80 void ChromeScreenLockManager::OnPowerButtonStateChanged(State state) {
81 if (state == PRESSED)
82 LockScreen();
85 } // namespace
87 // static
88 ScreenLockManager* ScreenLockManager::Create() {
89 ChromeScreenLockManager* instance = new ChromeScreenLockManager();
90 instance->Init();
91 return instance;
94 } // namespace athena