OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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. |
| 4 |
| 5 #include "chrome/browser/chromeos/power/power_button_observer.h" |
| 6 |
| 7 #include "ash/shell.h" |
| 8 #include "ash/wm/power_button_controller.h" |
| 9 #include "base/logging.h" |
| 10 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 11 #include "chrome/browser/chromeos/login/user.h" |
| 12 #include "chrome/browser/chromeos/login/user_manager.h" |
| 13 #include "chrome/browser/chromeos/power/power_button_controller_delegate_chromeo
s.h" |
| 14 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "content/public/browser/notification_service.h" |
| 16 |
| 17 namespace chromeos { |
| 18 |
| 19 PowerButtonObserver::PowerButtonObserver() { |
| 20 ash::PowerButtonController* controller = |
| 21 ash::Shell::GetInstance()->power_button_controller(); |
| 22 controller->set_delegate(new PowerButtonControllerDelegateChromeos); |
| 23 |
| 24 registrar_.Add( |
| 25 this, |
| 26 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 27 content::NotificationService::AllSources()); |
| 28 registrar_.Add( |
| 29 this, |
| 30 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
| 31 content::NotificationService::AllSources()); |
| 32 |
| 33 // Tell the controller about the initial state. |
| 34 const UserManager* user_manager = UserManager::Get(); |
| 35 bool logged_in = user_manager->user_is_logged_in(); |
| 36 bool is_guest = logged_in && user_manager->logged_in_user().is_guest(); |
| 37 controller->OnLoginStateChange(logged_in, is_guest); |
| 38 |
| 39 const ScreenLocker* locker = ScreenLocker::default_screen_locker(); |
| 40 bool locked = locker && locker->locked(); |
| 41 controller->OnLockStateChange(locked); |
| 42 } |
| 43 |
| 44 PowerButtonObserver::~PowerButtonObserver() { |
| 45 } |
| 46 |
| 47 void PowerButtonObserver::Observe(int type, |
| 48 const content::NotificationSource& source, |
| 49 const content::NotificationDetails& details) { |
| 50 switch (type) { |
| 51 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { |
| 52 const User* user = content::Details<const User>(details).ptr(); |
| 53 ash::Shell::GetInstance()->power_button_controller()-> |
| 54 OnLoginStateChange(true /* logged_in */, user->is_guest()); |
| 55 break; |
| 56 } |
| 57 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { |
| 58 bool locked = *content::Details<bool>(details).ptr(); |
| 59 ash::Shell::GetInstance()->power_button_controller()-> |
| 60 OnLockStateChange(locked); |
| 61 break; |
| 62 } |
| 63 default: |
| 64 NOTREACHED() << "Unexpected notification " << type; |
| 65 } |
| 66 } |
| 67 |
| 68 void PowerButtonObserver::PowerButtonStateChanged( |
| 69 bool down, const base::TimeTicks& timestamp) { |
| 70 ash::Shell::GetInstance()->power_button_controller()-> |
| 71 OnPowerButtonEvent(down, timestamp); |
| 72 } |
| 73 |
| 74 void PowerButtonObserver::LockButtonStateChanged( |
| 75 bool down, const base::TimeTicks& timestamp) { |
| 76 ash::Shell::GetInstance()->power_button_controller()-> |
| 77 OnLockButtonEvent(down, timestamp); |
| 78 } |
| 79 |
| 80 void PowerButtonObserver::LockScreen() { |
| 81 ash::Shell::GetInstance()->power_button_controller()->OnStartingLock(); |
| 82 } |
| 83 |
| 84 } // namespace chromeos |
OLD | NEW |